diff -ru samba-2.2.8a.orig/source/lib/pidfile.c samba-2.2.8a/source/lib/pidfile.c --- samba-2.2.8a.orig/source/lib/pidfile.c Fri Mar 14 13:34:47 2003 +++ samba-2.2.8a/source/lib/pidfile.c Wed Apr 9 15:31:52 2003 @@ -30,14 +30,11 @@ /* return the pid in a pidfile. return 0 if the process (or pidfile) does not exist */ -pid_t pidfile_pid(const char *name) +static pid_t _pidfile_pid(pstring pidFile) { int fd; char pidstr[20]; unsigned ret; - pstring pidFile; - - slprintf(pidFile, sizeof(pidFile)-1, "%s/%s.pid", lp_piddir(), name); fd = sys_open(pidFile, O_NONBLOCK | O_RDONLY, 0644); if (fd == -1) { @@ -70,20 +67,28 @@ return 0; } -/* create a pid file in the pid directory. open it and leave it locked */ -void pidfile_create(const char *name) +/* return the pid in a pidfile in the lock directory. return 0 if the process + (or pidfile) does not exist */ +pid_t pidfile_pid(const char *name) { - int fd; - char buf[20]; pstring pidFile; - pid_t pid; slprintf(pidFile, sizeof(pidFile)-1, "%s/%s.pid", lp_piddir(), name); - pid = pidfile_pid(name); + return _pidfile_pid(pidFile); +} + +/* create a pid file that can be anywhere. open it and leave it locked */ +void _pidfile_create(pstring pidFile) +{ + int fd; + char buf[20]; + pid_t pid; + + pid = _pidfile_pid(pidFile); if (pid != 0) { - DEBUG(0,("ERROR: %s is already running. File %s exists and process id %d is running.\n", - name, pidFile, (int)pid)); + DEBUG(0,("ERROR: Already running. File %s exists and process id %d is running.\n", + pidFile, (int)pid)); exit(1); } @@ -95,8 +100,8 @@ } 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))); + DEBUG(0,("ERROR: fcntl lock of file %s failed. Error was %s\n", + pidFile, strerror(errno))); exit(1); } @@ -108,4 +113,14 @@ exit(1); } /* Leave pid file open & locked for the duration... */ +} + +/* create a pid file in the lock directory. open it and leave it locked */ +void pidfile_create(const char *name) +{ + pstring pidFile; + + slprintf(pidFile, sizeof(pidFile)-1, "%s/%s.pid", lp_lockdir(), name); + + return _pidfile_create(pidFile); } Only in samba-2.2.8a/source/lib: pidfile.c.orig diff -ru samba-2.2.8a.orig/source/nmbd/nmbd.c samba-2.2.8a/source/nmbd/nmbd.c --- samba-2.2.8a.orig/source/nmbd/nmbd.c Fri Mar 14 13:34:48 2003 +++ samba-2.2.8a/source/nmbd/nmbd.c Wed Apr 9 15:14:02 2003 @@ -647,6 +647,7 @@ printf( "Usage: %s [-DaiohV] [-H lmhosts file] [-d debuglevel] [-l log basename]\n", pname ); printf( " [-n name] [-p port] [-s configuration file]\n" ); printf( "\t-D Become a daemon (default)\n" ); + printf( "\t-f pidfile Use a specific pidfile\n" ); printf( "\t-a Append to log file (default)\n" ); printf( "\t-i Run interactive (not a daemon)\n" ); printf( "\t-o Overwrite log file, don't append\n" ); @@ -675,7 +676,9 @@ extern BOOL AllowDebugChange; BOOL opt_interactive = False; pstring logfile; + char const *pidfile; + pidfile = NULL; append_log = True; /* Default, override with '-o' option. */ global_nmb_port = NMB_PORT; @@ -763,6 +766,9 @@ case 'D': is_daemon = True; break; + case 'f': + pidfile = optarg; + break; case 'd': DEBUGLEVEL = atoi(optarg); AllowDebugChange = False; @@ -855,7 +861,11 @@ mkdir(lp_lockdir(), 0755); } - pidfile_create("nmbd"); + if (pidfile) { + _pidfile_create(pidfile); + } else { + pidfile_create("nmbd"); + } message_init(); message_register(MSG_FORCE_ELECTION, nmbd_message_election); Only in samba-2.2.8a/source/nmbd: nmbd.c.orig diff -ru samba-2.2.8a.orig/source/smbd/server.c samba-2.2.8a/source/smbd/server.c --- samba-2.2.8a.orig/source/smbd/server.c Fri Mar 14 13:34:49 2003 +++ samba-2.2.8a/source/smbd/server.c Wed Apr 9 15:14:02 2003 @@ -619,6 +619,7 @@ printf("Usage: %s [-DaioPh?V] [-d debuglevel] [-l log basename] [-p port]\n", pname); printf(" [-O socket options] [-s services file]\n"); printf("\t-D Become a daemon (default)\n"); + printf("\t-f pidfile Use a specific pidfile\n" ); printf("\t-a Append to log file (default)\n"); printf("\t-i Run interactive (not a daemon)\n"); printf("\t-o Overwrite log file, don't append\n"); @@ -643,12 +644,14 @@ extern BOOL AllowDebugChange; /* shall I run as a daemon */ BOOL is_daemon = False; + char const *pidfile; BOOL interactive = False; BOOL specified_logfile = False; int port = SMB_PORT; int opt; extern char *optarg; pstring logfile; + pidfile = NULL; #ifdef HAVE_SET_AUTH_PARAMETERS set_auth_parameters(argc,argv); @@ -692,6 +695,10 @@ interactive = True; break; + case 'f': + pidfile = optarg; + break; + case 'd': if (*optarg == 'A') DEBUGLEVEL = 10000; @@ -859,8 +866,13 @@ if (!directory_exist(lp_lockdir(), NULL)) mkdir(lp_lockdir(), 0755); - if (is_daemon) - pidfile_create("smbd"); + if (is_daemon) { + if (pidfile) { + _pidfile_create(pidfile); + } else { + pidfile_create("smbd"); + } + } if (!message_init()) exit(1); Only in samba-2.2.8a/source/smbd: server.c.orig