From f55c2e5316febfb498bcba8150f21494c1b79048 Mon Sep 17 00:00:00 2001
From: deuce <>
Date: Wed, 24 Mar 2004 01:19:36 +0000
Subject: [PATCH] Move daemon() into strn.cpp so it can be included in
 libsbbs.so if needed

---
 src/sbbs3/sbbscon.c | 36 ------------------------------------
 src/sbbs3/xtrn.cpp  | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 36 deletions(-)

diff --git a/src/sbbs3/sbbscon.c b/src/sbbs3/sbbscon.c
index dfd449b705..e02ef07dee 100644
--- a/src/sbbs3/sbbscon.c
+++ b/src/sbbs3/sbbscon.c
@@ -822,42 +822,6 @@ void _sighandler_rerun(int sig)
 	services_startup.recycle_now=TRUE;
 }
 
-#ifdef NEEDS_DAEMON
-/****************************************************************************/
-/* Daemonizes the process                                                   */
-/****************************************************************************/
-int
-daemon(nochdir, noclose)
-    int nochdir, noclose;
-{
-    int fd;
-
-    switch (fork()) {
-    case -1:
-        return (-1);
-    case 0:
-        break;
-    default:
-        _exit(0);
-    }
-
-    if (setsid() == -1)
-        return (-1);
-
-    if (!nochdir)
-        (void)chdir("/");
-
-    if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
-        (void)dup2(fd, STDIN_FILENO);
-        (void)dup2(fd, STDOUT_FILENO);
-        (void)dup2(fd, STDERR_FILENO);
-        if (fd > 2)
-            (void)close(fd);
-    }
-    return (0);
-}
-#endif /* NEEDS_DAEMON */
-
 static void handle_sigs(void)  {
 	int			sig;
 	sigset_t	sigs;
diff --git a/src/sbbs3/xtrn.cpp b/src/sbbs3/xtrn.cpp
index 855bd55511..e44c521232 100644
--- a/src/sbbs3/xtrn.cpp
+++ b/src/sbbs3/xtrn.cpp
@@ -1102,6 +1102,41 @@ static int login_tty(int fd)
 	return (0);
 }
 
+#ifdef NEEDS_DAEMON
+/****************************************************************************/
+/* Daemonizes the process                                                   */
+/****************************************************************************/
+int
+daemon(int nochdir, int noclose)
+{
+    int fd;
+
+    switch (fork()) {
+    case -1:
+        return (-1);
+    case 0:
+        break;
+    default:
+        _exit(0);
+    }
+
+    if (setsid() == -1)
+        return (-1);
+
+    if (!nochdir)
+        (void)chdir("/");
+
+    if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
+        (void)dup2(fd, STDIN_FILENO);
+        (void)dup2(fd, STDOUT_FILENO);
+        (void)dup2(fd, STDERR_FILENO);
+        if (fd > 2)
+            (void)close(fd);
+    }
+    return (0);
+}
+#endif
+
 static int openpty(int *amaster, int *aslave, char *name, struct termios *termp, winsize *winp)
 {
 	char line[] = "/dev/ptyXX";
-- 
GitLab