From d360320618fe3a7f53ac1f05ee3ac54323a03c82 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 15 Mar 1998 02:37:52 +0000 Subject: - 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) --- source3/lib/pidfile.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'source3/lib') 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); -- cgit