chiark / gitweb /
Rename ethereal -> wireshark.
[tripe] / util.c
diff --git a/util.c b/util.c
index 4dd6f351df335e45f5ed2a1bd1e84a34190f36ea..ceeb0bd519ca7780e570f92fddeaed9c86ab27ee 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: util.c,v 1.1 2001/02/03 20:26:37 mdw Exp $
+ * $Id: util.c,v 1.3 2004/04/08 01:36:17 mdw Exp $
  *
  * Utilities for the client and the server
  *
  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
-/*----- Revision history --------------------------------------------------* 
- *
- * $Log: util.c,v $
- * Revision 1.1  2001/02/03 20:26:37  mdw
- * Initial checkin.
- *
- */
-
 /*----- Header files ------------------------------------------------------*/
 
 #include <errno.h>
 
 /*----- Main code ---------------------------------------------------------*/
 
-/* --- @u_daemon@ --- *
+/* --- @u_detach@ --- *
  *
  * Arguments:  ---
  *
- * Returns:    Zero if OK, nonzero on failure.
+ * Returns:    ---
  *
- * Use:                Becomes a daemon.
+ * Use:                Detaches from the current terminal and ensures it can never
+ *             acquire a new one.  Calls @fork@.
  */
 
-int u_daemon(void)
+void u_detach(void)
 {
-  pid_t kid;
-
-  if ((kid = fork()) < 0)
-    return (-1);
-  if (kid)
-    _exit(0);
 #ifdef TIOCNOTTY
   {
     int fd;
@@ -78,9 +65,28 @@ int u_daemon(void)
   }
 #endif
   setsid();
-
   if (fork() > 0)
     _exit(0);
+}
+
+/* --- @u_daemon@ --- *
+ *
+ * Arguments:  ---
+ *
+ * Returns:    Zero if OK, nonzero on failure.
+ *
+ * Use:                Becomes a daemon.
+ */
+
+int u_daemon(void)
+{
+  pid_t kid;
+
+  if ((kid = fork()) < 0)
+    return (-1);
+  if (kid)
+    _exit(0);
+  u_detach();
   return (0);
 }