summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorajs <ajs>2004-12-17 20:50:00 +0000
committerajs <ajs>2004-12-17 20:50:00 +0000
commit202d08cab9ef110dcbf6202cd0223d8877c7f0b6 (patch)
tree50fabfbb3e4567c9f4fd91d08c3ec72529158545 /lib
parentfa40f65874ca21bb9cca59ab5ddc8dbaf046f3c8 (diff)
2004-12-17 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
* pid_output.c: (pid_output_lock) Eliminate static function, and just use the #ifdef to decide which version of the function to include. This eliminates a compilation problem with gcc4. And fix the non-fcntl version so that it actually compiles. Exit with status 1 instead of -1 on error.
Diffstat (limited to 'lib')
-rw-r--r--lib/ChangeLog8
-rw-r--r--lib/pid_output.c40
2 files changed, 29 insertions, 19 deletions
diff --git a/lib/ChangeLog b/lib/ChangeLog
index 22f60c24..a91901cd 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,3 +1,11 @@
+2004-12-17 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
+
+ * pid_output.c: (pid_output_lock) Eliminate static function, and just
+ use the #ifdef to decide which version of the function to include.
+ This eliminates a compilation problem with gcc4. And fix the
+ non-fcntl version so that it actually compiles. Exit with
+ status 1 instead of -1 on error.
+
2004-12-15 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
* sigevent.c: (trap_default_signals) Ignore SIGPIPE instead of exiting.
diff --git a/lib/pid_output.c b/lib/pid_output.c
index 11e1243d..a098c63c 100644
--- a/lib/pid_output.c
+++ b/lib/pid_output.c
@@ -25,13 +25,14 @@
#include <log.h>
#include "version.h"
+#ifndef HAVE_FCNTL
+
pid_t
pid_output (const char *path)
{
-#ifndef HAVE_FCNTL
FILE *fp;
pid_t pid;
- mask_t oldumask;
+ mode_t oldumask;
pid = getpid();
@@ -42,20 +43,20 @@ pid_output (const char *path)
fprintf (fp, "%d\n", (int) pid);
fclose (fp);
umask(oldumask);
- return -1;
+ return pid;
}
+ /* XXX Why do we continue instead of exiting? This seems incompatible
+ with the behavior of the fcntl version below. */
+ zlog_warn("Can't fopen pid lock file %s (%s), continuing",
+ path, safe_strerror(errno));
umask(oldumask);
- return pid;
-#else
- static pid_t pid_output_lock (const char *);
-
- return pid_output_lock(path);
-#endif /* HAVE_FCNTL */
+ return -1;
}
-#ifdef HAVE_FCNTL
-static pid_t
-pid_output_lock (const char *path)
+#else /* HAVE_FCNTL */
+
+pid_t
+pid_output (const char *path)
{
int tmp;
int fd;
@@ -68,12 +69,12 @@ pid_output_lock (const char *path)
oldumask = umask(0777 & ~LOGFILE_MASK);
fd = open (path, O_RDWR | O_CREAT, LOGFILE_MASK);
- if (fd < 0)
- {
- zlog_err( "Can't creat pid lock file %s (%s), exit",
- path, safe_strerror(errno));
+ if (fd < 0)
+ {
+ zlog_err("Can't create pid lock file %s (%s), exiting",
+ path, safe_strerror(errno));
umask(oldumask);
- exit (-1);
+ exit(1);
}
else
{
@@ -87,8 +88,8 @@ pid_output_lock (const char *path)
if (fcntl(fd, F_SETLK, &lock) < 0)
{
- zlog_err("Could not lock pid_file %s, exit", path);
- exit (-1);
+ zlog_err("Could not lock pid_file %s, exiting", path);
+ exit(1);
}
sprintf (buf, "%d\n", (int) pid);
@@ -102,4 +103,5 @@ pid_output_lock (const char *path)
}
return pid;
}
+
#endif /* HAVE_FCNTL */