[SCM] Samba Shared Repository - branch master updated

Jeremy Allison jra at samba.org
Thu Jul 19 19:58:01 MDT 2012


The branch, master has been updated
       via  b336b8e Remove source3/lib/pidfile.c
       via  e8dbf28 Move everything to use the common pidfile functions.
       via  f58d8fe Fix the configure build - add lib/util/pidfile.o into UTIL_OBJ.
       via  0d24370 Make the s3 pidfile use the common code inside lib/util/pidfile.c
       via  3e476e1 Add debugs to functions. Add pidfile_unlink().
       via  2922fda Move source4/smbd/pidfile into lib/util in preparation for making it in common.
      from  03a6137 s3-param: Remove special case for lp_ctdbd_socket(), set CTDB_PATH as default

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit b336b8ed586e7058e24332339241ffd31ccb1b68
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Jul 19 16:41:07 2012 -0700

    Remove source3/lib/pidfile.c
    
    Autobuild-User(master): Jeremy Allison <jra at samba.org>
    Autobuild-Date(master): Fri Jul 20 03:57:20 CEST 2012 on sn-devel-104

commit e8dbf2889f0f5c6d213e92cbfd97b6a874aedb03
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Jul 19 16:36:18 2012 -0700

    Move everything to use the common pidfile functions.
    
    The extra code in source3/lib/pidfile.c is no longer needed.

commit f58d8feabc4b2c75681af1effeb4fb062cee74bd
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Jul 19 16:21:15 2012 -0700

    Fix the configure build - add lib/util/pidfile.o into UTIL_OBJ.

commit 0d24370c76002bb9db91f23e74f887805b070304
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Jul 19 16:08:49 2012 -0700

    Make the s3 pidfile use the common code inside lib/util/pidfile.c

commit 3e476e184dc388677012778ca1d422273db76af6
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Jul 19 16:08:16 2012 -0700

    Add debugs to functions. Add pidfile_unlink().

commit 2922fdaaf0ab2178a1701141cc2435af33c10dc8
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Jul 19 15:41:52 2012 -0700

    Move source4/smbd/pidfile into lib/util in preparation for making it in common.

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

Summary of changes:
 {source4/smbd => lib/util}/pidfile.c               |   26 +++-
 .../python/modules.h => lib/util/pidfile.h         |   20 ++-
 lib/util/wscript_build                             |    2 +-
 source3/Makefile.in                                |   11 +-
 source3/include/proto.h                            |    6 -
 source3/lib/pidfile.c                              |  191 --------------------
 source3/libsmb/clidgram.c                          |    3 +-
 source3/nmbd/nmbd.c                                |    5 +-
 source3/smbd/server.c                              |    3 +-
 source3/smbd/server_exit.c                         |    3 +-
 source3/utils/smbcontrol.c                         |    3 +-
 source3/web/startstop.c                            |    8 +-
 source3/web/statuspage.c                           |    3 +-
 source3/winbindd/winbindd.c                        |    5 +-
 source3/wscript_build                              |    6 -
 source4/smbd/server.c                              |    2 +-
 source4/smbd/wscript_build                         |    8 +-
 17 files changed, 61 insertions(+), 244 deletions(-)
 rename {source4/smbd => lib/util}/pidfile.c (80%)
 copy source4/scripting/python/modules.h => lib/util/pidfile.h (70%)
 delete mode 100644 source3/lib/pidfile.c


Changeset truncated at 500 lines:

diff --git a/source4/smbd/pidfile.c b/lib/util/pidfile.c
similarity index 80%
rename from source4/smbd/pidfile.c
rename to lib/util/pidfile.c
index 32d3964..8846371 100644
--- a/source4/smbd/pidfile.c
+++ b/lib/util/pidfile.c
@@ -21,7 +21,7 @@
 
 #include "includes.h"
 #include "system/filesys.h"
-#include "smbd/pidfile.h"
+#include "lib/util/pidfile.h"
 
 /**
  * @file
@@ -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/source4/scripting/python/modules.h b/lib/util/pidfile.h
similarity index 70%
copy from source4/scripting/python/modules.h
copy to lib/util/pidfile.h
index e7e97aa..d504f52 100644
--- a/source4/scripting/python/modules.h
+++ b/lib/util/pidfile.h
@@ -1,25 +1,27 @@
-/* 
+/*
    Unix SMB/CIFS implementation.
    Samba utility functions
-   Copyright (C) Jelmer Vernooij <jelmer at samba.org> 2007
-   
+   Copyright (C) Jeremy Allison 2012.
+
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
-   
+
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
-   
+
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#ifndef __SAMBA_PYTHON_MODULES_H__
-#define __SAMBA_PYTHON_MODULES_H__
+#ifndef _SAMBA_PIDFILE_H_
+#define _SAMBA_PIDFILE_H_
 
-bool py_update_path(void);
+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 /* __SAMBA_PYTHON_MODULES_H__ */ 
+#endif
diff --git a/lib/util/wscript_build b/lib/util/wscript_build
index 340cf12..ddaf90f 100755
--- a/lib/util/wscript_build
+++ b/lib/util/wscript_build
@@ -7,7 +7,7 @@ bld.SAMBA_LIBRARY('samba-util',
                     signal.c system.c params.c util.c util_id.c util_net.c
                     util_strlist.c util_paths.c idtree.c debug.c fault.c base64.c
                     util_str.c util_str_common.c substitute.c ms_fnmatch.c
-                    server_id.c dprintf.c parmlist.c bitmap.c''',
+                    server_id.c dprintf.c parmlist.c bitmap.c pidfile.c''',
                   deps='DYNCONFIG',
                   public_deps='talloc execinfo uid_wrapper pthread LIBCRYPTO charset util_setid',
                   public_headers='debug.h attr.h byteorder.h data_blob.h memory.h safe_string.h time.h talloc_stack.h xfile.h dlinklist.h samba_util.h string_wrappers.h',
diff --git a/source3/Makefile.in b/source3/Makefile.in
index dc3817f..4fc3efd 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -435,7 +435,7 @@ UTIL_OBJ = ../lib/util/rbtree.o ../lib/util/signal.o ../lib/util/time.o \
 		   ../lib/util/smb_threads.o ../lib/util/util_id.o \
 		   ../lib/util/blocking.o ../lib/util/rfc1738.o \
 		   ../lib/util/select.o ../lib/util/util_pw.o ../lib/util/server_id.o \
-		   ../lib/util/setid.o
+		   ../lib/util/setid.o ../lib/util/pidfile.o
 
 CRYPTO_OBJ = ../lib/crypto/crc32.o @CRYPTO_MD5_OBJ@ \
 			 ../lib/crypto/hmacmd5.o ../lib/crypto/arcfour.o \
@@ -460,7 +460,7 @@ LIB_OBJ = $(LIBSAMBAUTIL_OBJ) $(UTIL_OBJ) $(CRYPTO_OBJ) $(LIBTSOCKET_OBJ) \
 	  $(VERSION_OBJ) lib/charcnv.o ../lib/util/charset/convert_string.o \
 	  ../lib/util/charset/pull_push.o \
 	  lib/fstring.o ../lib/util/debug.o ../lib/util/debug_s3.o ../lib/util/fault.o \
-	  lib/interface.o lib/pidfile.o lib/dumpcore.o \
+	  lib/interface.o lib/dumpcore.o \
 	  lib/system.o lib/sendfile.o lib/recvfile.o lib/time.o \
 	  lib/username.o \
 	  ../libds/common/flag_mapping.o \
@@ -1864,13 +1864,6 @@ libsmb/libsmb_thread_posix.o: libsmb/libsmb_thread_posix.c
 		$(COMPILE_CC) $(PTHREAD_CFLAGS) >/dev/null 2>&1
 ### End section of object files that require PTHREAD_CFLAGS
 
-lib/pidfile.o: lib/pidfile.c
-	@echo Compiling $*.c
-	@$(COMPILE_CC_PATH) && exit 0;\
-		echo "The following command failed:" 1>&2;\
-		echo "$(COMPILE_CC_PATH)" 1>&2;\
-		$(COMPILE_CC_PATH) >/dev/null 2>&1
-
 lib/version.o: lib/version.c include/autoconf/version.h
 	@echo Compiling $*.c
 	@$(COMPILE_CC_PATH) && exit 0;\
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 4d99a60..585067e 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -158,12 +158,6 @@ char *escape_rdn_val_string_alloc(const char *s);
 int ms_fnmatch(const char *pattern, const char *string, bool translate_pattern,
 	       bool is_case_sensitive);
 
-/* The following definitions come from lib/pidfile.c  */
-
-pid_t pidfile_pid(const char *name);
-void pidfile_create(const char *program_name);
-void pidfile_unlink(void);
-
 /* The following definitions come from lib/recvfile.c  */
 
 ssize_t sys_recvfile(int fromfd,
diff --git a/source3/lib/pidfile.c b/source3/lib/pidfile.c
deleted file mode 100644
index 987ab06..0000000
--- a/source3/lib/pidfile.c
+++ /dev/null
@@ -1,191 +0,0 @@
-/* this code is broken - there is a race condition with the unlink (tridge) */
-
-/* 
-   Unix SMB/CIFS implementation.
-   pidfile handling
-   Copyright (C) Andrew Tridgell 1998
-   
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3 of the License, or
-   (at your option) any later version.
-   
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-   
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "includes.h"
-#include "system/filesys.h"
-
-#ifndef O_NONBLOCK
-#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 *program_name)
-{
-	int fd;
-	char pidstr[20];
-	pid_t pid = 0;
-	unsigned int ret;
-	char *name;
-	const char *short_configfile;
-	char * pidFile;
-
-	/* Add a suffix to the program name if this is a process with a
-	 * none default configuration file name. */
-	if (strcmp( CONFIGFILE, get_dyn_CONFIGFILE()) == 0) {
-		name = SMB_STRDUP(program_name);
-	} else {
-		short_configfile = strrchr( get_dyn_CONFIGFILE(), '/');
-		if (short_configfile == NULL) {
-			/* conf file in current directory */
-			short_configfile = get_dyn_CONFIGFILE();
-		} else {
-			/* full/relative path provided */
-			short_configfile++;
-		}
-		if (asprintf(&name, "%s-%s", program_name,
-				short_configfile) == -1) {
-			smb_panic("asprintf failed");
-		}
-	}
-
-	if (asprintf(&pidFile, "%s/%s.pid", lp_piddir(), name) == -1) {
-		SAFE_FREE(name);
-		return 0;
-	}
-
-	SAFE_FREE(name);
-
-	fd = open(pidFile, O_NONBLOCK | O_RDONLY, 0644);
-	if (fd == -1) {
-		SAFE_FREE(pidFile);
-		return 0;
-	}
-
-	ZERO_ARRAY(pidstr);
-
-	if (read(fd, pidstr, sizeof(pidstr)-1) <= 0) {
-		goto noproc;
-	}
-
-	ret = atoi(pidstr);
-
-	if (ret == 0) {
-		/* Obviously we had some garbage in the pidfile... */
-		DEBUG(1, ("Could not parse contents of pidfile %s\n",
-			  pidFile));
-		goto noproc;
-	}
-	
-	pid = (pid_t)ret;
-	if (!process_exists_by_pid(pid)) {
-		DEBUG(10, ("Process with PID=%d does not exist.\n", (int)pid));
-		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 no Samba process.\n",
-			  (int)pid));
-		goto noproc;
-	}
-
-	DEBUG(10, ("Process with PID=%d is running.\n", (int)pid));
-	SAFE_FREE(pidFile);
-	close(fd);
-	return (pid_t)ret;
-
- noproc:
-	close(fd);
-	DEBUG(10, ("Deleting %s, since %d is no Samba process.\n", pidFile,
-		  (int)pid));
-	unlink(pidFile);
-	SAFE_FREE(pidFile);
-	return 0;
-}
-
-/* create a pid file in the pid directory. open it and leave it locked */
-void pidfile_create(const char *program_name)
-{
-	int     fd;
-	char    buf[20];
-	const char    *short_configfile;
-	char *name;
-	pid_t pid;
-
-	/* Add a suffix to the program name if this is a process with a
-	 * none default configuration file name. */
-	if (strcmp( CONFIGFILE, get_dyn_CONFIGFILE()) == 0) {
-		name = SMB_STRDUP(program_name);
-	} else {
-		short_configfile = strrchr( get_dyn_CONFIGFILE(), '/');
-		if (short_configfile == NULL) {
-			/* conf file in current directory */
-			short_configfile = get_dyn_CONFIGFILE();
-		} else {
-			/* full/relative path provided */
-			short_configfile++;
-		}
-		if (asprintf(&name, "%s-%s", program_name,
-			     short_configfile) == -1) {
-			smb_panic("asprintf failed");
-		}
-	}
-
-	if (asprintf(&pidFile_name, "%s/%s.pid", lp_piddir(), name) == -1) {
-		smb_panic("asprintf failed");
-	}
-
-	pid = pidfile_pid(program_name);
-	if (pid != 0) {
-		DEBUG(0,("ERROR: %s is already running. File %s exists and process id %d is running.\n", 
-			 name, pidFile_name, (int)pid));
-		exit(1);
-	}
-
-	fd = 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_name,
-			 strerror(errno)));
-		exit(1);
-	}
-
-	if (fcntl_lock(fd,F_SETLK,0,1,F_WRLCK)==False) {
-		DEBUG(0,("ERROR: %s : fcntl lock of file %s failed. Error was %s\n",  
-			 name, pidFile_name, strerror(errno)));
-		exit(1);
-	}
-
-	memset(buf, 0, sizeof(buf));
-	slprintf(buf, sizeof(buf) - 1, "%u\n", (unsigned int)getpid());
-	if (write(fd, buf, strlen(buf)) != (ssize_t)strlen(buf)) {
-		DEBUG(0,("ERROR: can't write to file %s: %s\n", 
-			 pidFile_name, strerror(errno)));
-		exit(1);
-	}
-	/* Leave pid file open & locked for the duration... */
-	SAFE_FREE(name);
-
-	/* set the close on exec so that we don't leak the fd */
-	fcntl(fd, F_SETFD, FD_CLOEXEC);
-}
-
-void pidfile_unlink(void)
-{
-	if (pidFile_name == NULL) {
-		return;
-	}
-	unlink(pidFile_name);
-	SAFE_FREE(pidFile_name);
-}
diff --git a/source3/libsmb/clidgram.c b/source3/libsmb/clidgram.c
index 3772194..6e3ecb3 100644
--- a/source3/libsmb/clidgram.c
+++ b/source3/libsmb/clidgram.c
@@ -26,6 +26,7 @@
 #include "libsmb/nmblib.h"
 #include "messages.h"
 #include "librpc/gen_ndr/samr.h"
+#include "../lib/util/pidfile.h"
 
 /*
  * cli_send_mailslot, send a mailslot for client code ...
@@ -327,7 +328,7 @@ struct tevent_req *nbt_getdc_send(TALLOC_CTX *mem_ctx,
 	if (tevent_req_nomem(state->my_mailslot, req)) {
 		return tevent_req_post(req, ev);
 	}
-	state->nmbd_pid = pidfile_pid("nmbd");
+	state->nmbd_pid = pidfile_pid(lp_piddir(), "nmbd");
 	if (state->nmbd_pid == 0) {
 		DEBUG(3, ("No nmbd found\n"));
 		tevent_req_nterror(req, NT_STATUS_NOT_SUPPORTED);
diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c
index ebe83a6..a28ed7c 100644
--- a/source3/nmbd/nmbd.c
+++ b/source3/nmbd/nmbd.c
@@ -25,6 +25,7 @@
 #include "nmbd/nmbd.h"
 #include "serverid.h"
 #include "messages.h"
+#include "../lib/util/pidfile.h"
 
 int ClientNMB       = -1;
 int ClientDGRAM     = -1;
@@ -70,7 +71,7 @@ static void terminate(struct messaging_context *msg)
 	gencache_stabilize();
 	serverid_deregister(messaging_server_id(msg));
 
-	pidfile_unlink();
+	pidfile_unlink(lp_piddir(), "nmbd");
 
 	exit(0);
 }
@@ -942,7 +943,7 @@ static bool open_sockets(bool isdaemon, int port)
 		mkdir(lp_piddir(), 0755);
 	}
 
-	pidfile_create("nmbd");
+	pidfile_create(lp_piddir(), "nmbd");
 
 	status = reinit_after_fork(msg, nmbd_event_context(),
 				   false);
diff --git a/source3/smbd/server.c b/source3/smbd/server.c
index f7f1d8c..63edf00 100644
--- a/source3/smbd/server.c
+++ b/source3/smbd/server.c
@@ -43,6 +43,7 @@
 #include "lib/param/param.h"
 #include "lib/background.h"
 #include "lib/conn_tdb.h"
+#include "../lib/util/pidfile.h"
 
 struct smbd_open_socket;
 struct smbd_child_pid;
@@ -1285,7 +1286,7 @@ extern void build_options(bool screen);
 		mkdir(lp_piddir(), 0755);
 
 	if (is_daemon)
-		pidfile_create("smbd");
+		pidfile_create(lp_piddir(), "smbd");
 
 	status = reinit_after_fork(msg_ctx,
 				   ev_ctx,
diff --git a/source3/smbd/server_exit.c b/source3/smbd/server_exit.c
index 07b8432..517d4c2 100644
--- a/source3/smbd/server_exit.c
+++ b/source3/smbd/server_exit.c
@@ -44,6 +44,7 @@
 #include "printing.h"
 #include "serverid.h"
 #include "messages.h"
+#include "../lib/util/pidfile.h"
 
 static struct files_struct *log_writeable_file_fn(
 	struct files_struct *fsp, void *private_data)
@@ -216,7 +217,7 @@ static void exit_server_common(enum server_exit_reason how,
 		DEBUG(3,("Server exit (%s)\n",
 			(reason ? reason : "normal exit")));
 		if (am_parent) {
-			pidfile_unlink();
+			pidfile_unlink(lp_piddir(), "smbd");
 		}
 		gencache_stabilize();
 	}
diff --git a/source3/utils/smbcontrol.c b/source3/utils/smbcontrol.c
index 54e10d8..54c5d62 100644
--- a/source3/utils/smbcontrol.c
+++ b/source3/utils/smbcontrol.c
@@ -32,6 +32,7 @@
 #include "libsmb/nmblib.h"
 #include "messages.h"
 #include "util_tdb.h"
+#include "../lib/util/pidfile.h"
 
 #if HAVE_LIBUNWIND_H
 #include <libunwind.h>
@@ -1365,7 +1366,7 @@ static struct server_id parse_dest(struct messaging_context *msg,
 
 	/* Look up other destinations in pidfile directory */
 
-	if ((pid = pidfile_pid(dest)) != 0) {
+	if ((pid = pidfile_pid(lp_piddir(), dest)) != 0) {
 		return pid_to_procid(pid);
 	}
 
diff --git a/source3/web/startstop.c b/source3/web/startstop.c
index e23acf8..ec8f802 100644
--- a/source3/web/startstop.c
+++ b/source3/web/startstop.c
@@ -20,7 +20,7 @@
 #include "includes.h"
 #include "web/swat_proto.h"
 #include "dynconfig/dynconfig.h"
-
+#include "../lib/util/pidfile.h"


-- 
Samba Shared Repository


More information about the samba-cvs mailing list