summaryrefslogtreecommitdiff
path: root/lib/pid_output.c
diff options
context:
space:
mode:
authorajs <ajs>2004-11-25 16:07:53 +0000
committerajs <ajs>2004-11-25 16:07:53 +0000
commite5879ca1d8ea26870dbf74f330f5e6f5a9c93bfa (patch)
tree890045008a54c7b046395417f7ece40c9426ef3f /lib/pid_output.c
parentad4d974d06ba3344e2e0df3277f7e0c42f018a4e (diff)
2004-11-25 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
* pid_output.c: (pid_output_lock) Fix 2 bugs: when locking, should set l_whence to SEEK_SET, not SEEK_END. And after writing new pid to file, must ftruncate to eliminate any extraneous bytes left over from the last time a pid was written.
Diffstat (limited to 'lib/pid_output.c')
-rw-r--r--lib/pid_output.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/pid_output.c b/lib/pid_output.c
index 2782b9d4..ae3393c1 100644
--- a/lib/pid_output.c
+++ b/lib/pid_output.c
@@ -23,8 +23,7 @@
#include <zebra.h>
#include <fcntl.h>
#include <log.h>
-
-pid_t pid_output_lock(const char *);
+#include "version.h"
pid_t
pid_output (const char *path)
@@ -77,11 +76,13 @@ pid_output_lock (const char *path)
}
else
{
+ size_t pidsize;
+
umask(oldumask);
memset (&lock, 0, sizeof(lock));
lock.l_type = F_WRLCK;
- lock.l_whence = SEEK_END;
+ lock.l_whence = SEEK_SET;
if (fcntl(fd, F_SETLK, &lock) < 0)
{
@@ -90,7 +91,13 @@ pid_output_lock (const char *path)
}
sprintf (buf, "%d\n", (int) pid);
- tmp = write (fd, buf, strlen (buf));
+ pidsize = strlen(buf);
+ if ((tmp = write (fd, buf, pidsize)) != (int)pidsize)
+ zlog_err("Could not write pid %d to pid_file %s, rc was %d: %s",
+ (int)pid,path,tmp,safe_strerror(errno));
+ else if (ftruncate(fd, pidsize) < 0)
+ zlog_err("Could not truncate pid_file %s to %u bytes: %s",
+ path,(u_int)pidsize,safe_strerror(errno));
}
return pid;
}