diff options
author | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2002-05-22 01:21:41 +0000 |
---|---|---|
committer | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2002-05-22 01:21:41 +0000 |
commit | 73f1ddd8f579962f829a5161ff561fa309506a13 (patch) | |
tree | c1175283b2631c7585789bc3e047310223a9d237 | |
parent | ee5f3ac31112a06ac7401e954d9058400d90e715 (diff) |
atexit(3) can fail. handle error accordingly. deraadt ok
XXX libraries should not use atexit(3) from within, as program can terminate
with _exit.
-rw-r--r-- | lib/libutil/pidfile.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/libutil/pidfile.c b/lib/libutil/pidfile.c index e009572db63..ae6e9342b3b 100644 --- a/lib/libutil/pidfile.c +++ b/lib/libutil/pidfile.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pidfile.c,v 1.3 2002/01/02 10:22:18 mpech Exp $ */ +/* $OpenBSD: pidfile.c,v 1.4 2002/05/22 01:21:40 itojun Exp $ */ /* $NetBSD: pidfile.c,v 1.4 2001/02/19 22:43:42 cgd Exp $ */ /*- @@ -38,7 +38,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$OpenBSD: pidfile.c,v 1.3 2002/01/02 10:22:18 mpech Exp $"; +static const char rcsid[] = "$OpenBSD: pidfile.c,v 1.4 2002/05/22 01:21:40 itojun Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> @@ -95,7 +95,15 @@ pidfile(const char *basename) } pidfile_pid = pid; - (void) atexit(pidfile_cleanup); + if (atexit(pidfile_cleanup) < 0) { + save_errno = errno; + (void) unlink(pidfile_path); + free(pidfile_path); + pidfile_path = NULL; + pidfile_pid = 0; + errno = save_errno; + return (-1); + } return (0); } |