From 995b3f071aa0e7df03be1a086b9b4942fcf0f409 Mon Sep 17 00:00:00 2001 From: Arnaud Cornet Date: Mon, 3 Sep 2007 12:01:13 +0200 Subject: [PATCH] Re-open main logfile to allow rotate. Trivial fix. --- src/bip.c | 30 ++++++++++++++++++++---------- src/irc.c | 4 ++-- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/bip.c b/src/bip.c index c5cbc40..dfef0f2 100644 --- a/src/bip.c +++ b/src/bip.c @@ -178,16 +178,6 @@ static pid_t daemonize(void) _exit(0); } - if (conf_log_system) { - snprintf(buf, 4095, "%s/bip.log", conf_log_root); - FILE *f = fopen(buf, "a"); - if (!f) - fatal("Can't open %s: %s", buf, strerror(errno)); - conf_global_log_file = f; - } else { - conf_global_log_file = stderr; - } - close(0); close(1); close(2); @@ -861,6 +851,21 @@ void ircize(bip_t *bip) } #endif +static void log_file_setup(void) +{ + if (conf_log_system) { + if (conf_global_log_file && conf_global_log_file != stderr) + fclose(conf_log_system); + snprintf(buf, 4095, "%s/bip.log", conf_log_root); + FILE *f = fopen(buf, "a"); + if (!f) + fatal("Can't open %s: %s", buf, strerror(errno)); + conf_global_log_file = f; + } else { + conf_global_log_file = stderr; + } +} + int main(int argc, char **argv) { FILE *conf = NULL; @@ -942,6 +947,8 @@ int main(int argc, char **argv) check_dir(conf_log_root, 1); fd = do_pid_stuff(); pid_t pid = 0; + + log_file_setup(); if (conf_daemonize) pid = daemonize(); else @@ -967,6 +974,9 @@ int main(int argc, char **argv) fatal("%s config file not found", confpath); fireup(&bip, conf); fclose(conf); + + /* re-open to allow logfile rotate */ + log_file_setup(); } return 1; } diff --git a/src/irc.c b/src/irc.c index ddb1e83..6bd3581 100644 --- a/src/irc.c +++ b/src/irc.c @@ -216,7 +216,7 @@ static void irc_server_connected(struct link_server *server) LINK(server)->s_state = IRCS_CONNECTED; LINK(server)->s_conn_attempt = 0; - mylog(LOG_INFO, "Connected user %s to %s", LINK(server)->username, + mylog(LOG_INFO, "Connected user %s to %s", LINK(server)->user->name, LINK(server)->name); irc_server_join(server); @@ -694,7 +694,7 @@ static int irc_cli_startup(bip_t *bip, struct link_client *ic, for (list_it_init(&bip->link_list, &it); list_it_item(&it); list_it_next(&it)) { struct link *l = list_it_item(&it); - if (strcmp(user, l->username) == 0 && + if (strcmp(user, l->user->name) == 0 && strcmp(connname, l->name) == 0) { if (chash_cmp(pass, l->user->password, l->user->seed) == 0) {