aboutsummaryrefslogtreecommitdiff
path: root/src/log.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-12-28 19:48:52 +0100
committerMax Kellermann <max@duempel.org>2008-12-28 19:48:52 +0100
commit8e9def1b5a042b881a2d5fa8f29827c44d0373e7 (patch)
treeb7ad02514e7472331eee57872468ab932ccfb43e /src/log.c
parent8dc92ad28420a2babb3731624c137ad4ef1540c2 (diff)
log: moved code to open_log_file()
Merged code from open_log_files() and cycle_log_files().
Diffstat (limited to 'src/log.c')
-rw-r--r--src/log.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/src/log.c b/src/log.c
index 8fa056cb..fe7744d5 100644
--- a/src/log.c
+++ b/src/log.c
@@ -93,6 +93,22 @@ mpd_log_func(const gchar *log_domain,
g_free(converted);
}
+static int
+open_log_file(void)
+{
+ mode_t prev;
+ int fd;
+
+ assert(out_filename != NULL);
+
+ prev = umask(0066);
+ fd = open(out_filename, O_CREAT | O_WRONLY | O_APPEND, 0666);
+
+ umask(prev);
+
+ return fd;
+}
+
void initLog(bool verbose)
{
ConfigParam *param;
@@ -121,21 +137,18 @@ void initLog(bool verbose)
void open_log_files(bool use_stdout)
{
- mode_t prev;
ConfigParam *param;
if (use_stdout)
return;
- prev = umask(0066);
param = parseConfigFilePath(CONF_LOG_FILE, 1);
out_filename = param->value;
- out_fd = open(out_filename, O_CREAT | O_WRONLY | O_APPEND, 0666);
+
+ out_fd = open_log_file();
if (out_fd < 0)
FATAL("problem opening log file \"%s\" (config line %i) for "
"writing\n", param->value, param->line);
-
- umask(prev);
}
void setup_log_output(bool use_stdout)
@@ -178,8 +191,6 @@ G_GNUC_PRINTF(1, 2) G_GNUC_NORETURN void FATAL(const char *fmt, ...)
int cycle_log_files(void)
{
- mode_t prev;
-
if (stdout_mode)
return 0;
assert(out_filename);
@@ -187,16 +198,12 @@ int cycle_log_files(void)
DEBUG("Cycling log files...\n");
close_log_files();
- prev = umask(0066);
-
- out_fd = open(out_filename, O_CREAT | O_WRONLY | O_APPEND, 0666);
+ out_fd = open_log_file();
if (out_fd < 0) {
ERROR("error re-opening log file: %s\n", out_filename);
return -1;
}
- umask(prev);
-
redirect_logs();
DEBUG("Done cycling log files\n");
return 0;