summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2017-07-16 15:30:07 -0400
committerGlenn Strauss <gstrauss@gluelogic.com>2017-07-23 19:02:31 -0400
commitad7d6a6b1555f3ada1de3088c428b75ad4be6cb3 (patch)
tree9062a5230652ac107f11aea9f6558f34ce3a5fe8
parentd742e438341bd638d7ab782b2cce0471445bfd22 (diff)
downloadlighttpd1.4-ad7d6a6b1555f3ada1de3088c428b75ad4be6cb3.tar.gz
lighttpd1.4-ad7d6a6b1555f3ada1de3088c428b75ad4be6cb3.zip
[core] fdevent_cycle_logger()
fdevent_cycle_logger() re-opens log files before closing existing fd
-rw-r--r--src/fdevent.c10
-rw-r--r--src/fdevent.h1
-rw-r--r--src/mod_accesslog.c7
-rw-r--r--src/server.c21
4 files changed, 15 insertions, 24 deletions
diff --git a/src/fdevent.c b/src/fdevent.c
index d9c24335..b73a08b3 100644
--- a/src/fdevent.c
+++ b/src/fdevent.c
@@ -594,6 +594,16 @@ int fdevent_open_logger(const char *logger) {
}
}
+int fdevent_cycle_logger(const char *logger, int *curfd) {
+ if (logger[0] != '|') {
+ int fd = fdevent_open_logger(logger);
+ if (-1 == fd) return -1; /*(error; leave *curfd as-is)*/
+ if (-1 != *curfd) close(*curfd);
+ *curfd = fd;
+ }
+ return *curfd;
+}
+
#include <sys/ioctl.h>
#ifdef HAVE_SYS_FILIO_H
diff --git a/src/fdevent.h b/src/fdevent.h
index 2130fecc..bf9ba7c9 100644
--- a/src/fdevent.h
+++ b/src/fdevent.h
@@ -224,6 +224,7 @@ int fdevent_open_dirname(char *path);
int fdevent_set_stdin_stdout_stderr(int fdin, int fdout, int fderr);
pid_t fdevent_fork_execve(const char *name, char *argv[], char *envp[], int fdin, int fdout, int fderr, int dfd);
int fdevent_open_logger(const char *logger);
+int fdevent_cycle_logger(const char *logger, int *curfd);
int fdevent_select_init(fdevents *ev);
int fdevent_poll_init(fdevents *ev);
diff --git a/src/mod_accesslog.c b/src/mod_accesslog.c
index 482d1887..309579ed 100644
--- a/src/mod_accesslog.c
+++ b/src/mod_accesslog.c
@@ -666,13 +666,8 @@ SIGHUP_FUNC(log_access_cycle) {
&& !buffer_string_is_empty(s->access_logfile)
&& s->access_logfile->ptr[0] != '|') {
- if (-1 != s->log_access_fd) close(s->log_access_fd);
-
- if (-1 == (s->log_access_fd =
- fdevent_open_cloexec(s->access_logfile->ptr, O_APPEND | O_WRONLY | O_CREAT | O_LARGEFILE, 0644))) {
-
+ if (-1 == fdevent_cycle_logger(s->access_logfile->ptr, &s->log_access_fd)) {
log_error_write(srv, __FILE__, __LINE__, "ss", "cycling access-log failed:", strerror(errno));
-
return HANDLER_ERROR;
}
}
diff --git a/src/server.c b/src/server.c
index 2195d54c..a344357c 100644
--- a/src/server.c
+++ b/src/server.c
@@ -882,26 +882,11 @@ static int log_error_cycle(server *srv) {
if (srv->errorlog_mode == ERRORLOG_FILE) {
const char *logfile = srv->srvconf.errorlog_file->ptr;
- int new_fd;
-
- if (-1 == (new_fd = fdevent_open_logger(logfile))) {
+ if (-1 == fdevent_cycle_logger(logfile, &srv->errorlog_fd)) {
/* write to old log */
- log_error_write(srv, __FILE__, __LINE__, "SSSSS",
+ log_error_write(srv, __FILE__, __LINE__, "SSSS",
"cycling errorlog '", logfile,
- "' failed: ", strerror(errno),
- ", falling back to syslog()");
-
- close(srv->errorlog_fd);
- srv->errorlog_fd = -1;
- #ifdef HAVE_SYSLOG_H
- srv->errorlog_mode = ERRORLOG_SYSLOG;
- #endif
- }
- else {
- /* ok, new log is open, close the old one */
- close(srv->errorlog_fd);
- srv->errorlog_fd = new_fd;
- fdevent_setfd_cloexec(srv->errorlog_fd);
+ "' failed: ", strerror(errno));
}
}