]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
* log: Provide "||program" syntax to optionally restore behavior broken in
authorJim Jagielski <jim@apache.org>
Thu, 21 May 2009 17:31:52 +0000 (17:31 +0000)
committerJim Jagielski <jim@apache.org>
Thu, 21 May 2009 17:31:52 +0000 (17:31 +0000)
      2.0.50 which leads to bad process handling on Solaris and wasted process
           resources on all platforms.
              Trunk version (new behavior);
                     http://svn.apache.org/viewvc?view=rev&revision=775300
                            http://svn.apache.org/viewvc?view=rev&revision=775320
                               Proposed 2.2.12 patch, retaining default behavior from 2.2.11;
                                      http://people.apache.org/~wrowe/fixlog22.patch

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.2.x@777193 13f79535-47bb-0310-9956-ffa450edef68

include/ap_mmn.h
include/http_log.h
server/log.c

index e5e5be55c9412b75f0e5dc53609c562f188558d7..893f5bc32293b6003bbd9d562546940e00b4f26b 100644 (file)
  * 20051115.20 (2.2.11) Add ap_proxy_buckets_lifetime_transform to mod_proxy.h
  * 20051115.21 (2.2.11) Export mod_rewrite.h in the public API
  * 20051115.22 (2.2.12) Add ap_escape_html2 API, with additional option
+ * 20051115.23 (2.2.12) Add ap_open_piped_log_ex API, with cmdtype option,
+ *                      and conditional cmdtype member of piped_log struct
  */
 
 #define MODULE_MAGIC_COOKIE 0x41503232UL /* "AP22" */
 #ifndef MODULE_MAGIC_NUMBER_MAJOR
 #define MODULE_MAGIC_NUMBER_MAJOR 20051115
 #endif
-#define MODULE_MAGIC_NUMBER_MINOR 21                    /* 0...n */
+#define MODULE_MAGIC_NUMBER_MINOR 23                    /* 0...n */
 
 /**
  * Determine if the server's current MODULE_MAGIC_NUMBER is at least a
index 9a09b7d3105960f95ecae958f0f0898a091e864a..e0c0c29014acc21bcae503c8a3b167418044d13a 100644 (file)
@@ -289,6 +289,8 @@ struct piped_log {
     char *program;
     /** The pid of the logging process */
     apr_proc_t *pid;
+    /** How to reinvoke program when it must be replaced */
+    apr_cmdtype_e cmdtype;
 #endif
 };
 
@@ -297,9 +299,22 @@ struct piped_log {
  * @param p The pool to allocate out of
  * @param program The program to run in the logging process
  * @return The piped log structure
+ * @tip The log program is invoked as APR_SHELLCMD_ENV, 
+ *      @see ap_open_piped_log_ex to modify this behavior
  */
 AP_DECLARE(piped_log *) ap_open_piped_log(apr_pool_t *p, const char *program);
 
+/**
+ * Open the piped log process specifying the execution choice for program
+ * @param p The pool to allocate out of
+ * @param program The program to run in the logging process
+ * @param cmdtype How to invoke program, e.g. APR_PROGRAM, APR_SHELLCMD_ENV, etc
+ * @return The piped log structure
+ */
+AP_DECLARE(piped_log *) ap_open_piped_log_ex(apr_pool_t *p,
+                                             const char *program,
+                                             apr_cmdtype_e cmdtype);
+
 /**
  * Close the piped log and kill the logging process
  * @param pl The piped log structure
index 3aa20b0b49b9ea1f169096ea8bd3d53cec7f93ac..42a77290c85f5e6bffc4ece4170cf8b6d272dbf1 100644 (file)
@@ -265,7 +265,8 @@ static void log_child_errfn(apr_pool_t *pool, apr_status_t err,
  * stderr for the child will be the same as the stdout of the parent.
  * Otherwise the child will inherit the stderr from the parent. */
 static int log_child(apr_pool_t *p, const char *progname,
-                     apr_file_t **fpin, int dummy_stderr)
+                     apr_file_t **fpin, apr_cmdtype_e cmdtype,
+                     int dummy_stderr)
 {
     /* Child process code for 'ErrorLog "|..."';
      * may want a common framework for this, since I expect it will
@@ -277,8 +278,7 @@ static int log_child(apr_pool_t *p, const char *progname,
     apr_file_t *outfile, *errfile;
 
     if (((rc = apr_procattr_create(&procattr, p)) == APR_SUCCESS)
-        && ((rc = apr_procattr_cmdtype_set(procattr,
-                                           APR_SHELLCMD_ENV)) == APR_SUCCESS)
+        && ((rc = apr_procattr_cmdtype_set(procattr, cmdtype)) == APR_SUCCESS)
         && ((rc = apr_procattr_io_set(procattr,
                                       APR_FULL_BLOCK,
                                       APR_NO_PIPE,
@@ -325,12 +325,26 @@ static int open_error_log(server_rec *s, int is_main, apr_pool_t *p)
 
     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, s->error_fname + 1, &dummy, is_main);
+        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");
@@ -883,12 +897,12 @@ static apr_status_t piped_log_spawn(piped_log *pl)
     apr_status_t status;
 
     if (((status = apr_procattr_create(&procattr, pl->p)) != APR_SUCCESS) ||
-        ((status = apr_procattr_cmdtype_set(procattr,
-                                            APR_SHELLCMD_ENV)) != APR_SUCCESS) ||
+        ((status = apr_procattr_cmdtype_set(procattr, pl->cmdtype))
+         != APR_SUCCESS) ||
         ((status = apr_procattr_child_in_set(procattr,
                                              ap_piped_log_read_fd(pl),
                                              ap_piped_log_write_fd(pl)))
-        != APR_SUCCESS) ||
+         != APR_SUCCESS) ||
         ((status = apr_procattr_child_errfn_set(procattr, log_child_errfn))
          != APR_SUCCESS) ||
         ((status = apr_procattr_error_check_set(procattr, 1)) != APR_SUCCESS)) {
@@ -1012,7 +1026,9 @@ static apr_status_t piped_log_cleanup(void *data)
 }
 
 
-AP_DECLARE(piped_log *) ap_open_piped_log(apr_pool_t *p, const char *program)
+AP_DECLARE(piped_log *) ap_open_piped_log_ex(apr_pool_t *p,
+                                             const char *program,
+                                             apr_cmdtype_e cmdtype)
 {
     piped_log *pl;
 
@@ -1020,6 +1036,7 @@ AP_DECLARE(piped_log *) ap_open_piped_log(apr_pool_t *p, const char *program)
     pl->p = p;
     pl->program = apr_pstrdup(p, program);
     pl->pid = NULL;
+    pl->cmdtype = cmdtype;
     if (apr_file_pipe_create(&ap_piped_log_read_fd(pl),
                              &ap_piped_log_write_fd(pl), p) != APR_SUCCESS) {
         return NULL;
@@ -1045,13 +1062,15 @@ static apr_status_t piped_log_cleanup(void *data)
     return APR_SUCCESS;
 }
 
-AP_DECLARE(piped_log *) ap_open_piped_log(apr_pool_t *p, const char *program)
+AP_DECLARE(piped_log *) ap_open_piped_log_ex(apr_pool_t *p,
+                                             const char *program,
+                                             apr_cmdtype_e cmdtype)
 {
     piped_log *pl;
     apr_file_t *dummy = NULL;
     int rc;
 
-    rc = log_child(p, program, &dummy, 0);
+    rc = log_child(p, program, &dummy, cmdtype, 0);
     if (rc != APR_SUCCESS) {
         ap_log_error(APLOG_MARK, APLOG_STARTUP, rc, NULL,
                      "Couldn't start piped log process");
@@ -1069,6 +1088,26 @@ AP_DECLARE(piped_log *) ap_open_piped_log(apr_pool_t *p, const char *program)
 
 #endif
 
+AP_DECLARE(piped_log *) ap_open_piped_log(apr_pool_t *p,
+                                          const char *program)
+{
+    apr_cmdtype_e cmdtype = APR_SHELLCMD_ENV;
+
+    /* 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 (*program == '|') {
+        cmdtype = APR_PROGRAM_ENV;
+        ++program;
+    }
+    if (*program == '$')
+        ++program;
+
+    return ap_open_piped_log_ex(p, program, cmdtype);
+}
+
 AP_DECLARE(void) ap_close_piped_log(piped_log *pl)
 {
     apr_pool_cleanup_run(pl->p, pl, piped_log_cleanup);