- Add a note that passing NULL to pidfile_write(), pidfile_remove() and

pidfile_close() functions is safe. This possibility is used in example code.
- Cast pid_t to int.

Requested by:	yar
This commit is contained in:
Pawel Jakub Dawidek 2006-01-28 14:13:15 +00:00
parent b098466191
commit 560c4fc142

View File

@ -105,14 +105,24 @@ will be set.
.Rv -std pidfile_write pidfile_close pidfile_remove
.Sh EXAMPLES
The following example shows in which order these functions should be used.
Note that it is safe to pass
.Dv NULL
to
.Fn pidfile_write ,
.Fn pidfile_remove
and
.Fn pidfile_close
functions.
.Bd -literal
struct pidfh *pfh;
pid_t otherpid, childpid;
pfh = pidfile_open("/var/run/daemon.pid", 0600, &otherpid);
if (pfh == NULL) {
if (errno == EEXIST)
errx(EXIT_FAILURE, "Daemon already running, pid: %d.", otherpid);
if (errno == EEXIST) {
errx(EXIT_FAILURE, "Daemon already running, pid: %d.",
(int)otherpid);
}
/* If we cannot create pidfile from other reasons, only warn. */
warn("Cannot open or create pidfile");
}
@ -137,7 +147,7 @@ for (;;) {
/* Do child work. */
break;
default:
syslog(LOG_INFO, "Child %d started.", childpid);
syslog(LOG_INFO, "Child %d started.", (int)childpid);
break;
}
}