From: Rob Landley Date: Fri, 18 Jul 2014 03:50:49 +0000 (-0500) Subject: Use libc daemon() instead of pending daemonize. X-Git-Tag: android-x86-6.0-r1~432 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=c880061f511e85d55afe3966f5eda0df7c3ebb56;p=android-x86%2Fexternal-toybox.git Use libc daemon() instead of pending daemonize. --- diff --git a/lib/pending.c b/lib/pending.c deleted file mode 100644 index 639c82f5..00000000 --- a/lib/pending.c +++ /dev/null @@ -1,22 +0,0 @@ -/* pending.c - reusable stuff awaiting review - * - * new lib entries for stuff in toys/pending - */ - -#include "toys.h" - -void daemonize(void) -{ - int fd = open("/dev/null", O_RDWR); - if (fd < 0) fd = xcreate("/", O_RDONLY, 0666); - - pid_t pid = fork(); - if (pid < 0) perror_exit("DAEMON: failed to fork"); - if (pid) exit(EXIT_SUCCESS); - - setsid(); - dup2(fd, 0); - dup2(fd, 1); - dup2(fd, 2); - if (fd > 2) close(fd); -} diff --git a/lib/pending.h b/lib/pending.h index c99a9f17..ec80c91f 100644 --- a/lib/pending.h +++ b/lib/pending.h @@ -7,6 +7,3 @@ void is_valid_username(const char *name); int read_password(char * buff, int buflen, char* mesg); int update_password(char *filename, char* username, char* encrypted); - -// cut helper functions -void daemonize(void); diff --git a/toys/pending/dhcpd.c b/toys/pending/dhcpd.c index 2919cb52..7da51949 100644 --- a/toys/pending/dhcpd.c +++ b/toys/pending/dhcpd.c @@ -1086,7 +1086,7 @@ void dhcpd_main(void) infomode = LOG_CONSOLE; if (!(flag_chk(FLAG_f))) { - daemonize(); + daemon(0,0); infomode = LOG_SILENT; } if (flag_chk(FLAG_S)) { diff --git a/toys/pending/klogd.c b/toys/pending/klogd.c index 54abedff..2c842889 100644 --- a/toys/pending/klogd.c +++ b/toys/pending/klogd.c @@ -68,7 +68,7 @@ void klogd_main(void) sigatexit(handle_signal); if (toys.optflags & FLAG_c) set_log_level(TT.level); //set log level - if (!(toys.optflags & FLAG_n)) daemonize(); //Make it daemon + if (!(toys.optflags & FLAG_n)) daemon(0, 0); //Make it daemon if (CFG_KLOGD_SOURCE_RING_BUFFER) { syslog(LOG_NOTICE, "KLOGD: started with Kernel ring buffer as log source\n"); diff --git a/toys/pending/syslogd.c b/toys/pending/syslogd.c index db2e52ee..7fb297f8 100644 --- a/toys/pending/syslogd.c +++ b/toys/pending/syslogd.c @@ -470,7 +470,7 @@ init_jumpin: if (parse_config_file() == -1) goto clean_and_exit; open_logfiles(); if (!(toys.optflags & FLAG_n)) { - daemonize(); + daemon(0, 0); //don't daemonize again if SIGHUP received. toys.optflags |= FLAG_n; } diff --git a/toys/pending/telnetd.c b/toys/pending/telnetd.c index 3c0f8e39..4198e63f 100644 --- a/toys/pending/telnetd.c +++ b/toys/pending/telnetd.c @@ -317,7 +317,7 @@ void telnetd_main(void) master_fd = listen_socket(); fcntl(master_fd, F_SETFD, FD_CLOEXEC); if (master_fd > TT.gmax_fd) TT.gmax_fd = master_fd; - if (!(toys.optflags & FLAG_F)) daemonize(); + if (!(toys.optflags & FLAG_F)) daemon(0, 0); } else { pty_fd = new_session(master_fd); //master_fd = 0 if (pty_fd > TT.gmax_fd) TT.gmax_fd = pty_fd;