summaryrefslogtreecommitdiff
path: root/support/suexec.c
diff options
context:
space:
mode:
authorStefan Fritsch <sf@apache.org>2009-10-03 13:46:48 +0000
committerStefan Fritsch <sf@apache.org>2009-10-03 13:46:48 +0000
commit9adcc73504363d0ad26a006a48e37169f79b9b3c (patch)
tree709811e1f10d2e4c34b5339dc05a56a2c324bcd3 /support/suexec.c
parentabcfac33f8d3f7690425f6426bb1fb1af9fe6419 (diff)
downloadhttpd-9adcc73504363d0ad26a006a48e37169f79b9b3c.tar.gz
suexec: Allow to log an error if exec fails by setting FD_CLOEXEC
on the log file instead of closing it. PR: 10744 Submitted by: Nicolas Rachinsky Reviewed by: Stefan Fritsch git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@821321 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'support/suexec.c')
-rw-r--r--support/suexec.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/support/suexec.c b/support/suexec.c
index a6a82b5ec2..1ef4e0928f 100644
--- a/support/suexec.c
+++ b/support/suexec.c
@@ -46,6 +46,7 @@
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
+#include <fcntl.h>
#ifdef HAVE_PWD_H
#include <pwd.h>
@@ -575,17 +576,16 @@ int main(int argc, char *argv[])
#endif /* AP_SUEXEC_UMASK */
/*
- * Be sure to close the log file so the CGI can't
- * mess with it. If the exec fails, it will be reopened
- * automatically when log_err is called. Note that the log
- * might not actually be open if AP_LOG_EXEC isn't defined.
- * However, the "log" cell isn't ifdef'd so let's be defensive
- * and assume someone might have done something with it
- * outside an ifdef'd AP_LOG_EXEC block.
+ * ask fcntl(2) to set the FD_CLOEXEC flag on the log file,
+ * so it'll be automagically closed if the exec() call succeeds.
*/
if (log != NULL) {
- fclose(log);
- log = NULL;
+ fflush(log);
+ setbuf(log,NULL);
+ if ((fcntl(fileno(log), F_SETFD, FD_CLOEXEC) == -1)) {
+ log_err("error: can't set close-on-exec flag");
+ exit(122);
+ }
}
/*