static int piped_log_child (void *cmd, child_info *pinfo) { /* Child process code for 'TransferLog "|..."'; * may want a common framework for this, since I expect it will * be common for other foo-loggers to want this sort of thing... */ int child_pid = 1; ap_cleanup_for_exec(); #ifdef SIGHUP signal (SIGHUP, SIG_IGN); #endif #if defined(WIN32) child_pid = spawnl (_P_NOWAIT, SHELL_PATH, SHELL_PATH, "/c", (char *)cmd, NULL); return(child_pid); #elif defined(__EMX__) /* For OS/2 we need to use a '/' */ execl (SHELL_PATH, SHELL_PATH, "/c", (char *)cmd, NULL); #else execl (SHELL_PATH, SHELL_PATH, "-c", (char *)cmd, NULL); #endif perror ("exec"); fprintf (stderr, "Exec of shell for logging failed!!!\n"); return(child_pid); }
static int error_log_child (void *cmd, child_info *pinfo) { /* Child process code for 'ErrorLog "|..."'; * may want a common framework for this, since I expect it will * be common for other foo-loggers to want this sort of thing... */ int child_pid = 0; ap_cleanup_for_exec(); #ifdef SIGHUP /* No concept of a child process on Win32 */ signal (SIGHUP, SIG_IGN); #endif /* ndef SIGHUP */ #if defined(WIN32) child_pid = spawnl (_P_NOWAIT, SHELL_PATH, SHELL_PATH, "/c", (char *)cmd, NULL); return(child_pid); #elif defined(__EMX__) /* For OS/2 we need to use a '/' */ execl (SHELL_PATH, SHELL_PATH, "/c", (char *)cmd, NULL); #else execl (SHELL_PATH, SHELL_PATH, "-c", (char *)cmd, NULL); #endif exit (1); /* NOT REACHED */ return(child_pid); }
static int dirsize(void *rp, child_info *pinfo) { char **env; int child_pid; request_rec *r = (request_rec *) rp; env = ap_create_environment(r->pool, r->subprocess_env); ap_error_log2stderr(r->server); r->filename = "/usr/bin/du"; // fixme: ugly! r->args = ap_pstrcat(r->pool, "-sk+", r->path_info, NULL); ap_cleanup_for_exec(); child_pid = ap_call_exec(r, pinfo, r->filename, env, 0); #ifdef WIN32 return(child_pid); #else ap_log_error(APLOG_MARK, APLOG_ERR, NULL, "exec of %s failed", r->filename); exit(0); return(0); #endif }
int suphp_source_child(void *rp, child_info *cinfo) { request_rec *r = (request_rec *) rp; suphp_conf *conf; pool *p = r->main ? r->main->pool : r->pool; char **argv, **env; table *empty_table = ap_make_table(p, 0); conf = ap_get_module_config(r->server->module_config, &suphp_module); /* We want to log output written to stderr */ ap_error_log2stderr(r->server); /* prepare argv for new process */ argv = ap_palloc(p, 4 * sizeof(char *)); argv[0] = ap_pstrdup(p, conf->php_path); argv[1] = "-s"; argv[2] = ap_pstrdup(p, r->filename); argv[3] = NULL; /* prepare environment */ env = ap_create_environment(p, empty_table); /* We cannot use ap_call_exec because of the interference with suExec */ /* So we do everything ourselves */ /* mandatory cleanup before execution */ ap_cleanup_for_exec(); execve(ap_pstrdup(p, conf->php_path), argv, env); /* We are still here? Okay - exec failed */ ap_log_error(APLOG_MARK, APLOG_ERR, NULL, "exec of %s failed", conf->php_path); exit(0); /* NOT REACHED */ return (0); }
static int piped_log_spawn (piped_log *pl) { int pid; ap_block_alarms(); pid = fork(); if (pid == 0) { /* XXX: this needs porting to OS2 and WIN32 */ /* XXX: need to check what open fds the logger is actually passed, * XXX: and CGIs for that matter ... cleanup_for_exec *should* * XXX: close all the relevant stuff, but hey, it could be broken. */ RAISE_SIGSTOP(PIPED_LOG_SPAWN); /* we're now in the child */ close (STDIN_FILENO); dup2 (pl->fds[0], STDIN_FILENO); ap_cleanup_for_exec (); signal (SIGCHLD, SIG_DFL); /* for HPUX */ signal (SIGHUP, SIG_IGN); execl (SHELL_PATH, SHELL_PATH, "-c", pl->program, NULL); fprintf (stderr, "piped_log_spawn: unable to exec %s -c '%s': %s\n", SHELL_PATH, pl->program, strerror (errno)); exit (1); } if (pid == -1) { fprintf (stderr, "piped_log_spawn: unable to fork(): %s\n", strerror (errno)); ap_unblock_alarms (); return -1; } ap_unblock_alarms(); pl->pid = pid; ap_register_other_child (pid, piped_log_maintenance, pl, pl->fds[1]); return 0; }
int suphp_child(void *rp, child_info *cinfo) { request_rec *r = (request_rec *) rp; core_dir_config *core_conf; pool *p = r->main ? r->main->pool : r->pool; char **argv, **env; core_conf = (core_dir_config *) ap_get_module_config( r->per_dir_config, &core_module); /* We want to log output written to stderr */ ap_error_log2stderr(r->server); /* prepare argv for new process */ argv = ap_palloc(p, 2 * sizeof(char *)); argv[0] = SUPHP_PATH_TO_SUPHP; argv[1] = NULL; /* prepare environment */ env = ap_create_environment(p, r->subprocess_env); /* We cannot use ap_call_exec because of the interference with suExec */ /* So we do everything ourselves */ /* Set resource limits from core config */ #ifdef RLIMIT_CPU if (core_conf->limit_cpu != NULL) { if ((setrlimit(RLIMIT_CPU, core_conf->limit_cpu)) != 0) { ap_log_error(APLOG_MARK, APLOG_ERR, r->server, "setrlimit: failed to set CPU usage limit"); } } #endif /* RLIMIT_CPU */ #ifdef RLIMIT_NPROC if (core_conf->limit_nproc != NULL) { if ((setrlimit(RLIMIT_NPROC, core_conf->limit_nproc)) != 0) { ap_log_error(APLOG_MARK, APLOG_ERR, r->server, "setrlimit: failed to set process limit"); } } #endif /* RLIMIT_NPROC */ #ifdef RLIMIT_AS if (core_conf->limit_mem != NULL) { if ((setrlimit(RLIMIT_AS, core_conf->limit_mem)) != 0) { ap_log_error(APLOG_MARK, APLOG_ERR, r->server, "setrlimit: failed to set memory limit"); } } #endif /* RLIMIT_VMEM */ #ifdef RLIMIT_DATA if (core_conf->limit_mem != NULL) { if ((setrlimit(RLIMIT_DATA, core_conf->limit_mem)) != 0) { ap_log_error(APLOG_MARK, APLOG_ERR, r->server, "setrlimit: failed to set memory limit"); } } #endif /* RLIMIT_VMEM */ #ifdef RLIMIT_VMEM if (core_conf->limit_mem != NULL) { if ((setrlimit(RLIMIT_VMEM, core_conf->limit_mem)) != 0) { ap_log_error(APLOG_MARK, APLOG_ERR, r->server, "setrlimit: failed to set memory limit"); } } #endif /* RLIMIT_VMEM */ /* mandatory cleanup before execution */ ap_cleanup_for_exec(); execve(SUPHP_PATH_TO_SUPHP, argv, env); /* We are still here? Okay - exec failed */ ap_log_error(APLOG_MARK, APLOG_ERR, NULL, "exec of %s failed", SUPHP_PATH_TO_SUPHP); exit(0); /* NOT REACHED */ return (0); }