log.c revision 52bdaf788c70b03fe6f68a5a489cdbe11fb184ef
842ae4bd224140319ae7feec1872b93dfd491143fielding/* Licensed to the Apache Software Foundation (ASF) under one or more
842ae4bd224140319ae7feec1872b93dfd491143fielding * contributor license agreements. See the NOTICE file distributed with
842ae4bd224140319ae7feec1872b93dfd491143fielding * this work for additional information regarding copyright ownership.
842ae4bd224140319ae7feec1872b93dfd491143fielding * The ASF licenses this file to You under the Apache License, Version 2.0
842ae4bd224140319ae7feec1872b93dfd491143fielding * (the "License"); you may not use this file except in compliance with
842ae4bd224140319ae7feec1872b93dfd491143fielding * the License. You may obtain a copy of the License at
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * Unless required by applicable law or agreed to in writing, software
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * distributed under the License is distributed on an "AS IS" BASIS,
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * See the License for the specific language governing permissions and
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * limitations under the License.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * http_log.c: Dealing with the logs and errors
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Rob McCool
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingtypedef struct {
cb9e6e5c78f5a1690214e9548250fc6af1fc73b5wroweint AP_DECLARE_DATA ap_default_loglevel = DEFAULT_LOGLEVEL;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick/* track pipe handles to close in child process */
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawicktypedef struct read_handle_t {
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick/* clear_handle_list() is called when plog is cleared; at that
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick * point we need to forget about our old list of pipe read
649c9dd342a580016d29c2866de88a4609eb6457wrowe * handles. We let the plog cleanups close the actual pipes.
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick/* remember to close this handle in the child process */
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawickstatic void close_handle_in_child(apr_pool_t *p, apr_file_t *f)
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawickvoid ap_logs_child_init(apr_pool_t *p, server_rec *s)
e8f95a682820a599fe41b22977010636be5c2717jimAP_DECLARE(apr_status_t) ap_replace_stderr_log(apr_pool_t *p,
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe const char *fname)
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe "%s: could not open error log file %s.",
649c9dd342a580016d29c2866de88a4609eb6457wrowe /* This is safe provided we revert it when we are finished.
649c9dd342a580016d29c2866de88a4609eb6457wrowe * We don't manager the callers pool!
649c9dd342a580016d29c2866de88a4609eb6457wrowe if ((rc = apr_file_open_stderr(&stderr_log, stderr_pool))
649c9dd342a580016d29c2866de88a4609eb6457wrowe if ((rc = apr_file_dup2(stderr_log, stderr_file, stderr_pool))
649c9dd342a580016d29c2866de88a4609eb6457wrowe * You might ponder why stderr_pool should survive?
649c9dd342a580016d29c2866de88a4609eb6457wrowe * The trouble is, stderr_pool may have s_main->error_log,
649c9dd342a580016d29c2866de88a4609eb6457wrowe * so we aren't in a position to destory stderr_pool until
649c9dd342a580016d29c2866de88a4609eb6457wrowe * the next recycle. There's also an apparent bug which
649c9dd342a580016d29c2866de88a4609eb6457wrowe * is not; if some folk decided to call this function before
649c9dd342a580016d29c2866de88a4609eb6457wrowe * the core open error logs hook, this pool won't survive.
649c9dd342a580016d29c2866de88a4609eb6457wrowe * Neither does the stderr logger, so this isn't a problem.
649c9dd342a580016d29c2866de88a4609eb6457wrowe /* Revert, see above */
760b90f5b0bb414646deb6a3a2a53c14bf49bf3dwrowe "unable to replace stderr with error log file");
76185d819b745e953dd2cd636fbdd515c333e4a4trawickstatic void log_child_errfn(apr_pool_t *pool, apr_status_t err,
399cf0e5e061b49593817421b94305889fa6bc1fjorton/* Create a child process running PROGNAME with a pipe connected to
399cf0e5e061b49593817421b94305889fa6bc1fjorton * the childs stdin. The write-end of the pipe will be placed in
399cf0e5e061b49593817421b94305889fa6bc1fjorton * *FPIN on successful return. If dummy_stderr is non-zero, the
399cf0e5e061b49593817421b94305889fa6bc1fjorton * stderr for the child will be the same as the stdout of the parent.
399cf0e5e061b49593817421b94305889fa6bc1fjorton * Otherwise the child will inherit the stderr from the parent. */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougmstatic int log_child(apr_pool_t *p, const char *progname,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* Child process code for 'ErrorLog "|..."';
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * may want a common framework for this, since I expect it will
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * be common for other foo-loggers to want this sort of thing...
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh if (((rc = apr_procattr_create(&procattr, p)) == APR_SUCCESS)
76185d819b745e953dd2cd636fbdd515c333e4a4trawick && ((rc = apr_procattr_error_check_set(procattr, 1)) == APR_SUCCESS)
ff0436077dc959b17a6f87825e4a106d211224c1wrowe && ((rc = apr_procattr_child_errfn_set(procattr, log_child_errfn))
fa4e5ac791dd1c84df616b28d4ee9751efe9c64frbb const char *pname;
8a3228198adb03e6996f7738c361a612777ecab6aaron procnew = (apr_proc_t *)apr_pcalloc(p, sizeof(*procnew));
ff0436077dc959b17a6f87825e4a106d211224c1wrowe if ((rc = apr_file_open_stdout(&errfile, p)) == APR_SUCCESS)
ff0436077dc959b17a6f87825e4a106d211224c1wrowe rc = apr_procattr_child_err_set(procattr, errfile, NULL);
066877f1a045103acfdd376d48cdd473c33f409bdougm rc = apr_proc_create(procnew, pname, (const char * const *)args,
d521bfef0e1a65993d5e302628ac68a2c91a195ftrawick apr_pool_note_subprocess(p, procnew, APR_KILL_AFTER_TIMEOUT);
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick /* read handle to pipe not kept open, so no need to call
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick * close_handle_in_child()
399cf0e5e061b49593817421b94305889fa6bc1fjorton/* Open the error log for the given server_rec. If IS_MAIN is
399cf0e5e061b49593817421b94305889fa6bc1fjorton * non-zero, s is the main server. */
399cf0e5e061b49593817421b94305889fa6bc1fjortonstatic int open_error_log(server_rec *s, int is_main, apr_pool_t *p)
061c3874622b67beff724876b9bd1b1f291f2eaafielding const char *fname;
399cf0e5e061b49593817421b94305889fa6bc1fjorton /* Spawn a new child logger. If this is the main server_rec,
399cf0e5e061b49593817421b94305889fa6bc1fjorton * the new child must use a dummy stderr since the current
399cf0e5e061b49593817421b94305889fa6bc1fjorton * stderr might be a pipe to the old logger. Otherwise, the
399cf0e5e061b49593817421b94305889fa6bc1fjorton * child inherits the parents stderr. */
399cf0e5e061b49593817421b94305889fa6bc1fjorton rc = log_child(p, s->error_fname + 1, &dummy, is_main);
f5fccb8eae1f1a5f212a5bda878479c281f36512trawick "Couldn't start ErrorLog process");
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strncasecmp(s->error_fname, "syslog", 6)) {
8a3228198adb03e6996f7738c361a612777ecab6aaron openlog(ap_server_argv0, LOG_NDELAY|LOG_CONS|LOG_PID, LOG_LOCAL7);
32c4bc04f89b16521718145dc731f750144d7b38wrowe ap_log_error(APLOG_MARK, APLOG_STARTUP, APR_EBADPATH, NULL,
32c4bc04f89b16521718145dc731f750144d7b38wrowe "%s: Invalid error log path %s.",
2b484455736f4c30447aa852764f53282cbeb5ddrbb "%s: could not open error log file %s.",
e8f95a682820a599fe41b22977010636be5c2717jimint ap_open_logs(apr_pool_t *pconf, apr_pool_t *p /* plog */,
649c9dd342a580016d29c2866de88a4609eb6457wrowe /* Register to throw away the read_handles list when we
649c9dd342a580016d29c2866de88a4609eb6457wrowe * cleanup plog. Upon fork() for the apache children,
649c9dd342a580016d29c2866de88a4609eb6457wrowe * this read_handles list is closed so only the parent
649c9dd342a580016d29c2866de88a4609eb6457wrowe * can relaunch a lost log child. These read handles
649c9dd342a580016d29c2866de88a4609eb6457wrowe * are always closed on exec.
649c9dd342a580016d29c2866de88a4609eb6457wrowe * We won't care what happens to our stderr log child
649c9dd342a580016d29c2866de88a4609eb6457wrowe * between log phases, so we don't mind losing stderr's
649c9dd342a580016d29c2866de88a4609eb6457wrowe * read_handle a little bit early.
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick apr_pool_cleanup_register(p, NULL, clear_handle_list,
649c9dd342a580016d29c2866de88a4609eb6457wrowe /* HERE we need a stdout log that outlives plog.
649c9dd342a580016d29c2866de88a4609eb6457wrowe * We *presume* the parent of plog is a process
649c9dd342a580016d29c2866de88a4609eb6457wrowe * or global pool which spans server restarts.
649c9dd342a580016d29c2866de88a4609eb6457wrowe * Create our stderr_pool as a child of the plog's
649c9dd342a580016d29c2866de88a4609eb6457wrowe * parent pool.
ab43b4a17b2ac31ccb1cf280be8c42a8a314cecbjorton /* Replace existing stderr with new log. */
649c9dd342a580016d29c2866de88a4609eb6457wrowe rv = apr_file_dup2(stderr_log, s_main->error_log, stderr_p);
ec727afb817df0e5202135278c0d2902923cc980stoddard "unable to replace stderr with error_log");
649c9dd342a580016d29c2866de88a4609eb6457wrowe /* We are done with stderr_pool, close it, killing
649c9dd342a580016d29c2866de88a4609eb6457wrowe * the previous generation's stderr logger
188dff19ac1e71ffd25752d1a4f8d71f9f563305wrowe * Now that we have dup'ed s_main->error_log to stderr_log
188dff19ac1e71ffd25752d1a4f8d71f9f563305wrowe * close it and set s_main->error_log to stderr_log. This avoids
188dff19ac1e71ffd25752d1a4f8d71f9f563305wrowe * this fd being inherited by the next piped logger who would
188dff19ac1e71ffd25752d1a4f8d71f9f563305wrowe * keep open the writing end of the pipe that this one uses
188dff19ac1e71ffd25752d1a4f8d71f9f563305wrowe * as stdin. This in turn would prevent the piped logger from
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* note that stderr may still need to be replaced with something
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * because it points to the old error log, or back to the tty
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * of the submitter.
0f57a69cc84c59eacda1179763ae42ca88f1a577wrowe * XXX: This is BS - /dev/null is non-portable
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (replace_stderr && freopen("/dev/null", "w", stderr) == NULL) {
8a3228198adb03e6996f7738c361a612777ecab6aaron "unable to replace stderr with /dev/null");
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding for (virt = s_main->next; virt; virt = virt->next) {
8a3228198adb03e6996f7738c361a612777ecab6aaron if (q == virt) {
bdf833c0329ee171eb99efe9c037b6ed653c5007aaron apr_file_dup2(s->error_log, errfile, s->process->pool);
2261031aa94be82d7e6b1b8c367afc1b282317f5ianhstatic void log_error_core(const char *file, int line, int level,
d2e443764d6855a4a06c8eb2b7708ab9b465ddeerbb const char *referer;
e34223f72e630187c4d8ac7c22da5096c833eb20trawick if (r && r->connection) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (s == NULL) {
8a3228198adb03e6996f7738c361a612777ecab6aaron * If we are doing stderr logging (startup), don't log messages that are
8a3228198adb03e6996f7738c361a612777ecab6aaron * above the default server log level unless it is a startup/shutdown
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (s->error_log) {
8a3228198adb03e6996f7738c361a612777ecab6aaron * If we are doing normal logging, don't log messages that are
8a3228198adb03e6996f7738c361a612777ecab6aaron * above the server log level unless it is a startup/shutdown notice
8a3228198adb03e6996f7738c361a612777ecab6aaron * If we are doing normal logging, don't log messages that are
8a3228198adb03e6996f7738c361a612777ecab6aaron * above the server log level unless it is a startup/shutdown notice
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif /* TPF */
8a3228198adb03e6996f7738c361a612777ecab6aaron * If we are doing syslog logging, don't log messages that are
8a3228198adb03e6996f7738c361a612777ecab6aaron * above the server log level (including a startup/shutdown notice)
2b484455736f4c30447aa852764f53282cbeb5ddrbb if (logf && ((level & APLOG_STARTUP) != APLOG_STARTUP)) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm len += apr_snprintf(errstr + len, MAX_STRING_LEN - len,
0ef41d8e4b94d343e5b093c4dbd6ee61c1279401trawick#if defined(_OSD_POSIX) || defined(WIN32) || defined(__MVS__)
8a3228198adb03e6996f7738c361a612777ecab6aaron /* In OSD/POSIX, the compiler returns for __FILE__
8a3228198adb03e6996f7738c361a612777ecab6aaron * a string like: __FILE__="*POSIX(/usr/include/stdio.h)"
8a3228198adb03e6996f7738c361a612777ecab6aaron * (it even returns an absolute path for sources in
8a3228198adb03e6996f7738c361a612777ecab6aaron * the current directory). Here we try to strip this
8a3228198adb03e6996f7738c361a612777ecab6aaron * down to the basename.
8a3228198adb03e6996f7738c361a612777ecab6aaron if (*e == ')') {
50e421c0e069853bb724f3d816cef543e447c844jorton#else /* _OSD_POSIX || WIN32 */
50e421c0e069853bb724f3d816cef543e447c844jorton const char *p;
50e421c0e069853bb724f3d816cef543e447c844jorton /* On Unix, __FILE__ may be an absolute path in a
50e421c0e069853bb724f3d816cef543e447c844jorton * VPATH build. */
50e421c0e069853bb724f3d816cef543e447c844jorton if (file[0] == '/' && (p = ap_strrchr_c(file, '/')) != NULL) {
50e421c0e069853bb724f3d816cef543e447c844jorton#endif /*_OSD_POSIX || WIN32 */
8a3228198adb03e6996f7738c361a612777ecab6aaron len += apr_snprintf(errstr + len, MAX_STRING_LEN - len,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif /* TPF */
8a3228198adb03e6996f7738c361a612777ecab6aaron /* XXX: TODO: add a method of selecting whether logged client
8a3228198adb03e6996f7738c361a612777ecab6aaron * addresses are in dotted quad or resolved form... dotted
8a3228198adb03e6996f7738c361a612777ecab6aaron * quad is the most secure, which is why I'm implementing it
8a3228198adb03e6996f7738c361a612777ecab6aaron * first. -djg
8a3228198adb03e6996f7738c361a612777ecab6aaron len += apr_snprintf(errstr + len, MAX_STRING_LEN - len,
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe len += apr_snprintf(errstr + len, MAX_STRING_LEN - len,
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe len += apr_snprintf(errstr + len, MAX_STRING_LEN - len,
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe len += apr_snprintf(errstr + len, MAX_STRING_LEN - len,
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe len += apr_snprintf(errstr + len, MAX_STRING_LEN - len,
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe apr_strerror(status, errstr + len, MAX_STRING_LEN - len);
82acfa3f57607ae78326104c420a317260554a47nd if (apr_vsnprintf(scratch, MAX_STRING_LEN - len, fmt, args)) {
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd len += apr_vsnprintf(errstr + len, MAX_STRING_LEN - len, fmt, args);
82acfa3f57607ae78326104c420a317260554a47nd if ( r && (referer = apr_table_get(r->headers_in, "Referer"))
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd && ap_escape_errorlog_item(scratch, referer, MAX_STRING_LEN - len)
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd ", referer: %s",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* NULL if we are logging to syslog */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm /* Truncate for the terminator (as apr_snprintf does) */
3c09db9ce04e444548e386a4b822e76ea0dabbebrbb ap_run_error_log(file, line, level, status, s, r, pool, errstr + errstrlen);
3d96ee83babeec32482c9082c9426340cee8c44dwroweAP_DECLARE(void) ap_log_error(const char *file, int line, int level,
0942697a9b5de44865676345a3828741c827efe6rbb const char *fmt, ...)
e34223f72e630187c4d8ac7c22da5096c833eb20trawick log_error_core(file, line, level, status, s, NULL, NULL, NULL, fmt, args);
3d96ee83babeec32482c9082c9426340cee8c44dwroweAP_DECLARE(void) ap_log_perror(const char *file, int line, int level,
8a3228198adb03e6996f7738c361a612777ecab6aaron const char *fmt, ...)
e34223f72e630187c4d8ac7c22da5096c833eb20trawick log_error_core(file, line, level, status, NULL, NULL, NULL, p, fmt, args);
3d96ee83babeec32482c9082c9426340cee8c44dwroweAP_DECLARE(void) ap_log_rerror(const char *file, int line, int level,
0942697a9b5de44865676345a3828741c827efe6rbb const char *fmt, ...)
e34223f72e630187c4d8ac7c22da5096c833eb20trawick log_error_core(file, line, level, status, r->server, NULL, r, NULL, fmt,
2b13bc45632d72cdf50ac42149e4fc8bc0d05bf2stoddard * IF APLOG_TOCLIENT is set,
2b13bc45632d72cdf50ac42149e4fc8bc0d05bf2stoddard * AND the error level is 'warning' or more severe,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * AND there isn't already error text associated with this request,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * THEN make the message text available to ErrorDocument and
2b13bc45632d72cdf50ac42149e4fc8bc0d05bf2stoddard * other error processors.
8a3228198adb03e6996f7738c361a612777ecab6aaron && (apr_table_get(r->notes, "error-notes") == NULL)) {
e34223f72e630187c4d8ac7c22da5096c833eb20trawickAP_DECLARE(void) ap_log_cerror(const char *file, int line, int level,
e34223f72e630187c4d8ac7c22da5096c833eb20trawick const char *fmt, ...)
e34223f72e630187c4d8ac7c22da5096c833eb20trawick log_error_core(file, line, level, status, c->base_server, c, NULL, NULL,
32c4bc04f89b16521718145dc731f750144d7b38wroweAP_DECLARE(void) ap_log_pid(apr_pool_t *p, const char *filename)
32c4bc04f89b16521718145dc731f750144d7b38wrowe const char *fname;
e8f95a682820a599fe41b22977010636be5c2717jim ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, APR_EBADPATH,
32c4bc04f89b16521718145dc731f750144d7b38wrowe NULL, "Invalid PID file path %s, ignoring.", filename);
8a3228198adb03e6996f7738c361a612777ecab6aaron && apr_stat(&finfo, fname, APR_FINFO_MTIME, p) == APR_SUCCESS) {
8a3228198adb03e6996f7738c361a612777ecab6aaron /* AP_SIG_GRACEFUL and HUP call this on each restart.
8a3228198adb03e6996f7738c361a612777ecab6aaron * Only warn on first time through for this pid.
8a3228198adb03e6996f7738c361a612777ecab6aaron * XXX: Could just write first time through too, although
8a3228198adb03e6996f7738c361a612777ecab6aaron * that may screw up scripts written to do something
8a3228198adb03e6996f7738c361a612777ecab6aaron * based on the last modification time of the pid file.
4bb7ba7c1f9972b443562faf99151ccec854446fjorton "pid file %s overwritten -- Unclean "
4bb7ba7c1f9972b443562faf99151ccec854446fjorton "shutdown of previous Apache run?",
2b484455736f4c30447aa852764f53282cbeb5ddrbb "%s: could not log pid to file %s",
066877f1a045103acfdd376d48cdd473c33f409bdougm apr_file_printf(pid_file, "%ld" APR_EOL_STR, (long)mypid);
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawickAP_DECLARE(apr_status_t) ap_read_pid(apr_pool_t *p, const char *filename,
dc64949d88a97fef0bfcb2eed2115dddafc41666wrowe const apr_size_t BUFFER_SIZE = sizeof(long) * 3 + 2; /* see apr_ltoa */
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick const char *fname;
e8f95a682820a599fe41b22977010636be5c2717jim ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, APR_EBADPATH,
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick NULL, "Invalid PID file path %s, ignoring.", filename);
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick rv = apr_file_open(&pid_file, fname, APR_READ, APR_OS_DEFAULT, p);
2de7ee14d4925c754a2d3a52d91350b895257df9jerenkrantz rv = apr_file_read_full(pid_file, buf, BUFFER_SIZE - 1, &bytes_read);
2de7ee14d4925c754a2d3a52d91350b895257df9jerenkrantz /* If we fill the buffer, we're probably reading a corrupt pid file.
2de7ee14d4925c754a2d3a52d91350b895257df9jerenkrantz * To be nice, let's also ensure the first char is a digit. */
f2b43354f9ac8496ab7003ae01211af739efba1atrawick if (bytes_read == 0 || bytes_read == BUFFER_SIZE - 1 || !apr_isdigit(*buf)) {
8a3228198adb03e6996f7738c361a612777ecab6aaronAP_DECLARE(void) ap_log_assert(const char *szExp, const char *szFile,
2b484455736f4c30447aa852764f53282cbeb5ddrbb "[%s] file %s, line %d, assertion \"%s\" failed",
8f0d7adca1c0719b3b1863fb2b9d333d7822567awrowe#if defined(WIN32)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* unix assert does an abort leading to a core dump */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/* piped log support */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/* forward declaration */
10a4cdd68ef1ca0e54af296fe1d08ac00150c90bwrowestatic void piped_log_maintenance(int reason, void *data, apr_wait_t status);
f5308a6d396448120986bed14412954788af3e5cjorton/* Spawn the piped logger process pl->program. */
066877f1a045103acfdd376d48cdd473c33f409bdougm if (((status = apr_procattr_create(&procattr, pl->p)) != APR_SUCCESS) ||
76185d819b745e953dd2cd636fbdd515c333e4a4trawick ((status = apr_procattr_child_errfn_set(procattr, log_child_errfn))
76185d819b745e953dd2cd636fbdd515c333e4a4trawick ((status = apr_procattr_error_check_set(procattr, 1)) != APR_SUCCESS)) {
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb /* Something bad happened, give up and go away. */
8a3228198adb03e6996f7738c361a612777ecab6aaron "piped_log_spawn: unable to setup child process '%s': %s",
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb const char *pname;
76185d819b745e953dd2cd636fbdd515c333e4a4trawick status = apr_proc_create(procnew, pname, (const char * const *) args,
38cf7a307a8067b5b476403b9fec0bc6d7849cd2jorton /* procnew->in was dup2'd from ap_piped_log_write_fd(pl);
38cf7a307a8067b5b476403b9fec0bc6d7849cd2jorton * since the original fd is still valid, close the copy to
38cf7a307a8067b5b476403b9fec0bc6d7849cd2jorton * avoid a leak. */
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh apr_proc_other_child_register(procnew, piped_log_maintenance, pl,
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick close_handle_in_child(pl->p, ap_piped_log_read_fd(pl));
76185d819b745e953dd2cd636fbdd515c333e4a4trawick /* Something bad happened, give up and go away. */
76185d819b745e953dd2cd636fbdd515c333e4a4trawick "unable to start piped log program '%s': %s",
76185d819b745e953dd2cd636fbdd515c333e4a4trawick pl->program, apr_strerror(status, buf, sizeof(buf)));
10a4cdd68ef1ca0e54af296fe1d08ac00150c90bwrowestatic void piped_log_maintenance(int reason, void *data, apr_wait_t status)
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick pl->pid = NULL; /* in case we don't get it going again, this
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick * tells other logic not to try to kill it
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick stats = ap_mpm_query(AP_MPMQ_MPM_STATE, &mpm_state);
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick "can't query MPM state; not restarting "
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick "piped log program '%s'",
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick "piped log program '%s' failed unexpectedly",
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick /* what can we do? This could be the error log we're having
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick * problems opening up... */
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick "piped_log_maintenance: unable to respawn '%s': %s",
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick pl->program, apr_strerror(stats, buf, sizeof(buf)));
ffb048955d9939c0ab6ff99c2efc412d8e7a191dwrowe /* We should not kill off the pipe here, since it may only be full.
ffb048955d9939c0ab6ff99c2efc412d8e7a191dwrowe * If it really is locked, we should kill it off manually. */
c54189c4d2d06d8b374940b32acf20287effff07wrowestatic apr_status_t piped_log_cleanup_for_exec(void *data)
3d96ee83babeec32482c9082c9426340cee8c44dwroweAP_DECLARE(piped_log *) ap_open_piped_log(apr_pool_t *p, const char *program)
52bdaf788c70b03fe6f68a5a489cdbe11fb184efwrowe if (apr_file_pipe_create_ex(&ap_piped_log_read_fd(pl),
cddad5fd27fd3b9f4375d76d04bbbeaebec00548wrowe#else /* !AP_HAVE_RELIABLE_PIPED_LOGS */
3d96ee83babeec32482c9082c9426340cee8c44dwroweAP_DECLARE(piped_log *) ap_open_piped_log(apr_pool_t *p, const char *program)
f5fccb8eae1f1a5f212a5bda878479c281f36512trawick "Couldn't start piped log process");