changeset 1391:6a06541c090c draft

Use libc daemon() instead of pending daemonize.
author Rob Landley <rob@landley.net>
date Thu, 17 Jul 2014 22:50:49 -0500
parents c18ad59ae442
children 6fbbe46b35d5
files lib/pending.c lib/pending.h toys/pending/dhcpd.c toys/pending/klogd.c toys/pending/syslogd.c toys/pending/telnetd.c
diffstat 6 files changed, 4 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/lib/pending.c	Wed Jul 16 20:43:58 2014 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -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);
-}
--- a/lib/pending.h	Wed Jul 16 20:43:58 2014 -0500
+++ b/lib/pending.h	Thu Jul 17 22:50:49 2014 -0500
@@ -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);
--- a/toys/pending/dhcpd.c	Wed Jul 16 20:43:58 2014 -0500
+++ b/toys/pending/dhcpd.c	Thu Jul 17 22:50:49 2014 -0500
@@ -1086,7 +1086,7 @@
 
   infomode = LOG_CONSOLE;
   if (!(flag_chk(FLAG_f))) {
-    daemonize();
+    daemon(0,0);
     infomode = LOG_SILENT;
   }
   if (flag_chk(FLAG_S)) {
--- a/toys/pending/klogd.c	Wed Jul 16 20:43:58 2014 -0500
+++ b/toys/pending/klogd.c	Thu Jul 17 22:50:49 2014 -0500
@@ -68,7 +68,7 @@
 
   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");
--- a/toys/pending/syslogd.c	Wed Jul 16 20:43:58 2014 -0500
+++ b/toys/pending/syslogd.c	Thu Jul 17 22:50:49 2014 -0500
@@ -470,7 +470,7 @@
   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;
   }
--- a/toys/pending/telnetd.c	Wed Jul 16 20:43:58 2014 -0500
+++ b/toys/pending/telnetd.c	Thu Jul 17 22:50:49 2014 -0500
@@ -317,7 +317,7 @@
     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;