* Now including pidfile.h
* using check_pid() function to check for a running fspd * writing our pid with write_pid() to the file named in pidlogname * deleting the pidfile when existing with remove_pid()
This commit is contained in:
parent
284f67382a
commit
e01da77bdd
|
|
@ -13,6 +13,7 @@
|
||||||
#include "s_extern.h"
|
#include "s_extern.h"
|
||||||
#include "co_extern.h"
|
#include "co_extern.h"
|
||||||
#include "my-string.h"
|
#include "my-string.h"
|
||||||
|
#include "pidfile.h"
|
||||||
|
|
||||||
#define NULL_DEV "/dev/null"
|
#define NULL_DEV "/dev/null"
|
||||||
|
|
||||||
|
|
@ -268,10 +269,24 @@ int main PROTO2(int, argc, char **, argv)
|
||||||
/* Fork and die to drop daemon into background */
|
/* Fork and die to drop daemon into background */
|
||||||
/* Added Alban E J Fellows 12 Jan 93 */
|
/* Added Alban E J Fellows 12 Jan 93 */
|
||||||
/* Moved by JT Traub to only do this if not running under inetd. */
|
/* Moved by JT Traub to only do this if not running under inetd. */
|
||||||
|
|
||||||
|
/* check the pidlog before we fork */
|
||||||
|
if (!check_pid(pidlogname)) {
|
||||||
|
/* pidfile empty, not existing or prozess already dead */
|
||||||
|
} else {
|
||||||
|
exit(1); /* fspd already running */
|
||||||
|
}
|
||||||
|
|
||||||
if(daemonize) {
|
if(daemonize) {
|
||||||
#if HAVE_FORK
|
#if HAVE_FORK
|
||||||
if (fork() > 0)
|
pid_t forkpid;
|
||||||
|
forkpid = fork();
|
||||||
|
if (forkpid == 0) { /* child prozess */
|
||||||
|
if (!write_pid(pidlogname))
|
||||||
|
exit(1);/* cannot write pid file - exit */
|
||||||
|
} else if (forkpid > 0) { /* father prozess */
|
||||||
_exit(0);
|
_exit(0);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#if HAVE_SETSID
|
#if HAVE_SETSID
|
||||||
setsid();
|
setsid();
|
||||||
|
|
@ -285,6 +300,7 @@ int main PROTO2(int, argc, char **, argv)
|
||||||
if(inetd_mode||dbug||shutdowning) break;
|
if(inetd_mode||dbug||shutdowning) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(void) remove_pid(pidlogname);
|
||||||
shutdown_caches();
|
shutdown_caches();
|
||||||
destroy_configuration();
|
destroy_configuration();
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user