Mercurial > hg > toybox
diff toys/pending/klogd.c @ 995:893c86bbe452
Add daemonize function to lib for klogd and syslogd
author | Felix Janda <felix.janda@posteo.de> |
---|---|
date | Sat, 10 Aug 2013 20:18:18 +0200 |
parents | 00c7b6f4104a |
children | 8b1814e4c987 |
line wrap: on
line diff
--- a/toys/pending/klogd.c Sat Aug 10 19:35:11 2013 +0200 +++ b/toys/pending/klogd.c Sat Aug 10 20:18:18 2013 +0200 @@ -67,19 +67,7 @@ sigatexit(handle_signal); if (toys.optflags & FLAG_c) set_log_level(TT.level); //set log level - if (!(toys.optflags & FLAG_n)) { //Make it daemon - pid_t pid; - int fd = open("/dev/null", O_RDWR); - if (fd < 0) fd = open("/", O_RDONLY, 0666); - if((pid = fork()) < 0) perror_exit("DAEMON: fail to fork"); - if (pid) exit(EXIT_SUCCESS); - - setsid(); - dup2(fd, 0); - dup2(fd, 1); - dup2(fd, 2); - if (fd > 2) close(fd); - } + if (!(toys.optflags & FLAG_n)) daemonize(); //Make it daemon if (CFG_KLOGD_SOURCE_RING_BUFFER) { syslog(LOG_NOTICE, "KLOGD: started with Kernel ring buffer as log source\n");