summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
Diffstat (limited to 'source3')
-rw-r--r--source3/include/proto.h2
-rw-r--r--source3/lib/pidfile.c69
2 files changed, 35 insertions, 36 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 888f26e906..06f0015638 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -1689,8 +1689,8 @@ void pcap_printer_fn(void (*fn)(char *, char *));
/*The following definitions come from pidfile.c */
-void pidfile_create(char *name);
int pidfile_pid(char *name);
+void pidfile_create(char *name);
/*The following definitions come from pipes.c */
diff --git a/source3/lib/pidfile.c b/source3/lib/pidfile.c
index 9cb3f5afef..fecc759da9 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;
-}
-