summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRalf Baechle <ralf@linux-mips.org>2015-05-20 00:45:27 +0200
committerRalf Baechle <ralf@linux-mips.org>2015-05-20 00:45:27 +0200
commitbd2655711d9de446c8b8125d5d696e56aebc5053 (patch)
treeebc628a89e9bcba1af63a699e1b9e38b6fa0c661
parentcea8a07505b8964557441ea3b3fb57b12b5abd36 (diff)
Modernize daemon_start(3).
daemon_start(3) was implemented using ancient APIs. Modernize and simplify using setsid(). Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
-rw-r--r--configure.ac2
-rw-r--r--daemon.c18
2 files changed, 8 insertions, 12 deletions
diff --git a/configure.ac b/configure.ac
index ab6e497..553fba1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -12,8 +12,8 @@ AC_PROG_LIBTOOL
dnl Checks for libraries.
-AC_FUNC_SETPGRP
AC_TYPE_SIGNAL
+AC_CHECK_FUNC(setsid,, AC_MSG_ERROR([setsid not found]))
AC_CHECK_FUNCS(socket strdup strerror strspn)
dnl Checks for header files.
diff --git a/daemon.c b/daemon.c
index 01511b6..3658c94 100644
--- a/daemon.c
+++ b/daemon.c
@@ -17,7 +17,7 @@ int daemon_start(int ignsigcld)
/* Programming_ pp.72-85, by W. Richard Stephens, Prentice */
/* Hall PTR, 1990 */
- int childpid, fd;
+ int childpid;
/* If started by init, don't bother */
if (getppid() == 1)
@@ -35,16 +35,12 @@ int daemon_start(int ignsigcld)
exit(0);
}
- /* Disassociate from controlling terminal and process group. */
- /* Ensure the process can't reacquire a new controlling terminal. */
- if (setpgrp() == -1)
- return 0;
-
- if ((fd = open("/dev/tty", O_RDWR)) >= 0) {
- /* loose controlling tty */
- ioctl(fd, TIOCNOTTY, NULL);
- close(fd);
- }
+ /*
+ * Disassociate from controlling terminal and process group and
+ * ensure the process can't reacquire a new controlling terminal.
+ * We're freshly forked, so setsid can't fail.
+ */
+ (void) setsid();
out:
/* Move the current directory to root, to make sure we aren't on a */