Back to index

courier  0.68.2
Defines | Functions
waitlib.h File Reference
#include <sys/types.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define WEXITSTATUS(stat_val)   ((unsigned)(stat_val) >> 8)
#define WIFEXITED(stat_val)   (((stat_val) & 255) == 0)

Functions

void wait_reap (void(*)(pid_t, int), RETSIGTYPE(*)(int))
void wait_block ()
void wait_clear (RETSIGTYPE(*)(int))
void wait_restore ()
void wait_forchild (void(*)(pid_t, int), RETSIGTYPE(*)(int))
int wait_startchildren (unsigned nchildren, pid_t **pidptr)
int wait_reforkchild (unsigned nchildren, pid_t *pidptr, pid_t pid)

Define Documentation

#define WEXITSTATUS (   stat_val)    ((unsigned)(stat_val) >> 8)

Definition at line 19 of file waitlib.h.

#define WIFEXITED (   stat_val)    (((stat_val) & 255) == 0)

Definition at line 22 of file waitlib.h.


Function Documentation

void wait_block ( )

Definition at line 59 of file waitlib.c.

{
       signal(SIGCHLD, SIG_DFL);
}

Here is the caller graph for this function:

void wait_clear ( RETSIGTYPE(*)(int)  )

Definition at line 64 of file waitlib.c.

{
       signal(SIGCHLD, func);
}

Here is the caller graph for this function:

void wait_forchild ( void(*)(pid_t, int)  ,
RETSIGTYPE(*)(int)   
)

Definition at line 101 of file waitlib.c.

{
pid_t  p;
int    wait_stat;

       signal(SIGCHLD, SIG_DFL);
       p=wait(&wait_stat);
       signal(SIGCHLD, func);
       (*reap)(p, wait_stat);
}
void wait_reap ( void(*)(pid_t, int)  ,
RETSIGTYPE(*)(int)   
)

Definition at line 76 of file waitlib.c.

{
int    dummy;
pid_t  p;

#if    USE_WAIT3

       HOLD_CHILDREN;

       while ((p=wait3(&dummy, WNOHANG, 0)) > 0)
#else
       if ((p=wait(&dummy)) > 0)
#endif
       {
              (*func)(p, dummy);
       }

       signal(SIGCHLD, handler);

#if    USE_WAIT3
       RELEASE_CHILDREN;
#endif

}

Here is the caller graph for this function:

int wait_reforkchild ( unsigned  nchildren,
pid_t *  pidptr,
pid_t  pid 
)

Definition at line 95 of file waitlib2.c.

{
unsigned i;

       for (i=0; i<nchildren; i++)
              if (pidptr[i] == pid)       break;

       if (i >= nchildren)  return (0);

       switch ((pidptr[i]=fork())) {
       case 0:
              wait_restore();      /* Just in case */
              return (1);
       case -1:
              return (-1);
       default:
              break;
       }
       return (0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void wait_restore ( )

Definition at line 69 of file waitlib.c.

{
       signal(SIGCHLD, SIG_DFL);
}

Here is the caller graph for this function:

int wait_startchildren ( unsigned  nchildren,
pid_t **  pidptr 
)

Definition at line 35 of file waitlib2.c.

{
int    pipefd[2];
pid_t  p;
unsigned i;

       if (!pidptr)
       {
              if (static_pid_buf)  free(static_pid_buf);
              static_pid_buf=0;
              pidptr= &static_pid_buf;
       }

       if (*pidptr == 0 && (*pidptr=malloc(nchildren * sizeof(pid_t))) == 0)
              return (-1);

       if (pipe(pipefd) < 0)       return (-1);

       signal(SIGCHLD, start_reap);
       wait_block();
       for (i=0; i<nchildren; i++)
       {
              p=fork();
              if (p < 0)
              {
                     while (i)
                     {
                            kill( (*pidptr)[--i], SIGKILL);
                            wait_forchild(start_reaper, start_reap);
                     }
                     close(pipefd[0]);
                     close(pipefd[1]);
                     wait_clear(start_reap);
                     signal(SIGCHLD, SIG_DFL);
                     return (-1);
              }

              if (p == 0)
              {
              char   buf;

                     wait_restore();
                     close(pipefd[1]);
                     if (read(pipefd[0], &buf, 1) != 1)
                            exit(1);
                     close(pipefd[0]);
                     return (1);
              }

              (*pidptr)[i]=p;
       }
       wait_restore();
       close(pipefd[0]);
       for (i=0; i<nchildren; i++)
              if (write(pipefd[1], "", 1) < 0)
                     ; /* Shut gcc up */
       close(pipefd[1]);
       return (0);
}

Here is the call graph for this function:

Here is the caller graph for this function: