httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jim Jagielski <...@jaguNET.com>
Subject [PATCH] Have logfiles closed on exec
Date Wed, 11 Dec 2002 14:25:19 GMT
This patch uses the recently folded in "magic" cleanups to
have all log files (well, access and transfer logs) set with
CLOSEXEC. It also adds another *_ex function (ap_popenf_ex)
and allows for the magic cleanups to be called/run whenever
by passing a NULL pool (also protects against dumps when
a NULL might be passed by accident).

Comments??


Index: src/include/ap_alloc.h
===================================================================
RCS file: /home/cvs/apache-1.3/src/include/ap_alloc.h,v
retrieving revision 1.80
diff -u -r1.80 ap_alloc.h
--- src/include/ap_alloc.h	8 Dec 2002 19:09:55 -0000	1.80
+++ src/include/ap_alloc.h	11 Dec 2002 14:22:04 -0000
@@ -337,6 +337,8 @@
 API_EXPORT(FILE *) ap_pfopen(struct pool *, const char *name, const char *fmode);
 API_EXPORT(FILE *) ap_pfdopen(struct pool *, int fd, const char *fmode);
 API_EXPORT(int) ap_popenf(struct pool *, const char *name, int flg, int mode);
+API_EXPORT(int) ap_popenf_ex(struct pool *, const char *name, int flg,
+                             int mode, int domagic);
 
 API_EXPORT(void) ap_note_cleanups_for_file(pool *, FILE *);
 API_EXPORT(void) ap_note_cleanups_for_file_ex(pool *, FILE *, int);
Index: src/main/alloc.c
===================================================================
RCS file: /home/cvs/apache-1.3/src/main/alloc.c,v
retrieving revision 1.134
diff -u -r1.134 alloc.c
--- src/main/alloc.c	11 Dec 2002 12:24:27 -0000	1.134
+++ src/main/alloc.c	11 Dec 2002 14:22:05 -0000
@@ -1687,12 +1687,17 @@
 				      void (*child_cleanup) (void *),
 				      int (*magic_cleanup) (void *))
 {
-    struct cleanup *c = (struct cleanup *) ap_palloc(p, sizeof(struct cleanup));
-    c->data = data;
-    c->plain_cleanup = plain_cleanup;
-    c->child_cleanup = child_cleanup;
-    c->next = p->cleanups;
-    p->cleanups = c;
+    struct cleanup *c;
+    if (p) {
+	c = (struct cleanup *) ap_palloc(p, sizeof(struct cleanup));
+	c->data = data;
+	c->plain_cleanup = plain_cleanup;
+	c->child_cleanup = child_cleanup;
+	c->next = p->cleanups;
+	p->cleanups = c;
+    }
+    /* attempt to do magic even if not passed a pool. Allows us
+     * to perform the magic, therefore, "whenever" we want/need */
     if(magic_cleanup) {
 	if(!magic_cleanup(data)) 
 	   ap_log_error(APLOG_MARK, APLOG_WARNING, NULL,
@@ -1827,7 +1832,8 @@
     ap_kill_cleanup(p, (void *) (long) fd, fd_cleanup);
 }
 
-API_EXPORT(int) ap_popenf(pool *a, const char *name, int flg, int mode)
+API_EXPORT(int) ap_popenf_ex(pool *a, const char *name, int flg, int mode,
+                             int domagic)
 {
     int fd;
     int save_errno;
@@ -1837,11 +1843,16 @@
     save_errno = errno;
     if (fd >= 0) {
 	fd = ap_slack(fd, AP_SLACK_HIGH);
-	ap_note_cleanups_for_fd(a, fd);
+	ap_note_cleanups_for_fd_ex(a, fd, domagic);
     }
     ap_unblock_alarms();
     errno = save_errno;
     return fd;
+}
+
+API_EXPORT(int) ap_popenf(pool *a, const char *name, int flg, int mode)
+{
+    return ap_popenf_ex(a, name, flg, mode, 0);
 }
 
 API_EXPORT(int) ap_pclosef(pool *a, int fd)
Index: src/modules/standard/mod_log_agent.c
===================================================================
RCS file: /home/cvs/apache-1.3/src/modules/standard/mod_log_agent.c,v
retrieving revision 1.36
diff -u -r1.36 mod_log_agent.c
--- src/modules/standard/mod_log_agent.c	13 Mar 2002 21:05:33 -0000	1.36
+++ src/modules/standard/mod_log_agent.c	11 Dec 2002 14:22:06 -0000
@@ -125,7 +125,8 @@
         cls->agent_fd = ap_piped_log_write_fd(pl);
     }
     else if (*cls->fname != '\0') {
-        if ((cls->agent_fd = ap_popenf(p, fname, xfer_flags, xfer_mode)) < 0) {
+        if ((cls->agent_fd = ap_popenf_ex(p, fname, xfer_flags, xfer_mode, 1))
+             < 0) {
             ap_log_error(APLOG_MARK, APLOG_ERR, s,
                          "could not open agent log file %s.", fname);
             exit(1);
Index: src/modules/standard/mod_log_config.c
===================================================================
RCS file: /home/cvs/apache-1.3/src/modules/standard/mod_log_config.c,v
retrieving revision 1.88
diff -u -r1.88 mod_log_config.c
--- src/modules/standard/mod_log_config.c	21 May 2002 13:03:56 -0000	1.88
+++ src/modules/standard/mod_log_config.c	11 Dec 2002 14:22:07 -0000
@@ -1069,7 +1069,8 @@
     }
     else {
         char *fname = ap_server_root_relative(p, cls->fname);
-        if ((cls->log_fd = ap_popenf(p, fname, xfer_flags, xfer_mode)) < 0) {
+        if ((cls->log_fd = ap_popenf_ex(p, fname, xfer_flags, xfer_mode, 1))
+             < 0) {
             ap_log_error(APLOG_MARK, APLOG_ERR, s,
                          "could not open transfer log file %s.", fname);
             exit(1);
Index: src/modules/standard/mod_log_referer.c
===================================================================
RCS file: /home/cvs/apache-1.3/src/modules/standard/mod_log_referer.c,v
retrieving revision 1.39
diff -u -r1.39 mod_log_referer.c
--- src/modules/standard/mod_log_referer.c	13 Mar 2002 21:05:33 -0000	1.39
+++ src/modules/standard/mod_log_referer.c	11 Dec 2002 14:22:07 -0000
@@ -142,7 +142,8 @@
         cls->referer_fd = ap_piped_log_write_fd(pl);
     }
     else if (*cls->fname != '\0') {
-        if ((cls->referer_fd = ap_popenf(p, fname, xfer_flags, xfer_mode)) < 0) {
+        if ((cls->referer_fd = ap_popenf_ex(p, fname, xfer_flags, xfer_mode, 1))
+             < 0) {
 	    ap_log_error(APLOG_MARK, APLOG_ERR, s,
 			 "could not open referer log file %s.", fname);        
 	    exit(1);
-- 
===========================================================================
   Jim Jagielski   [|]   jim@jaguNET.com   [|]   http://www.jaguNET.com/
      "A society that will trade a little liberty for a little order
             will lose both and deserve neither" - T.Jefferson

Mime
View raw message