/* -*-c-*-
*
- * $Id: util.c,v 1.1 2001/02/03 20:26:37 mdw Exp $
+ * $Id: util.c,v 1.2 2001/02/22 09:07:08 mdw Exp $
*
* Utilities for the client and the server
*
/*----- Revision history --------------------------------------------------*
*
* $Log: util.c,v $
+ * Revision 1.2 2001/02/22 09:07:08 mdw
+ * Separate detach-from-terminal code into a separate function.
+ *
* Revision 1.1 2001/02/03 20:26:37 mdw
* Initial checkin.
*
/*----- 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;
}
#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);
}
/* -*-c-*-
*
- * $Id: util.h,v 1.1 2001/02/03 20:26:37 mdw Exp $
+ * $Id: util.h,v 1.2 2001/02/22 09:07:08 mdw Exp $
*
* Utilities for the client and the server
*
/*----- Revision history --------------------------------------------------*
*
* $Log: util.h,v $
+ * Revision 1.2 2001/02/22 09:07:08 mdw
+ * Separate detach-from-terminal code into a separate function.
+ *
* Revision 1.1 2001/02/03 20:26:37 mdw
* Initial checkin.
*
extern "C" {
#endif
-/*----- Header files ------------------------------------------------------*/
-
/*----- Functions provided ------------------------------------------------*/
+/* --- @u_detach@ --- *
+ *
+ * Arguments: ---
+ *
+ * Returns: ---
+ *
+ * Use: Detaches from the current terminal and ensures it can never
+ * acquire a new one. Calls @fork@.
+ */
+
+extern void u_detach(void);
+
/* --- @u_daemon@ --- *
*
* Arguments: ---
* Use: Becomes a daemon.
*/
-int u_daemon(void);
+extern int u_daemon(void);
/*----- That's all, folks -------------------------------------------------*/