int log_open(log_t **log,const char *filename) { int rc; *log = NULL; (*log) = (log_t *)calloc(1,sizeof(log_t)); log_level_set(*log,LOG_ERR); if(!filename){ return -1; } if (*filename == '|') { rc = log_child(filename + 1, &((*log)->logfile)); log_error(*log, "Start ErrorLog process!"); if(rc != 0) return -1; } else{ (*log)->logfile = open(filename,O_CREAT|O_RDWR|O_APPEND|O_LARGEFILE,0644); if((*log)->logfile != -1) { return 0; } } return 0; }
AP_DECLARE(piped_log *) ap_open_piped_log(apr_pool_t *p, const char *program) { piped_log *pl; apr_file_t *dummy = NULL; int rc; rc = log_child(p, program, &dummy, 0); if (rc != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_STARTUP, rc, NULL, "Couldn't start piped log process"); return NULL; } pl = apr_palloc(p, sizeof (*pl)); pl->p = p; ap_piped_log_read_fd(pl) = NULL; ap_piped_log_write_fd(pl) = dummy; apr_pool_cleanup_register(p, pl, piped_log_cleanup, piped_log_cleanup); return pl; }
/* Open the error log for the given server_rec. If IS_MAIN is * non-zero, s is the main server. */ static int open_error_log(server_rec *s, int is_main, apr_pool_t *p) { const char *fname; int rc; if (*s->error_fname == '|') { apr_file_t *dummy = NULL; /* Spawn a new child logger. If this is the main server_rec, * the new child must use a dummy stderr since the current * stderr might be a pipe to the old logger. Otherwise, the * child inherits the parents stderr. */ rc = log_child(p, s->error_fname + 1, &dummy, is_main); if (rc != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_STARTUP, rc, NULL, "Couldn't start ErrorLog process"); return DONE; } s->error_log = dummy; } #ifdef HAVE_SYSLOG else if (!strncasecmp(s->error_fname, "syslog", 6)) { if ((fname = strchr(s->error_fname, ':'))) { const TRANS *fac; fname++; for (fac = facilities; fac->t_name; fac++) { if (!strcasecmp(fname, fac->t_name)) { openlog(ap_server_argv0, LOG_NDELAY|LOG_CONS|LOG_PID, fac->t_val); s->error_log = NULL; return OK; } } } else { openlog(ap_server_argv0, LOG_NDELAY|LOG_CONS|LOG_PID, LOG_LOCAL7); } s->error_log = NULL; } #endif else { fname = ap_server_root_relative(p, s->error_fname); if (!fname) { ap_log_error(APLOG_MARK, APLOG_STARTUP, APR_EBADPATH, NULL, "%s: Invalid error log path %s.", ap_server_argv0, s->error_fname); return DONE; } if ((rc = apr_file_open(&s->error_log, fname, APR_APPEND | APR_WRITE | APR_CREATE | APR_LARGEFILE, APR_OS_DEFAULT, p)) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_STARTUP, rc, NULL, "%s: could not open error log file %s.", ap_server_argv0, fname); return DONE; } } return OK; }
/* Open the error log for the given server_rec. If IS_MAIN is * non-zero, s is the main server. */ static int open_error_log(server_rec *s, int is_main, apr_pool_t *p) { const char *fname; int rc; if (*s->error_fname == '|') { apr_file_t *dummy = NULL; apr_cmdtype_e cmdtype = APR_SHELLCMD_ENV; fname = s->error_fname + 1; /* In 2.4 favor PROGRAM_ENV, accept "||prog" syntax for compatibility * and "|$cmd" to override the default. * Any 2.2 backport would continue to favor SHELLCMD_ENV so there * accept "||prog" to override, and "|$cmd" to ease conversion. */ if (*fname == '|') { cmdtype = APR_PROGRAM_ENV; ++fname; } if (*fname == '$') ++fname; /* Spawn a new child logger. If this is the main server_rec, * the new child must use a dummy stderr since the current * stderr might be a pipe to the old logger. Otherwise, the * child inherits the parents stderr. */ rc = log_child(p, fname, &dummy, cmdtype, is_main); if (rc != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_STARTUP, rc, NULL, "Couldn't start ErrorLog process"); return DONE; } s->error_log = dummy; } #ifdef HAVE_SYSLOG else if (!strncasecmp(s->error_fname, "syslog", 6)) { if ((fname = strchr(s->error_fname, ':'))) { const TRANS *fac; fname++; for (fac = facilities; fac->t_name; fac++) { if (!strcasecmp(fname, fac->t_name)) { openlog(ap_server_argv0, LOG_NDELAY|LOG_CONS|LOG_PID, fac->t_val); s->error_log = NULL; return OK; } } } else { openlog(ap_server_argv0, LOG_NDELAY|LOG_CONS|LOG_PID, LOG_LOCAL7); } s->error_log = NULL; } #endif else { fname = ap_server_root_relative(p, s->error_fname); if (!fname) { ap_log_error(APLOG_MARK, APLOG_STARTUP, APR_EBADPATH, NULL, "%s: Invalid error log path %s.", ap_server_argv0, s->error_fname); return DONE; } if ((rc = apr_file_open(&s->error_log, fname, APR_APPEND | APR_WRITE | APR_CREATE | APR_LARGEFILE, APR_OS_DEFAULT, p)) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_STARTUP, rc, NULL, "%s: could not open error log file %s.", ap_server_argv0, fname); return DONE; } } return OK; }