From 27f032f4765e120b79ea6ced513ac7d32e470815 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Tue, 29 Jun 2010 11:22:24 +0000 Subject: logfile support Add support for logfile via -l option. --- sircbot.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'sircbot.c') diff --git a/sircbot.c b/sircbot.c index 9c072d6..6c63e49 100644 --- a/sircbot.c +++ b/sircbot.c @@ -65,7 +65,7 @@ static int write_pid(const char *file) return n; } -int daemonize(const char *pidfile) +int daemonize(const char *pidfile, const char *logfile) { int devnull, f; int pid = fork(); @@ -93,8 +93,8 @@ int daemonize(const char *pidfile) return -1; /* redirect stdin/stdout/stderr to /dev/null */ freopen("/dev/null", "r", stdin); - freopen("/dev/null", "w", stdout); - freopen("/dev/null", "w", stderr); + freopen(logfile, "w", stdout); + freopen(logfile, "w", stderr); return 0; } @@ -410,14 +410,18 @@ int main(int argc, char *argv[]) const char *user = "sircbot"; const char *group = "sircbot"; const char *pass = NULL; + const char *logfile = "/dev/null"; struct sircbot_channel *chan; int i, c, port = 6667; - while ((c = getopt(argc, argv, "fn:p:P:r:s:")) != -1) { + while ((c = getopt(argc, argv, "fl:n:p:P:r:s:")) != -1) { switch (c) { case 'f': foreground = 1; break; + case 'l': + logfile = optarg; + break; case 'n': nick = optarg; break; @@ -458,7 +462,7 @@ int main(int argc, char *argv[]) /* daemonize */ if (!foreground) { - if (daemonize(pidfile) < 0) + if (daemonize(pidfile, logfile) < 0) return 1; } signal(SIGTERM, sighandler); -- cgit v1.2.3