aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2012-08-14 23:16:46 +0200
committerMax Kellermann <max@duempel.org>2012-08-14 23:16:46 +0200
commitdc22846d58264bfae3b4516e2de1614b3b97a5ca (patch)
tree99c836bbbf044e119792d2168c9729e7e35c4a44
parentc9aaabb5d4467047514d291ff652d516a7025486 (diff)
downloadmpd-dc22846d58264bfae3b4516e2de1614b3b97a5ca.tar.gz
mpd-dc22846d58264bfae3b4516e2de1614b3b97a5ca.tar.xz
mpd-dc22846d58264bfae3b4516e2de1614b3b97a5ca.zip
log: store duplicated path string
Don't free the string right after calling log_init_file(). Add a new function log_deinit() that frees the string on shutdown. This fixes cycling the log file after SIGHUP (Mantis ticket 0003524).
-rw-r--r--src/log.c56
-rw-r--r--src/log.h5
-rw-r--r--src/main.c2
3 files changed, 32 insertions, 31 deletions
diff --git a/src/log.c b/src/log.c
index 86dd86eaa..2d3c7cafd 100644
--- a/src/log.c
+++ b/src/log.c
@@ -55,7 +55,7 @@ static const char *log_charset;
static bool stdout_mode = true;
static int out_fd;
-static const char *out_filename;
+static char *out_filename;
static void redirect_logs(int fd)
{
@@ -134,14 +134,15 @@ open_log_file(void)
}
static bool
-log_init_file(const char *path, unsigned line, GError **error_r)
+log_init_file(unsigned line, GError **error_r)
{
- out_filename = path;
+ assert(out_filename != NULL);
+
out_fd = open_log_file();
if (out_fd < 0) {
g_set_error(error_r, log_quark(), errno,
"failed to open log file \"%s\" (config line %u): %s",
- path, line, g_strerror(errno));
+ out_filename, line, g_strerror(errno));
return false;
}
@@ -271,22 +272,33 @@ log_init(bool verbose, bool use_stdout, GError **error_r)
return true;
#endif
} else {
- GError *error = NULL;
- char *path = config_dup_path(CONF_LOG_FILE, &error);
- if (path == NULL) {
- assert(error != NULL);
- g_propagate_error(error_r, error);
- return false;
- }
-
- bool success = log_init_file(path, param->line,
- error_r);
- g_free(path);
- return success;
+ out_filename = config_dup_path(CONF_LOG_FILE, error_r);
+ return out_filename != NULL &&
+ log_init_file(param->line, error_r);
}
}
}
+static void
+close_log_files(void)
+{
+ if (stdout_mode)
+ return;
+
+#ifdef HAVE_SYSLOG
+ if (out_filename == NULL)
+ closelog();
+#endif
+}
+
+void
+log_deinit(void)
+{
+ close_log_files();
+ g_free(out_filename);
+}
+
+
void setup_log_output(bool use_stdout)
{
fflush(NULL);
@@ -327,15 +339,3 @@ int cycle_log_files(void)
g_debug("Done cycling log files\n");
return 0;
}
-
-void close_log_files(void)
-{
- if (stdout_mode)
- return;
-
-#ifdef HAVE_SYSLOG
- if (out_filename == NULL)
- closelog();
-#endif
-}
-
diff --git a/src/log.h b/src/log.h
index 75e386b25..683ff3e9f 100644
--- a/src/log.h
+++ b/src/log.h
@@ -44,10 +44,11 @@ log_early_init(bool verbose);
bool
log_init(bool verbose, bool use_stdout, GError **error_r);
+void
+log_deinit(void);
+
void setup_log_output(bool use_stdout);
int cycle_log_files(void);
-void close_log_files(void);
-
#endif /* LOG_H */
diff --git a/src/main.c b/src/main.c
index 44e4dcf1c..12f8d86f6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -536,6 +536,6 @@ int mpd_main(int argc, char *argv[])
WSACleanup();
#endif
- close_log_files();
+ log_deinit();
return EXIT_SUCCESS;
}