diff options
author | Guy Helmer <ghelmer@FreeBSD.org> | 2003-11-10 22:01:42 +0000 |
---|---|---|
committer | Guy Helmer <ghelmer@FreeBSD.org> | 2003-11-10 22:01:42 +0000 |
commit | 8b2b22e84def6de2172ba8a9fbc9d41d0444d202 (patch) | |
tree | 0943c2b70e62ac5fe23f445330e4679ec07ddff1 /lib/libc/gen/daemon.3 | |
parent | 2c85cbd9b515a291d37ca754f5f0f1f7b83387b7 (diff) | |
download | src-8b2b22e84def6de2172ba8a9fbc9d41d0444d202.tar.gz src-8b2b22e84def6de2172ba8a9fbc9d41d0444d202.zip |
Prevent abnormal termination of a child daemon process when created
by a parent that is a session leader (e.g., login shell) by ignoring
SIGHUP in before calling fork(2) and then restoring SIGHUP's action
after setsid(3). Based on the patch by Martin Kammerhofer
<mkamm@gmx.net>.
PR: bin/25462
Reviewed by: bde, alex.neyman@auriga.ru
Notes
Notes:
svn path=/head/; revision=122442
Diffstat (limited to 'lib/libc/gen/daemon.3')
-rw-r--r-- | lib/libc/gen/daemon.3 | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/libc/gen/daemon.3 b/lib/libc/gen/daemon.3 index a08d0df0a1a1..97025e6c29a4 100644 --- a/lib/libc/gen/daemon.3 +++ b/lib/libc/gen/daemon.3 @@ -71,12 +71,13 @@ The function may fail and set .Va errno for any of the errors specified for the library functions -.Xr fork 2 +.Xr fork 2 , and .Xr setsid 2 . .Sh SEE ALSO .Xr fork 2 , -.Xr setsid 2 +.Xr setsid 2 , +.Xr sigaction 2 .Sh HISTORY The .Fn daemon @@ -101,3 +102,15 @@ should therefore either call .Fn daemon before opening any files or sockets, or verify that any file descriptors obtained have values greater than 2. +.Pp +The +.Fn daemon +function temporarily ignores +.Dv SIGHUP +while calling +.Xr setsid 2 +to prevent a parent session group leader's calls to +.Xr fork 2 +and then +.Xr _exit 2 +from prematurely terminating the child process. |