aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/gen/daemon.3
diff options
context:
space:
mode:
authorCrist J. Clark <cjc@FreeBSD.org>2002-01-14 02:08:02 +0000
committerCrist J. Clark <cjc@FreeBSD.org>2002-01-14 02:08:02 +0000
commit971730fc67968ec59db33ec6e3a13e2e09c8d224 (patch)
tree8bab8b0b61bd05c3e8f6bad304c9b16018445bd1 /lib/libc/gen/daemon.3
parent2b8877f48698ff65e0a586c9b0e0b9db79370f04 (diff)
downloadsrc-971730fc67968ec59db33ec6e3a13e2e09c8d224.tar.gz
src-971730fc67968ec59db33ec6e3a13e2e09c8d224.zip
Merge some updates and markup fixes from OpenBSD. This is mainly
motivated by the new "CAVEATS" section. Inspired by: alfred noting NetBSD's merging OpenBSD's changes Obtained from: OpenBSD
Notes
Notes: svn path=/head/; revision=89323
Diffstat (limited to 'lib/libc/gen/daemon.3')
-rw-r--r--lib/libc/gen/daemon.336
1 files changed, 30 insertions, 6 deletions
diff --git a/lib/libc/gen/daemon.3 b/lib/libc/gen/daemon.3
index c9ce0f4e8842..76932f380082 100644
--- a/lib/libc/gen/daemon.3
+++ b/lib/libc/gen/daemon.3
@@ -54,20 +54,25 @@ Unless the argument
.Fa nochdir
is non-zero,
.Fn daemon
-changes the current working directory to the root (``/'').
+changes the current working directory to the root
+.Pq Pa / .
.Pp
Unless the argument
.Fa noclose
is non-zero,
.Fn daemon
-will redirect standard input, standard output and standard error
-to ``/dev/null''.
+will redirect standard input, standard output, and standard error to
+.Pa /dev/null .
+.Sh RETURN VALUES
+Upon success,
+.Fn daemon
+returns 0; otherwise \-1 is returned.
.Sh ERRORS
-If an error occurs,
+The function
.Fn daemon
-returns -1 and sets the global variable
+may fail and set
.Va errno
-to any of the errors specified for the library functions
+for any of the errors specified for the library functions
.Xr fork 2
and
.Xr setsid 2 .
@@ -79,3 +84,22 @@ The
.Fn daemon
function first appeared in
.Bx 4.4 .
+.Sh CAVEATS
+Unless the
+.Ar noclose
+argument is non-zero,
+.Fn daemon
+will close the first three file descriptors and redirect them to
+.Pa /dev/null .
+Normally, these correspond to standard input, standard output, and
+standard error.
+However, if any of those file descriptors refer to something else they
+will still be closed, resulting in incorrect behavior of the calling program.
+This can happen if any of standard input, standard output, or standard
+error have been closed before the program was run.
+Programs using
+.Fn daemon
+should therefore either call
+.Fn daemon
+before opening any files or sockets, or verify that any file
+descriptors obtained have values greater than 2.