//my_err.h#include <errno.h> /* for definition of errno */
#include <stdarg.h> /* ISO C variable aruments */

static void err_doit(int, int, const char *, va_list);

/*
 * Nonfatal error related to a system call.
 * Print a message and return.
 */
void err_ret(const char *fmt, ...)
{
    va_list ap;

    va_start(ap, fmt);
    err_doit(, errno, fmt, ap);
    va_end(ap);
}

/*
 * Fatal error related to a system call.
 * Print a message and terminate.
 */
void err_sys(const char *fmt, ...)
{
    va_list ap;

    va_start(ap, fmt);
    err_doit(, errno, fmt, ap);
    va_end(ap);
    exit();
}

/*
 * Fatal error unrelated to a system call.
 * Error code passed as explict parameter.
 * Print a message and terminate.
 */
void err_exit(int error, const char *fmt, ...)
{
    va_list ap;

    va_start(ap, fmt);
    err_doit(, error, fmt, ap);
    va_end(ap);
    exit();
}

/*
 * Fatal error related to a system call.
 * Print a message, dump core, and terminate.
 */
void err_dump(const char *fmt, ...)
{
    va_list ap;

    va_start(ap, fmt);
    err_doit(, errno, fmt, ap);
    va_end(ap);
    abort(); /* dump core and terminate */
    exit(); /* shouldn't get here */
}

/*
 * Nonfatal error unrelated to a system call.
 * Print a message and return.
 */
void err_msg(const char *fmt, ...)
{
    va_list ap;

    va_start(ap, fmt);
    err_doit(, , fmt, ap);
    va_end(ap);
}

/*
 * Fatal error unrelated to a system call.
 * Print a message and terminate.
 */
void err_quit(const char *fmt, ...)
{
    va_list ap;

    va_start(ap, fmt);
    err_doit(, , fmt, ap);
    va_end(ap);
    exit();
}

/*
 * Print a message and return to caller.
 * Caller specifies "errnoflag".
 */
static void err_doit(int errnoflag, int error, const char *fmt, va_list ap)
{
   char buf[MAXLINE];
   vsnprintf(buf, MAXLINE, fmt, ap);
   if (errnoflag)
       snprintf(buf+strlen(buf), MAXLINE-strlen(buf), ": %s",
         strerror(error));
   strcat(buf, "\n");
   fflush(stdout); /* in case stdout and stderr are the same */
   fputs(buf, stderr);
   fflush(NULL); /* flushes all stdio output streams */
}
//unpipc.h/* include unpipch */
/* Our own header.  Tabs are set for 4 spaces, not 8 */

#ifndef    __unpipc_h
#define    __unpipc_h

#include    "./config.h"    /* configuration options for current OS */
                            /* "../config.h" is generated by configure */

/* If anything changes in the following list of #includes, must change
   ../aclocal.m4 and ../configure.in also, for configure's tests. */

#include    <sys/types.h>    /* basic system data types */
#include    <sys/time.h>    /* timeval{} for select() */
#include    <time.h>        /* timespec{} for pselect() */
#include    <errno.h>
#include    <fcntl.h>        /* for nonblocking */
#include    <limits.h>        /* PIPE_BUF */
#include    <signal.h>
#include    <stdio.h>
#include    <stdlib.h>
#include    <string.h>
#include    <sys/stat.h>    /* for S_xxx file mode constants */
#include    <unistd.h>
#include    <sys/wait.h>

#ifdef    HAVE_MQUEUE_H
# include    <mqueue.h>        /* Posix message queues */
#endif

#ifdef    HAVE_SEMAPHORE_H
# include    <semaphore.h>    /* Posix semaphores */

#ifndef    SEM_FAILED
#define    SEM_FAILED    ((sem_t *)(-1))
#endif

#endif

#ifdef    HAVE_SYS_MMAN_H
# include    <sys/mman.h>    /* Posix shared memory */
#endif

#ifndef    MAP_FAILED
#define    MAP_FAILED    ((void *)(-1))
#endif

#ifdef    HAVE_SYS_IPC_H
# include    <sys/ipc.h>        /* System V IPC */
#endif

#ifdef    HAVE_SYS_MSG_H
# include    <sys/msg.h>        /* System V message queues */
#endif

#ifdef    HAVE_SYS_SEM_H
#ifdef    __bsdi__
#undef    HAVE_SYS_SEM_H        /* hack: BSDI's semctl() prototype is wrong */
#else
# include    <sys/sem.h>        /* System V semaphores */
#endif

#ifndef    HAVE_SEMUN_UNION
/* $$.It semun$$ */
union semun {                /* define union for semctl() */
  int              val;
  struct semid_ds *buf;
  unsigned short  *array;
};
#endif
#endif    /* HAVE_SYS_SEM_H */

#ifdef    HAVE_SYS_SHM_H
# include    <sys/shm.h>        /* System V shared memory */
#endif

#ifdef    HAVE_SYS_SELECT_H
# include    <sys/select.h>    /* for convenience */
#endif

#ifdef    HAVE_POLL_H
# include    <poll.h>        /* for convenience */
#endif

#ifdef    HAVE_STROPTS_H
# include    <stropts.h>        /* for convenience */
#endif

#ifdef    HAVE_STRINGS_H
# include    <strings.h>        /* for convenience */
#endif

/* Next three headers are normally needed for socket/file ioctl's:
 * <sys/ioctl.h>, <sys/filio.h>, and <sys/sockio.h>.
 */
#ifdef    HAVE_SYS_IOCTL_H
# include    <sys/ioctl.h>
#endif
#ifdef    HAVE_SYS_FILIO_H
# include    <sys/filio.h>
#endif

#ifdef    HAVE_PTHREAD_H
# include    <pthread.h>
#endif

#ifdef    HAVE_DOOR_H
# include    <door.h>        /* Solaris doors API */
#endif

#ifdef    HAVE_RPC_RPC_H
#ifdef _PSX4_NSPACE_H_TS    /* Digital Unix 4.0b hack, hack, hack */
#undef    SUCCESS
#endif
# include    <rpc/rpc.h>        /* Sun RPC */
#endif

/* Define bzero() as a macro if it's not in standard C library. */
#ifndef    HAVE_BZERO
#define    bzero(ptr,n)        memset(ptr, 0, n)
#endif

/* Posix.1g requires that an #include of <poll.h> DefinE INFTIM, but many
   systems still DefinE it in <sys/stropts.h>.  We don't want to include
   all the streams stuff if it's not needed, so we just DefinE INFTIM here.
   This is the standard value, but there's no guarantee it is -1. */
#ifndef INFTIM
#define INFTIM          (-1)    /* infinite poll timeout */
#ifdef    HAVE_POLL_H
#define    INFTIM_UNPH                /* tell unpxti.h we defined it */
#endif
#endif

/* Miscellaneous constants */
#ifndef    PATH_MAX            /* should be in <limits.h> */
#define    PATH_MAX    1024    /* max # of characters in a pathname */
#endif

#define    MAX_PATH    1024
/* $$.ix [MAX_PATH]~constant,~definition~of$$ */
#define    MAXLINE        4096    /* max text line length */
/* $$.ix [MAXLINE]~constant,~definition~of$$ */
/* $$.ix [BUFFSIZE]~constant,~definition~of$$ */
#define    BUFFSIZE    8192    /* buffer size for reads and writes */

#define    FILE_MODE    (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
                    /* default permissions for new files */
/* $$.ix [FILE_MODE]~constant,~definition~of$$ */
#define    DIR_MODE    (FILE_MODE | S_IXUSR | S_IXGRP | S_IXOTH)
                    /* default permissions for new directories */
/* $$.ix [DIR_MODE]~constant,~definition~of$$ */

#define    SVMSG_MODE    (MSG_R | MSG_W | MSG_R>>3 | MSG_R>>6)
                    /* default permissions for new SV message queues */
/* $$.ix [SVMSG_MODE]~constant,~definition~of$$ */
#define    SVSEM_MODE    (SEM_R | SEM_A | SEM_R>>3 | SEM_R>>6)
                    /* default permissions for new SV semaphores */
/* $$.ix [SVSEM_MODE]~constant,~definition~of$$ */
#define    SVSHM_MODE    (SHM_R | SHM_W | SHM_R>>3 | SHM_R>>6)
                    /* default permissions for new SV shared memory */
/* $$.ix [SVSHM_MODE]~constant,~definition~of$$ */

typedef    void    Sigfunc(int);    /* for signal handlers */

#ifdef    HAVE_SIGINFO_T_STRUCT
typedef    void    Sigfunc_rt(int, siginfo_t *, void *);
#endif

#define    min(a,b)    ((a) < (b) ? (a) : (b))
#define    max(a,b)    ((a) > (b) ? (a) : (b))

#ifndef    HAVE_TIMESPEC_STRUCT
struct timespec {
  time_t    tv_sec;        /* seconds */
  long        tv_nsec;    /* and nanoseconds */
};
/* $$.It timespec$$ */
/* $$.Ib tv_sec$$ */
/* $$.Ib tv_nsec$$ */
#endif

/*
 * In our wrappers for open(), mq_open(), and sem_open() we handle the
 * optional arguments using the va_XXX() macros.  But one of the optional
 * arguments is of type "mode_t" and this breaks under BSD/OS because it
 * uses a 16-bit integer for this datatype.  But when our wrapper function
 * is called, the compiler expands the 16-bit short integer to a 32-bit
 * integer.  This breaks our call to va_arg().  All we can do is the
 * following hack.  Other systems in addition to BSD/OS might have this
 * problem too ...
 */

#ifdef    __bsdi__
#define    va_mode_t    int
#else
#define    va_mode_t    mode_t
#endif
/* $$.ix [va_mode_t]~datatype,~definition~of$$ */

        /* our record locking macros */
#define    read_lock(fd, offset, whence, len) \
            lock_reg(fd, F_SETLK, F_RDLCK, offset, whence, len)
#define    readw_lock(fd, offset, whence, len) \
            lock_reg(fd, F_SETLKW, F_RDLCK, offset, whence, len)
#define    write_lock(fd, offset, whence, len) \
            lock_reg(fd, F_SETLK, F_WRLCK, offset, whence, len)
#define    writew_lock(fd, offset, whence, len) \
            lock_reg(fd, F_SETLKW, F_WRLCK, offset, whence, len)
#define    un_lock(fd, offset, whence, len) \
            lock_reg(fd, F_SETLK, F_UNLCK, offset, whence, len)
#define    is_read_lockable(fd, offset, whence, len) \
            lock_test(fd, F_RDLCK, offset, whence, len)
#define    is_write_lockable(fd, offset, whence, len) \
            lock_test(fd, F_WRLCK, offset, whence, len)
/* end unpipch */

#define    Read_lock(fd, offset, whence, len) \
            Lock_reg(fd, F_SETLK, F_RDLCK, offset, whence, len)
#define    Readw_lock(fd, offset, whence, len) \
            Lock_reg(fd, F_SETLKW, F_RDLCK, offset, whence, len)
#define    Write_lock(fd, offset, whence, len) \
            Lock_reg(fd, F_SETLK, F_WRLCK, offset, whence, len)
#define    Writew_lock(fd, offset, whence, len) \
            Lock_reg(fd, F_SETLKW, F_WRLCK, offset, whence, len)
#define    Un_lock(fd, offset, whence, len) \
            Lock_reg(fd, F_SETLK, F_UNLCK, offset, whence, len)
#define    Is_read_lockable(fd, offset, whence, len) \
            Lock_test(fd, F_RDLCK, offset, whence, len)
#define    Is_write_lockable(fd, offset, whence, len) \
            Lock_test(fd, F_WRLCK, offset, whence, len)

            /* prototypes for our own library functions */
void     daemon_init(const char *, int);
void     daemon_inetd(const char *, int);
char    *gf_time(void);
int         lock_reg(int, int, int, off_t, int, off_t);
pid_t     lock_test(int, int, off_t, int, off_t);
void    *my_shm(size_t);
char    *px_ipc_name(const char *);
int         readable_timeo(int, int);
ssize_t     readline(int, void *, size_t);
ssize_t     readn(int, void *, size_t);
int         set_concurrency(int);
Sigfunc *signal_intr(int, Sigfunc *);
int          sleep_us(unsigned int);
int         start_time(void);
double     stop_time(void);
int         touch(void *, int);
void     tv_sub(struct timeval *, struct timeval *);
int         writable_timeo(int, int);
ssize_t     writen(int, const void *, size_t);

#ifndef    HAVE_GETHOSTNAME_PROTO
int         gethostname(char *, int);
#endif

#ifndef    HAVE_ISFDTYPE_PROTO
int         isfdtype(int, int);
#endif

#ifndef    HAVE_PSELECT_PROTO
int         pselect(int, fd_set *, fd_set *, fd_set *,
                 const struct timespec *, const sigset_t *);
#endif

#ifndef    HAVE_SNPRINTF_PROTO
int         snprintf(char *, size_t, const char *, ...);
#endif

            /* prototypes for our own library wrapper functions */
char    *Gf_time(void);
void     Lock_reg(int, int, int, off_t, int, off_t);
pid_t     Lock_test(int, int, off_t, int, off_t);
void    *My_shm(size_t);
char    *Px_ipc_name(const char *);
int         Readable_timeo(int, int);
ssize_t     Readline(int, void *, size_t);
ssize_t     Readn(int, void *, size_t);
void     Set_concurrency(int);
Sigfunc *Signal(int, Sigfunc *);
Sigfunc *Signal_intr(int, Sigfunc *);

#ifdef    HAVE_SIGINFO_T_STRUCT
Sigfunc_rt *Signal_rt(int, Sigfunc_rt *);
Sigfunc_rt *Signal_rt_intr(int, Sigfunc_rt *);
#endif

void     Sleep_us(unsigned int);
void     Start_time(void);
double     Stop_time(void);
void     Touch(void *, int);
int         Writable_timeo(int, int);
void     Writen(int, void *, size_t);

            /* prototypes for our Unix wrapper functions */
void    *Calloc(size_t, size_t);
void     Close(int);
void     Dup2(int, int);
int         Fcntl(int, int, void *);
pid_t     Fork(void);
long     Fpathconf(int, int);
void     Fstat(int, struct stat *);
key_t     Ftok(const char *, int);
void     Ftruncate(int, off_t);
int         Getopt(int, char *const *, const char *);
void     Gettimeofday(struct timeval *, void *);
int         Ioctl(int, int, void *);
void     Kill(pid_t, int);
off_t     Lseek(int, off_t, int);
void    *Malloc(size_t);
void     Mkfifo(const char *, mode_t);
void     Mktemp(char *);
void    *Mmap(void *, size_t, int, int, int, off_t);
void     Munmap(void *, size_t);
int         Open(const char *, int, ...);
long     Pathconf(const char *, int);
void     Pipe(int *fds);
ssize_t     Read(int, void *, size_t);
int         Select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
void     Sigaddset(sigset_t *, int);
void     Sigdelset(sigset_t *, int);
void     Sigemptyset(sigset_t *);
void     Sigfillset(sigset_t *);
int         Sigismember(const sigset_t *, int);
void     Sigpending(sigset_t *);
void     Sigprocmask(int, const sigset_t *, sigset_t *);
#ifdef    HAVE_SIGINFO_T_STRUCT
void     Sigqueue(pid_t, int, const union sigval);
#endif
#ifdef    HAVE_SIGWAIT
void     Sigwait(const sigset_t *, int *);
#endif
void     Stat(const char *, struct stat *);
char    *Strdup(const char *);
long     Sysconf(int);
void     Sysctl(int *, u_int, void *, size_t *, void *, size_t);
void     Unlink(const char *);
void    *Valloc(size_t);
pid_t     Wait(int *);
pid_t     Waitpid(pid_t, int *, int);
void     Write(int, void *, size_t);

#ifdef    HAVE_MQUEUE_H
            /* 4Posix message queues */
mqd_t     Mq_open(const char *, int, ...);
void     Mq_close(mqd_t);
void     Mq_unlink(const char *pathname);
void     Mq_send(mqd_t, const char *, size_t, unsigned int);
ssize_t     Mq_receive(mqd_t, char *, size_t, unsigned int *);
void     Mq_notify(mqd_t, const struct sigevent *);
void     Mq_getattr(mqd_t, struct mq_attr *);
void     Mq_setattr(mqd_t, const struct mq_attr *, struct mq_attr *);
#endif    /* HAVE_MQUEUE_H */

#ifdef    HAVE_SEMAPHORE_H
            /* 4Posix semaphores */
sem_t    *Sem_open(const char *, int, ...);
void     Sem_close(sem_t *);
void     Sem_unlink(const char *);
void     Sem_init(sem_t *, int, unsigned int);
void     Sem_destroy(sem_t *);
void     Sem_wait(sem_t *);
int         Sem_trywait(sem_t *);
void     Sem_post(sem_t *);
void     Sem_getvalue(sem_t *, int *);
#endif    /* HAVE_SEMAPHORE_H */

/* Note that <sys/mman.h> is defined on some systems that do not support
 * Posix shared memory (e.g., 4.4BSD), because this header predates Posix
 * and appears on any system that supports mmap().  Therefore we cannot
 * use this to determine whether the implementation supports Posix shared
 * memory or not.  We use our own HAVE_SHM_OPEN_PROTO symbol.
 */

#ifdef    HAVE_SHM_OPEN_PROTO
            /* 4Posix shared memory */
int         Shm_open(const char *, int, mode_t);
void     Shm_unlink(const char *);
#endif

#ifdef    HAVE_SYS_MSG_H
            /* 4System V message queues */
int         Msgget(key_t key, int flag);
void     Msgctl(int, int, struct msqid_ds *);
void     Msgsnd(int, const void *, size_t, int);
ssize_t     Msgrcv(int, void *, size_t, int, int);
#endif    /* HAVE_SYS_MSG_H */

#ifdef    HAVE_SYS_SEM_H
            /* 4System V semaphores */
int         Semget(key_t, int, int);
int         Semctl(int, int, int, ...);
void     Semop(int, struct sembuf *, size_t);
#endif    /* HAVE_SYS_SEM_H */

#ifdef    HAVE_SYS_SHM_H
            /* 4System V shared memory */
int         Shmget(key_t, size_t, int);
void    *Shmat(int, const void *, int);
void     Shmdt(const void *);
void     Shmctl(int, int, struct shmid_ds *);
#endif    /* HAVE_SYS_SHM_H */

            /* prototypes for our stdio wrapper functions */
void     Fclose(FILE *);
FILE    *Fdopen(int, const char *);
char    *Fgets(char *, int, FILE *);
FILE    *Fopen(const char *, const char *);
void     Fputs(const char *, FILE *);
FILE    *Popen(const char *, const char *);
int         Pclose(FILE *);

#ifdef    HAVE_FATTACH
void     Fattach(int, const char *);
#endif
#ifdef    HAVE_POLL
int         Poll(struct pollfd *, unsigned long, int);
#endif

void     err_dump(const char *, ...);
void     err_msg(const char *, ...);
void     err_quit(const char *, ...);
void     err_ret(const char *, ...);
void     err_sys(const char *, ...);

            /* prototypes for our pthread wrapper functions */
void     Pthread_attr_init(pthread_attr_t *);
void     Pthread_attr_destroy(pthread_attr_t *);
void     Pthread_attr_setdetachstate(pthread_attr_t *, int);
void     Pthread_attr_setscope(pthread_attr_t *, int);
void     Pthread_create(pthread_t *, const pthread_attr_t *,
                        void * (*)(void *), void *);
void     Pthread_join(pthread_t, void **);
void     Pthread_detach(pthread_t);
void     Pthread_kill(pthread_t, int);
void     Pthread_setcancelstate(int, int *);

void     Pthread_mutexattr_init(pthread_mutexattr_t *);
void     Pthread_mutexattr_destroy(pthread_mutexattr_t *);
void     Pthread_mutexattr_setpshared(pthread_mutexattr_t *, int);
void     Pthread_mutex_init(pthread_mutex_t *, pthread_mutexattr_t *);
void     Pthread_mutex_destroy(pthread_mutex_t *);
void     Pthread_mutex_lock(pthread_mutex_t *);
void     Pthread_mutex_unlock(pthread_mutex_t *);

void     Pthread_condattr_init(pthread_condattr_t *);
void     Pthread_condattr_destroy(pthread_condattr_t *);
void     Pthread_condattr_setpshared(pthread_condattr_t *, int);
void     Pthread_cond_broadcast(pthread_cond_t *);
void     Pthread_cond_signal(pthread_cond_t *);
void     Pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *);
void     Pthread_cond_timedwait(pthread_cond_t *, pthread_mutex_t *,
                                const struct timespec *);

void     Pthread_key_create(pthread_key_t *, void (*)(void *));
void     Pthread_setspecific(pthread_key_t, const void *);
void     Pthread_once(pthread_once_t *, void (*)(void));
long     pr_thread_id(pthread_t *);

#ifdef    HAVE_DOOR_H
            /* typedefs to simplify declarations */
typedef    void  Door_server_proc(void *, char *, size_t, door_desc_t *, size_t);
typedef    void  Door_create_proc(door_info_t *);

            /* prototypes for our doors wrapper functions */

void     Door_bind(int);
void     Door_call(int, door_arg_t *);
int         Door_create(Door_server_proc *, void *, u_int);
void     Door_cred(door_cred_t *);
void     Door_info(int, door_info_t *);
void     Door_return(char *, size_t, door_desc_t *, size_t);
void     Door_revoke(int);
void     Door_unbind(void);
Door_create_proc    *Door_server_create(Door_create_proc *);
#endif    /* HAVE_DOOR_H */

#ifdef    HAVE_RPC_RPC_H
CLIENT    *Clnt_create(const char *, u_long, u_long, const char *);
void     Clnt_control(CLIENT *, u_int, char *);
#endif

#endif    /* __unpipc_h */
//errors.h#ifndef __errors_h
#define __errors_h  

#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>  

#ifdef DEBUG
#define DPRINTF(arg) printf arg
#eles
#define DPRINTF(arg)
#endif
// 用do_while语句结束,把{}里的当作语句块
#define err_abort(code, text) do {\
  fprintf( stderr, "%s at \"%s\":%d: %s\n",\
       text, __FILE__, __LINE__, strerror(code));\
  abort(); \
  } )  

#define errno_abort(text) do{ \
  fprintf( stderr, "%s at \"%s\":%d: %s\n",       \
       text, __FILE__, __LINE__, strerror(errno)); \
  abort(); \
  } )  

#endif 
//config.h/* config.h.  Generated automatically by configure.  */
/* Define the following if you have the corresponding header */
#define    CPU_VENDOR_OS "i686-pc-linux-gnu"

/* *INDENT-OFF* */
/* #undef    HAVE_DOOR_H */                /* <door.h> */
/* #undef    HAVE_MQUEUE_H */                /* <mqueue.h> */
#define    HAVE_POLL_H 1                /* <poll.h> */
#define    HAVE_PTHREAD_H 1            /* <pthread.h> */
#define    HAVE_RPC_RPC_H 1            /* <rpc/rpc.h> */
#define    HAVE_SEMAPHORE_H 1            /* <semaphore.h> */
#define    HAVE_STRINGS_H 1            /* <strings.h> */
/* #undef    HAVE_SYS_FILIO_H */            /* <sys/filio.h> */
#define    HAVE_SYS_IOCTL_H 1            /* <sys/ioctl.h> */
#define    HAVE_SYS_IPC_H 1            /* <sys/ipc.h> */
#define    HAVE_SYS_MMAN_H 1            /* <sys/mman.h> */
#define    HAVE_SYS_MSG_H 1            /* <sys/msg.h> */
#define    HAVE_SYS_SEM_H 1            /* <sys/sem.h> */
#define    HAVE_SYS_SHM_H 1            /* <sys/shm.h> */
#define    HAVE_SYS_SELECT_H 1            /* <sys/select.h> */
#define    HAVE_SYS_SYSCTL_H 1    /* <sys/sysctl.h> */
#define    HAVE_SYS_TIME_H 1            /* <sys/time.h> */

/* Define if we can include <time.h> with <sys/time.h> */
#define    TIME_WITH_SYS_TIME 1

/* Define the following if the function is provided */
#define    HAVE_BZERO 1
/* #undef    HAVE_FATTACH */
#define    HAVE_POLL 1
#define    HAVE_PSELECT 1
#define    HAVE_SIGWAIT 1
#define    HAVE_VALLOC 1
#define    HAVE_VSNPRINTF 1

/* Define the following if the function prototype is in a header */
#define    HAVE_GETHOSTNAME_PROTO 1    /* <unistd.h> */
#define    HAVE_GETRUSAGE_PROTO 1        /* <sys/resource.h> */
/* #undef    HAVE_PSELECT_PROTO */    /* <sys/select.h> */
#define    HAVE_SHM_OPEN_PROTO 1        /* <sys/mman.h> */
#define    HAVE_SNPRINTF_PROTO 1        /* <stdio.h> */
/* #undef    HAVE_THR_SETCONCURRENCY_PROTO */        /* <thread.h> */

/* Define the following if the structure is defined. */
#define    HAVE_SIGINFO_T_STRUCT 1        /* <signal.h> */
#define    HAVE_TIMESPEC_STRUCT 1        /* <time.h> */
/* #undef    HAVE_SEMUN_UNION */        /* <sys/sem.h> */

/* Devices */
#define    HAVE_DEV_ZERO 1

/* Define the following to the appropriate datatype, if necessary */
/* #undef    int8_t */                /* <sys/types.h> */
/* #undef    int16_t */                /* <sys/types.h> */
/* #undef    int32_t */                /* <sys/types.h> */
//#define    uint8_t unsigned char                /* <sys/types.h> */
//#define    uint16_t unsigned short                /* <sys/types.h> */
//#define    uint32_t unsigned int                /* <sys/types.h> */
/* #undef    size_t */                /* <sys/types.h> */
/* #undef    ssize_t */                /* <sys/types.h> */

/* #undef    POSIX_IPC_PREFIX */
#define    RPCGEN_ANSIC 1            /* defined if rpcgen groks -C option */
/* *INDENT-ON* */
//add by jcq
//typedef unsigned long ulong_t;
#define MSG_R 0400
#define MSG_W 0200
#define _GNU_SOURCE
//让c程序在后台执行的代码void OS_Daemon()
{
    pid_t pid;

    )
    {
        fprintf(stderr, "fork1 failed: %d\n", errno);
        exit(-);
    }

    if (pid)
    {
        exit();
    }   

    setsid();

//    signal(SIGCLD, SIG_IGN);
    signal(SIGTERM, SIG_IGN);
    signal(SIGQUIT, SIG_IGN);
    signal(SIGINT, SIG_IGN);
    signal(SIGHUP, SIG_IGN);
    signal(SIGPIPE, SIG_IGN);

    )
    {
        fprintf(stderr, "fork2 failed: %d\n", errno);
        exit(-);
    }   

    if (pid)
    {
        exit();
    }   

/*
    chdir("/");
    umask(0);
*/
}
//pr_mask()//打印当前信号屏蔽字的屏蔽信号
static void pr_mask(char* ptr)
{
    sigset_t sigset;
    int errno_save;
    int ret;
    errno_save = errno;
    ret = sigprocmask(, NULL, &sigset);
    )
    {

        perror("sigprocmask error");
        exit();
    }

    printf("%s", ptr);

    if(sigismember(&sigset, SIGINT))
    {
        printf("SIGINT ");
    }
    if(sigismember(&sigset, SIGQUIT))
    {

        printf("SIGQUIT ");

    }
    if(sigismember(&sigset, SIGUSR1))
    {

        printf("SIGUSR1 ");
    }

    if(sigismember(&sigset, SIGALRM))
    {
        printf("SIGALRM ");
    }
    printf("\n");
    errno = errno_save;
}

一些IPC常用头文件的更多相关文章

  1. linux常用头文件及说明

    linux常用头文件及说明 1. Linux中一些头文件的作用: <assert.h>:ANSI C.提供断言,assert(表达式)<glib.h>:GCC.GTK,GNOM ...

  2. Linux网络常用头文件说明

    sys/types.h:数据类型定义 sys/socket.h:提供socket函数及数据结构 netinet/in.h:定义数据结构sockaddr_in arpa/inet.h:提供IP地址转换函 ...

  3. Linux中常用头文件的作用--转

    http://blog.sina.com.cn/s/blog_5c93b2ab0100q62k.html 1. Linux中一些头文件的作用: <assert.h>:ANSI C.提供断言 ...

  4. linux设备驱动程序该添加哪些头文件以及驱动常用头文件介绍(转)

    原文链接:http://blog.chinaunix.net/uid-22609852-id-3506475.html 驱动常用头文件介绍 #include <linux/***.h> 是 ...

  5. C/C++常用头文件及函数汇总

    转自: C/C++常用头文件及函数汇总 C/C++头文件一览 C #include <assert.h> //设定插入点#include <ctype.h> //字符处理#in ...

  6. OpenCV常用头文件介绍

    转载:https://www.cnblogs.com/wangguchao/p/7244483.html 1.OpenCV包含的模块 cv – 核心函数库 cvaux – 辅助函数库 cxcore – ...

  7. opencv 常用头文件介绍

    1.OpenCV包含的模块 cv – 核心函数库 cvaux – 辅助函数库 cxcore – 数据结构与线性代数库 highgui – GUI函数库 ml – 机器学习函数库 2.常用头文件: #i ...

  8. linux常用头文件

    http://blog.csdn.net/kokodudu/article/details/17361161 aio.h 异步I/Oassert.h 验证程序断言 complex 复数类complex ...

  9. linux网络编程常用头文件

    sys/types.h:数据类型定义 sys/socket.h:提供socket函数及数据结构 netinet/in.h:定义数据结构sockaddr_in arpa/inet.h:提供IP地址转换函 ...

随机推荐

  1. 第十天 1-9 rhel7-文件的归档和压缩

    大纲:文件的归档和压缩1.tar命令的使用及参数解析tar.gz.bz/bz2文件的创建.查看及解压zip/unzip命令的使用 一.文件的归档和压缩 在我们的计算机中,经常会遇到有好多文件名相似或作 ...

  2. python----tkinterm模块

    python tkinter学习——布局   目录 一.pack() 二.grid() 三.place() 四.Frame() 正文 布局 一.pack() pack()有以下几个常用属性: side ...

  3. java程序设计基础篇 复习笔记 第六单元

    第六章 一维数组 1 数组初始化语法 array initializer 2 for each loop 3 off-by-one error 通常是在循环中该使用<的地方使用了<= 4 ...

  4. 十一、dbms_random(随机数生成器)

    1.概述 提供了内置的随机数生成器,可以用于快速生成随机数. 2.包的组成 1).initialize作用:用于初始化dbms_random包,必须提供随机数种子.语法:dbms_random.ini ...

  5. PCA--主成份分析

    主成份分析(Principle Component Analysis)主要用来对数据进行降维.对于高维数据,处理起来比较麻烦,而且高维数据可能含有相关的维度,数据存在冗余,PCA通过把高维数据向低维映 ...

  6. 如何解决虚拟机中的ubuntu系统方向键与退格键不能正常使用的问题

    问题描述: 在虚拟机中安装了ubuntu系统,打开vi,当vi进入insert模式后,后退键(backspace)不能删除字符,上下左右键也对应了W,S,A,D. 解决办法: cp /etc/vim/ ...

  7. sed用法详解

    转载自: SED单行脚本快速参考(Unix 流编辑器) 如侵犯您的版权,请联系:Windeal12@qq.com ------------------------------------------- ...

  8. L163

    Chickens slaughtered in the United States, claim officials in Brussels, are not fit to grace Europea ...

  9. kd树 求k近邻 python 代码

      之前两篇随笔介绍了kd树的原理,并用python实现了kd树的构建和搜索,具体可以参考 kd树的原理 python kd树 搜索 代码 kd树常与knn算法联系在一起,knn算法通常要搜索k近邻, ...

  10. iOS-Core Data 详解

    使用Core Data 框架 Core Data框架本质就是一个ORM(对象关系映射(英语:Object Relational Mapping,简称ORM,或O/RM,或O/R mapping),是一 ...