Back to index

php5  5.3.10
Functions | Variables
fpm_signals.c File Reference
#include "fpm_config.h"
#include <signal.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include "fpm.h"
#include "fpm_signals.h"
#include "fpm_sockets.h"
#include "fpm_php.h"
#include "zlog.h"

Go to the source code of this file.

Functions

static void sig_soft_quit (int signo)
static void sig_handler (int signo)
int fpm_signals_init_main ()
int fpm_signals_init_child ()
int fpm_signals_get_fd ()

Variables

static int sp [2]
const char * fpm_signal_names [NSIG+1]

Function Documentation

Definition at line 246 of file fpm_signals.c.

{
       return sp[0];
}

Here is the caller graph for this function:

Definition at line 217 of file fpm_signals.c.

{
       struct sigaction act, act_dfl;

       memset(&act, 0, sizeof(act));
       memset(&act_dfl, 0, sizeof(act_dfl));

       act.sa_handler = &sig_soft_quit;
       act.sa_flags |= SA_RESTART;

       act_dfl.sa_handler = SIG_DFL;

       close(sp[0]);
       close(sp[1]);

       if (0 > sigaction(SIGTERM,  &act_dfl,  0) ||
           0 > sigaction(SIGINT,   &act_dfl,  0) ||
           0 > sigaction(SIGUSR1,  &act_dfl,  0) ||
           0 > sigaction(SIGUSR2,  &act_dfl,  0) ||
           0 > sigaction(SIGCHLD,  &act_dfl,  0) ||
           0 > sigaction(SIGQUIT,  &act,      0)) {

              zlog(ZLOG_SYSERROR, "failed to init child signals: sigaction()");
              return -1;
       }
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 180 of file fpm_signals.c.

{
       struct sigaction act;

       if (0 > socketpair(AF_UNIX, SOCK_STREAM, 0, sp)) {
              zlog(ZLOG_SYSERROR, "failed to init signals: socketpair()");
              return -1;
       }

       if (0 > fd_set_blocked(sp[0], 0) || 0 > fd_set_blocked(sp[1], 0)) {
              zlog(ZLOG_SYSERROR, "failed to init signals: fd_set_blocked()");
              return -1;
       }

       if (0 > fcntl(sp[0], F_SETFD, FD_CLOEXEC) || 0 > fcntl(sp[1], F_SETFD, FD_CLOEXEC)) {
              zlog(ZLOG_SYSERROR, "falied to init signals: fcntl(F_SETFD, FD_CLOEXEC)");
              return -1;
       }

       memset(&act, 0, sizeof(act));
       act.sa_handler = sig_handler;
       sigfillset(&act.sa_mask);

       if (0 > sigaction(SIGTERM,  &act, 0) ||
           0 > sigaction(SIGINT,   &act, 0) ||
           0 > sigaction(SIGUSR1,  &act, 0) ||
           0 > sigaction(SIGUSR2,  &act, 0) ||
           0 > sigaction(SIGCHLD,  &act, 0) ||
           0 > sigaction(SIGQUIT,  &act, 0)) {

              zlog(ZLOG_SYSERROR, "failed to init signals: sigaction()");
              return -1;
       }
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void sig_handler ( int  signo) [static]

Definition at line 154 of file fpm_signals.c.

{
       static const char sig_chars[NSIG + 1] = {
              [SIGTERM] = 'T',
              [SIGINT]  = 'I',
              [SIGUSR1] = '1',
              [SIGUSR2] = '2',
              [SIGQUIT] = 'Q',
              [SIGCHLD] = 'C'
       };
       char s;
       int saved_errno;

       if (fpm_globals.parent_pid != getpid()) {
              /* prevent a signal race condition when child process
                     have not set up it's own signal handler yet */
              return;
       }

       saved_errno = errno;
       s = sig_chars[signo];
       write(sp[1], &s, sizeof(s));
       errno = saved_errno;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void sig_soft_quit ( int  signo) [static]

Definition at line 142 of file fpm_signals.c.

{
       int saved_errno = errno;

       /* closing fastcgi listening socket will force fcgi_accept() exit immediately */
       close(0);
       socket(AF_UNIX, SOCK_STREAM, 0);
       fpm_php_soft_quit();
       errno = saved_errno;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

const char* fpm_signal_names[NSIG+1]

Definition at line 25 of file fpm_signals.c.

int sp[2] [static]

Definition at line 23 of file fpm_signals.c.