chiark
/
gitweb
/
~mdw
/
tripe
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
fa4bef8
)
Separate detach-from-terminal code into a separate function.
author
mdw
<mdw>
Thu, 22 Feb 2001 09:07:08 +0000
(09:07 +0000)
committer
mdw
<mdw>
Thu, 22 Feb 2001 09:07:08 +0000
(09:07 +0000)
util.c
patch
|
blob
|
blame
|
history
util.h
patch
|
blob
|
blame
|
history
diff --git
a/util.c
b/util.c
index 4dd6f351df335e45f5ed2a1bd1e84a34190f36ea..54890b3f23509d0ce738088907ecf035754d586b 100644
(file)
--- a/
util.c
+++ b/
util.c
@@
-1,6
+1,6
@@
/* -*-c-*-
*
/* -*-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
*
*
* Utilities for the client and the server
*
@@
-29,6
+29,9
@@
/*----- Revision history --------------------------------------------------*
*
* $Log: util.c,v $
/*----- 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.
*
* Revision 1.1 2001/02/03 20:26:37 mdw
* Initial checkin.
*
@@
-51,23
+54,18
@@
/*----- Main code ---------------------------------------------------------*/
/*----- Main code ---------------------------------------------------------*/
-/* --- @u_d
aemon
@ --- *
+/* --- @u_d
etach
@ --- *
*
* Arguments: ---
*
*
* 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;
#ifdef TIOCNOTTY
{
int fd;
@@
-78,9
+76,28
@@
int u_daemon(void)
}
#endif
setsid();
}
#endif
setsid();
-
if (fork() > 0)
_exit(0);
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);
}
return (0);
}
diff --git
a/util.h
b/util.h
index b5fbd579f0a8971546c930911c09096a6e71fb2c..f9c5c78fbc8508508a85c0aede44c7fa7e626eaa 100644
(file)
--- a/
util.h
+++ b/
util.h
@@
-1,6
+1,6
@@
/* -*-c-*-
*
/* -*-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
*
*
* Utilities for the client and the server
*
@@
-29,6
+29,9
@@
/*----- Revision history --------------------------------------------------*
*
* $Log: util.h,v $
/*----- 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.
*
* Revision 1.1 2001/02/03 20:26:37 mdw
* Initial checkin.
*
@@
-41,10
+44,20
@@
extern "C" {
#endif
extern "C" {
#endif
-/*----- Header files ------------------------------------------------------*/
-
/*----- Functions provided ------------------------------------------------*/
/*----- 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: ---
/* --- @u_daemon@ --- *
*
* Arguments: ---
@@
-54,7
+67,7
@@
* Use: Becomes a daemon.
*/
* Use: Becomes a daemon.
*/
-int u_daemon(void);
+
extern
int u_daemon(void);
/*----- That's all, folks -------------------------------------------------*/
/*----- That's all, folks -------------------------------------------------*/