]> arthur.barton.de Git - netatalk.git/blobdiff - libatalk/util/server_lock.c
Dont clobber env FLAGS
[netatalk.git] / libatalk / util / server_lock.c
index 8d023e7033aff244c5c9473e82eb8cf81a8edd2c..90dc11445eabc56cba7121d7888e15186ab3a30a 100644 (file)
 #include <sys/stat.h>
 #include <errno.h>
 
+#include <sys/time.h>
+
 #include <atalk/compat.h>
 #include <atalk/util.h>
 
+static struct itimerval itimer;
+
 /* this creates an open lock file which hangs around until the program
  * dies. it returns the pid. due to problems w/ solaris, this has
  * been changed to do the kill() thing. */
@@ -33,7 +37,8 @@ pid_t server_lock(char *program, char *pidfile, int debug)
   FILE *pf;
   pid_t pid;
   int mask;
-  
+
+  if ( !debug ) {
   mask = umask(022);
   /* check for pid. this can get fooled by stale pid's. */
   if ((pf = fopen(pidfile, "r"))) {
@@ -56,14 +61,19 @@ pid_t server_lock(char *program, char *pidfile, int debug)
   /*
    * Disassociate from controlling tty.
    */
-  if ( !debug ) {
+
     int                i;
 
+    getitimer(ITIMER_PROF, &itimer);
     switch (pid = fork()) {
     case 0 :
+      setitimer(ITIMER_PROF, &itimer, NULL);
       fclose(stdin);
       fclose(stdout);
       fclose(stderr);
+      i = open( "/dev/null", O_RDWR );
+      i = open( "/dev/null", O_RDWR );
+      i = open( "/dev/null", O_RDWR );
 
 #ifdef TIOCNOTTY
       if (( i = open( "/dev/tty", O_RDWR )) >= 0 ) {
@@ -81,9 +91,11 @@ pid_t server_lock(char *program, char *pidfile, int debug)
       fclose(pf);
       return pid;
     }
-  } 
 
   fprintf(pf, "%d\n", getpid());
   fclose(pf);
+  } 
+
   return 0;
 }
+