summaryrefslogtreecommitdiff
path: root/source3/lib/pidfile.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>1998-03-15 02:37:52 +0000
committerAndrew Tridgell <tridge@samba.org>1998-03-15 02:37:52 +0000
commitd360320618fe3a7f53ac1f05ee3ac54323a03c82 (patch)
tree97120a8949d82c8e9aab435bb56f6f0301beed28 /source3/lib/pidfile.c
parent69bb6f6f5fa472d2bf5c619a09aecc3b0ce4c254 (diff)
downloadsamba-d360320618fe3a7f53ac1f05ee3ac54323a03c82.tar.gz
samba-d360320618fe3a7f53ac1f05ee3ac54323a03c82.tar.bz2
samba-d360320618fe3a7f53ac1f05ee3ac54323a03c82.zip
- added the ability to kill off individual connections from SWAT (from
the status page) - split the claim_connection() code into its own file - fixed the claim_connection() code to lock the file when manipulating it - always claim a null connection at startup - fixed a bug in the pidfile code (This used to be commit abd4a17e21d12be3d1747e94ceb1915abaf135e3)
Diffstat (limited to 'source3/lib/pidfile.c')
-rw-r--r--source3/lib/pidfile.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/source3/lib/pidfile.c b/source3/lib/pidfile.c
index 8dee7421de..6cad1436eb 100644
--- a/source3/lib/pidfile.c
+++ b/source3/lib/pidfile.c
@@ -35,10 +35,17 @@ void pidfile_create(char *name)
int fd;
char buf[20];
pstring pidFile;
+ int pid;
sprintf(pidFile, "%s/%s.pid", lp_lockdir(), name);
- fd = open(pidFile, O_NONBLOCK | O_CREAT | O_WRONLY | O_TRUNC, 0644);
+ pid = pidfile_pid(name);
+ if (pid > 0 && process_exists(pid)) {
+ DEBUG(0,("ERROR: %s is already running\n", name));
+ exit(1);
+ }
+
+ fd = open(pidFile, O_NONBLOCK | O_CREAT | O_WRONLY, 0644);
if (fd < 0) {
DEBUG(0,("ERROR: can't open %s: %s\n", pidFile,
strerror(errno)));
@@ -50,8 +57,9 @@ void pidfile_create(char *name)
exit(1);
}
+ memset(buf, 0, sizeof(buf));
sprintf(buf, "%u\n", (unsigned int) getpid());
- if (write(fd, buf, strlen(buf)) < 0) {
+ if (write(fd, buf, sizeof(buf)) != sizeof(buf)) {
DEBUG(0,("ERROR: can't write to %s: %s\n",
pidFile, strerror(errno)));
exit(1);