[SCM] Samba Shared Repository - branch v3-4-stable updated - release-3-4-0pre2-45-geed5630

Karolin Seeger kseeger at samba.org
Fri Jun 19 08:28:07 GMT 2009


The branch, v3-4-stable has been updated
       via  eed5630c7ab918bb45de7131359af2173f9e0df2 (commit)
      from  256b2c4e2055170c726439e17f586eafa856965e (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-4-stable


- Log -----------------------------------------------------------------
commit eed5630c7ab918bb45de7131359af2173f9e0df2
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Jun 18 11:45:57 2009 +0200

    Fix bug 4699: Remove pidfile on clean shutdown
    (cherry picked from commit 5a9ca3db032af5938e9709f3355a1f45b1e08d27)
    (cherry picked from commit 9424e91ecdcf2e5dbdd06e9d97693dd193608324)

-----------------------------------------------------------------------

Summary of changes:
 source3/include/proto.h     |    1 +
 source3/lib/pidfile.c       |   26 ++++++++++++++++++--------
 source3/nmbd/nmbd.c         |    2 ++
 source3/smbd/server.c       |    3 +++
 source3/winbindd/winbindd.c |    4 ++++
 5 files changed, 28 insertions(+), 8 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/include/proto.h b/source3/include/proto.h
index b5c0608..18555bc 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -587,6 +587,7 @@ int nt_status_to_pam(NTSTATUS nt_status);
 
 pid_t pidfile_pid(const char *name);
 void pidfile_create(const char *program_name);
+void pidfile_unlink(void);
 
 /* The following definitions come from lib/popt_common.c  */
 
diff --git a/source3/lib/pidfile.c b/source3/lib/pidfile.c
index 3495dae..37b36af 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);
 }
diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c
index 064242b..f31e7b1 100644
--- a/source3/nmbd/nmbd.c
+++ b/source3/nmbd/nmbd.c
@@ -82,6 +82,8 @@ static void terminate(void)
 	/* If there was an async dns child - kill it. */
 	kill_async_dns_child();
 
+	pidfile_unlink();
+
 	exit(0);
 }
 
diff --git a/source3/smbd/server.c b/source3/smbd/server.c
index 30addaf..a6689b8 100644
--- a/source3/smbd/server.c
+++ b/source3/smbd/server.c
@@ -842,6 +842,9 @@ static void exit_server_common(enum server_exit_reason how,
 	} else {    
 		DEBUG(3,("Server exit (%s)\n",
 			(reason ? reason : "normal exit")));
+		if (am_parent) {
+			pidfile_unlink();
+		}
 	}
 
 	/* if we had any open SMB connections when we exited then we
diff --git a/source3/winbindd/winbindd.c b/source3/winbindd/winbindd.c
index 72ae813..33b35e0 100644
--- a/source3/winbindd/winbindd.c
+++ b/source3/winbindd/winbindd.c
@@ -170,6 +170,10 @@ static void terminate(bool is_parent)
 	}
 #endif
 
+	if (is_parent) {
+		pidfile_unlink();
+	}
+
 	exit(0);
 }
 


-- 
Samba Shared Repository


More information about the samba-cvs mailing list