Back to index

php5  5.3.10
Functions
fpm_stdio.h File Reference
#include "fpm_worker_pool.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int fpm_stdio_init_main ()
int fpm_stdio_init_final ()
int fpm_stdio_init_child (struct fpm_worker_pool_s *wp)
int fpm_stdio_prepare_pipes (struct fpm_child_s *child)
void fpm_stdio_child_use_pipes (struct fpm_child_s *child)
int fpm_stdio_parent_use_pipes (struct fpm_child_s *child)
int fpm_stdio_discard_pipes (struct fpm_child_s *child)
int fpm_stdio_open_error_log (int reopen)

Function Documentation

void fpm_stdio_child_use_pipes ( struct fpm_child_s child)

Definition at line 248 of file fpm_stdio.c.

{
       if (child->wp->config->catch_workers_output) {
              dup2(fd_stdout[1], STDOUT_FILENO);
              dup2(fd_stderr[1], STDERR_FILENO);
              close(fd_stdout[0]); close(fd_stdout[1]);
              close(fd_stderr[0]); close(fd_stderr[1]);
       } else {
              /* stdout of parent is always /dev/null */
              dup2(STDOUT_FILENO, STDERR_FILENO);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 233 of file fpm_stdio.c.

{
       if (0 == child->wp->config->catch_workers_output) { /* not required */
              return 0;
       }

       close(fd_stdout[1]);
       close(fd_stderr[1]);

       close(fd_stdout[0]);
       close(fd_stderr[0]);
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 62 of file fpm_stdio.c.

{
#ifdef HAVE_SYSLOG_H
       if (fpm_globals.error_log_fd == ZLOG_SYSLOG) {
              closelog(); /* ensure to close syslog not to interrupt with PHP syslog code */
       } else
#endif
       if (fpm_globals.error_log_fd > 0) {
              close(fpm_globals.error_log_fd);
       }
       fpm_globals.error_log_fd = -1;
       zlog_set_fd(-1);

       if (wp->listening_socket != STDIN_FILENO) {
              if (0 > dup2(wp->listening_socket, STDIN_FILENO)) {
                     zlog(ZLOG_SYSERROR, "failed to init child stdio: dup2()");
                     return -1;
              }
       }
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 44 of file fpm_stdio.c.

{
       if (fpm_global_config.daemonize) {
              /* prevent duping if logging to syslog */
              if (fpm_globals.error_log_fd > 0 && fpm_globals.error_log_fd != STDERR_FILENO) {

                     /* there might be messages to stderr from other parts of the code, we need to log them all */
                     if (0 > dup2(fpm_globals.error_log_fd, STDERR_FILENO)) {
                            zlog(ZLOG_SYSERROR, "failed to init stdio: dup2()");
                            return -1;
                     }
              }
       }
       zlog_set_launched();
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 26 of file fpm_stdio.c.

{
       int fd = open("/dev/null", O_RDWR);

       if (0 > fd) {
              zlog(ZLOG_SYSERROR, "failed to init stdio: open(\"/dev/null\")");
              return -1;
       }

       if (0 > dup2(fd, STDIN_FILENO) || 0 > dup2(fd, STDOUT_FILENO)) {
              zlog(ZLOG_SYSERROR, "failed to init stdio: dup2()");
              return -1;
       }
       close(fd);
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 262 of file fpm_stdio.c.

{
       int fd;

#ifdef HAVE_SYSLOG_H
       if (!strcasecmp(fpm_global_config.error_log, "syslog")) {
              openlog(fpm_global_config.syslog_ident, LOG_PID | LOG_CONS, fpm_global_config.syslog_facility);
              fpm_globals.error_log_fd = ZLOG_SYSLOG;
              if (fpm_global_config.daemonize) {
                     zlog_set_fd(fpm_globals.error_log_fd);
              }
              return 0;
       }
#endif

       fd = open(fpm_global_config.error_log, O_WRONLY | O_APPEND | O_CREAT, S_IRUSR | S_IWUSR);
       if (0 > fd) {
              zlog(ZLOG_SYSERROR, "failed to open error_log (%s)", fpm_global_config.error_log);
              return -1;
       }

       if (reopen) {
              if (fpm_global_config.daemonize) {
                     dup2(fd, STDERR_FILENO);
              }

              dup2(fd, fpm_globals.error_log_fd);
              close(fd);
              fd = fpm_globals.error_log_fd; /* for FD_CLOSEXEC to work */
       } else {
              fpm_globals.error_log_fd = fd;
              if (fpm_global_config.daemonize) {
                     zlog_set_fd(fpm_globals.error_log_fd);
              }
       }
       fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 212 of file fpm_stdio.c.

{
       if (0 == child->wp->config->catch_workers_output) { /* not required */
              return 0;
       }

       close(fd_stdout[1]);
       close(fd_stderr[1]);

       child->fd_stdout = fd_stdout[0];
       child->fd_stderr = fd_stderr[0];

       fpm_event_set(&child->ev_stdout, child->fd_stdout, FPM_EV_READ, fpm_stdio_child_said, child);
       fpm_event_add(&child->ev_stdout, 0);

       fpm_event_set(&child->ev_stderr, child->fd_stderr, FPM_EV_READ, fpm_stdio_child_said, child);
       fpm_event_add(&child->ev_stderr, 0);
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 182 of file fpm_stdio.c.

{
       if (0 == child->wp->config->catch_workers_output) { /* not required */
              return 0;
       }

       if (0 > pipe(fd_stdout)) {
              zlog(ZLOG_SYSERROR, "failed to prepare the stdout pipe");
              return -1;
       }

       if (0 > pipe(fd_stderr)) {
              zlog(ZLOG_SYSERROR, "failed to prepare the stderr pipe");
              close(fd_stdout[0]);
              close(fd_stdout[1]);
              return -1;
       }

       if (0 > fd_set_blocked(fd_stdout[0], 0) || 0 > fd_set_blocked(fd_stderr[0], 0)) {
              zlog(ZLOG_SYSERROR, "failed to unblock pipes");
              close(fd_stdout[0]);
              close(fd_stdout[1]);
              close(fd_stderr[0]);
              close(fd_stderr[1]);
              return -1;
       }
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function: