diff options
author | Volker Lendecke <vl@samba.org> | 2009-06-18 11:45:57 +0200 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2009-06-18 16:17:57 -0700 |
commit | 5a9ca3db032af5938e9709f3355a1f45b1e08d27 (patch) | |
tree | 5f12936d01b8c62531b07f307fdfee51ea65bcd3 /source3/lib | |
parent | 31885822ae0744582fb145f541bd4cfc590173d6 (diff) | |
download | samba-5a9ca3db032af5938e9709f3355a1f45b1e08d27.tar.gz samba-5a9ca3db032af5938e9709f3355a1f45b1e08d27.tar.bz2 samba-5a9ca3db032af5938e9709f3355a1f45b1e08d27.zip |
Fix bug 4699: Remove pidfile on clean shutdown
Diffstat (limited to 'source3/lib')
-rw-r--r-- | source3/lib/pidfile.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/source3/lib/pidfile.c b/source3/lib/pidfile.c index 3495dae5c2..37b36af277 100644 --- a/source3/lib/pidfile.c +++ b/source3/lib/pidfile.c @@ -25,6 +25,8 @@ #define O_NONBLOCK #endif +static char *pidFile_name = NULL; + /* return the pid in a pidfile. return 0 if the process (or pidfile) does not exist */ pid_t pidfile_pid(const char *name) @@ -88,7 +90,6 @@ void pidfile_create(const char *program_name) char buf[20]; const char *short_configfile; char *name; - char *pidFile; pid_t pid; /* Add a suffix to the program name if this is a process with a @@ -110,27 +111,28 @@ void pidfile_create(const char *program_name) } } - if (asprintf(&pidFile, "%s/%s.pid", lp_piddir(), name) == -1) { + if (asprintf(&pidFile_name, "%s/%s.pid", lp_piddir(), name) == -1) { smb_panic("asprintf failed"); } pid = pidfile_pid(name); if (pid != 0) { DEBUG(0,("ERROR: %s is already running. File %s exists and process id %d is running.\n", - name, pidFile, (int)pid)); + name, pidFile_name, (int)pid)); exit(1); } - fd = sys_open(pidFile, O_NONBLOCK | O_CREAT | O_WRONLY | O_EXCL, 0644); + fd = sys_open(pidFile_name, O_NONBLOCK | O_CREAT | O_WRONLY | O_EXCL, + 0644); if (fd == -1) { - DEBUG(0,("ERROR: can't open %s: Error was %s\n", pidFile, + DEBUG(0,("ERROR: can't open %s: Error was %s\n", pidFile_name, strerror(errno))); exit(1); } if (fcntl_lock(fd,SMB_F_SETLK,0,1,F_WRLCK)==False) { DEBUG(0,("ERROR: %s : fcntl lock of file %s failed. Error was %s\n", - name, pidFile, strerror(errno))); + name, pidFile_name, strerror(errno))); exit(1); } @@ -138,10 +140,18 @@ void pidfile_create(const char *program_name) slprintf(buf, sizeof(buf) - 1, "%u\n", (unsigned int) sys_getpid()); if (write(fd, buf, strlen(buf)) != (ssize_t)strlen(buf)) { DEBUG(0,("ERROR: can't write to file %s: %s\n", - pidFile, strerror(errno))); + pidFile_name, strerror(errno))); exit(1); } /* Leave pid file open & locked for the duration... */ SAFE_FREE(name); - SAFE_FREE(pidFile); +} + +void pidfile_unlink(void) +{ + if (pidFile_name == NULL) { + return; + } + unlink(pidFile_name); + SAFE_FREE(pidFile_name); } |