summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2012-07-19 16:08:16 -0700
committerJeremy Allison <jra@samba.org>2012-07-19 16:08:16 -0700
commit3e476e184dc388677012778ca1d422273db76af6 (patch)
treebbd1c53b543abd411b60074014f9860ce077e0dd /lib
parent2922fdaaf0ab2178a1701141cc2435af33c10dc8 (diff)
downloadsamba-3e476e184dc388677012778ca1d422273db76af6.tar.gz
samba-3e476e184dc388677012778ca1d422273db76af6.tar.bz2
samba-3e476e184dc388677012778ca1d422273db76af6.zip
Add debugs to functions. Add pidfile_unlink().
Diffstat (limited to 'lib')
-rw-r--r--lib/util/pidfile.c24
-rw-r--r--lib/util/pidfile.h1
2 files changed, 25 insertions, 0 deletions
diff --git a/lib/util/pidfile.c b/lib/util/pidfile.c
index ac8ff8a0c3..88463711f9 100644
--- a/lib/util/pidfile.c
+++ b/lib/util/pidfile.c
@@ -58,24 +58,32 @@ pid_t pidfile_pid(const char *piddir, const char *name)
ret = (pid_t)atoi(pidstr);
if (ret <= 0) {
+ DEBUG(1, ("Could not parse contents of pidfile %s\n",
+ pidFile));
goto noproc;
}
if (!process_exists_by_pid(ret)) {
+ DEBUG(10, ("Process with PID=%d does not exist.\n", (int)ret));
goto noproc;
}
if (fcntl_lock(fd,F_SETLK,0,1,F_RDLCK)) {
/* we could get the lock - it can't be a Samba process */
+ DEBUG(10, ("Process with PID=%d is not a Samba process.\n",
+ (int)ret));
goto noproc;
}
close(fd);
SAFE_FREE(pidFile);
+ DEBUG(10, ("Process with PID=%d is running.\n", (int)ret));
return ret;
noproc:
close(fd);
+ DEBUG(10, ("Deleting %s, since %d is not a Samba process.\n", pidFile,
+ (int)ret));
unlink(pidFile);
SAFE_FREE(pidFile);
return 0;
@@ -129,3 +137,19 @@ void pidfile_create(const char *piddir, const char *name)
/* Leave pid file open & locked for the duration... */
SAFE_FREE(pidFile);
}
+
+void pidfile_unlink(const char *piddir, const char *name)
+{
+ int ret;
+ char *pidFile = NULL;
+
+ if (asprintf(&pidFile, "%s/%s.pid", piddir, name) < 0) {
+ DEBUG(0,("ERROR: Out of memory\n"));
+ exit(1);
+ }
+ ret = unlink(pidFile);
+ if (ret == -1) {
+ DEBUG(0,("Failed to delete pidfile %s. Error was %s\n",
+ pidFile, strerror(errno)));
+ }
+}
diff --git a/lib/util/pidfile.h b/lib/util/pidfile.h
index 92a277d820..d504f526a5 100644
--- a/lib/util/pidfile.h
+++ b/lib/util/pidfile.h
@@ -22,5 +22,6 @@
pid_t pidfile_pid(const char *piddir, const char *name);
void pidfile_create(const char *piddir, const char *program_name);
+void pidfile_unlink(const char *piddir, const char *program_name);
#endif