diff options
author | Jeremy Allison <jra@samba.org> | 1998-07-02 23:57:56 +0000 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 1998-07-02 23:57:56 +0000 |
commit | efc2732f55c909a2d6228be2185a69c3569f7c97 (patch) | |
tree | 636f6e8c7439d850b0f49d8c49b88ede418b92d1 /source3/lib | |
parent | 6491a956ef0b6a54b28887521f75e2f54f18a6d2 (diff) | |
download | samba-efc2732f55c909a2d6228be2185a69c3569f7c97.tar.gz samba-efc2732f55c909a2d6228be2185a69c3569f7c97.tar.xz samba-efc2732f55c909a2d6228be2185a69c3569f7c97.zip |
Fix for pidfile startup message.
Jeremy.
(This used to be commit 108284cc28d44ffea028209cf28b746008bdf455)
Diffstat (limited to 'source3/lib')
-rw-r--r-- | source3/lib/pidfile.c | 69 |
1 files changed, 34 insertions, 35 deletions
diff --git a/source3/lib/pidfile.c b/source3/lib/pidfile.c index 9cb3f5afef4..fecc759da94 100644 --- a/source3/lib/pidfile.c +++ b/source3/lib/pidfile.c @@ -28,6 +28,31 @@ extern int DEBUGLEVEL; #define O_NONBLOCK #endif +/* return the pid in a pidfile. return 0 if the process (or pidfile) + does not exist */ +int pidfile_pid(char *name) +{ + FILE *f; + unsigned ret; + pstring pidFile; + + slprintf(pidFile, sizeof(pidFile)-1, "%s/%s.pid", lp_lockdir(), name); + + f = fopen(pidFile, "r"); + if (!f) { + return 0; + } + + if (fscanf(f,"%u", &ret) != 1) { + fclose(f); + return 0; + } + fclose(f); + + if (!process_exists(ret)) return 0; + + return ret; +} /* create a pid file in the lock directory. open it and leave it locked */ void pidfile_create(char *name) @@ -40,57 +65,31 @@ void pidfile_create(char *name) slprintf(pidFile, sizeof(pidFile)-1, "%s/%s.pid", lp_lockdir(), name); pid = pidfile_pid(name); - if (pid > 0 && process_exists(pid)) { - DEBUG(0,("ERROR: %s is already running\n", name)); - exit(1); - } + if (pid > 0 && process_exists(pid)) { + DEBUG(0,("ERROR: %s is already running. File %s exists and process id %d is running.\n", + name, pidFile, pid)); + 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, + DEBUG(0,("ERROR: can't open %s: Error was %s\n", pidFile, strerror(errno))); exit(1); } if (fcntl_lock(fd,F_SETLK,0,1,F_WRLCK)==False) { - DEBUG(0,("ERROR: %s is already running\n", name)); + DEBUG(0,("ERROR: %s : fcntl lock of file %s failed. Error was %s\n", + name, pidFile, strerror(errno))); exit(1); } memset(buf, 0, sizeof(buf)); slprintf(buf, sizeof(buf) - 1, "%u\n", (unsigned int) getpid()); if (write(fd, buf, sizeof(buf)) != sizeof(buf)) { - DEBUG(0,("ERROR: can't write to %s: %s\n", + DEBUG(0,("ERROR: can't write to file %s: %s\n", pidFile, strerror(errno))); exit(1); } /* Leave pid file open & locked for the duration... */ } - - -/* return the pid in a pidfile. return 0 if the process (or pidfile) - does not exist */ -int pidfile_pid(char *name) -{ - FILE *f; - pstring pidFile; - unsigned ret; - - slprintf(pidFile, sizeof(pidFile)-1, "%s/%s.pid", lp_lockdir(), name); - - f = fopen(pidFile, "r"); - if (!f) { - return 0; - } - - if (fscanf(f,"%u", &ret) != 1) { - fclose(f); - return 0; - } - fclose(f); - - if (!process_exists(ret)) return 0; - - return ret; -} - |