]> arthur.barton.de Git - netatalk.git/blobdiff - libatalk/util/server_lock.c
Merge remote-tracking branch 'origin/branch-netatalk-3-1'
[netatalk.git] / libatalk / util / server_lock.c
index 68c7355645c5596bf3520a04d14f52126de28a62..6ae817e5547c701891ee7e2d6dcfd554283b9870 100644 (file)
@@ -37,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"))) {
@@ -60,7 +61,7 @@ pid_t server_lock(char *program, char *pidfile, int debug)
   /*
    * Disassociate from controlling tty.
    */
-  if ( !debug ) {
+
     int                i;
 
     getitimer(ITIMER_PROF, &itimer);
@@ -90,23 +91,23 @@ pid_t server_lock(char *program, char *pidfile, int debug)
       fclose(pf);
       return pid;
     }
-  } 
 
   fprintf(pf, "%d\n", getpid());
   fclose(pf);
+  } 
+
   return 0;
 }
 
 /*!
- * Check and write lockfile
+ * Check lockfile
  */
 int check_lockfile(const char *program, const char *pidfile)
 {
     char buf[10];
     FILE *pf;
     pid_t pid;
-    int mask;
-  
+
     /* check for pid. this can get fooled by stale pid's. */
     if ((pf = fopen(pidfile, "r"))) {
         if (fgets(buf, sizeof(buf), pf) && !kill(pid = atol(buf), 0)) {
@@ -117,6 +118,19 @@ int check_lockfile(const char *program, const char *pidfile)
         }
         fclose(pf);
     }
+    return 0;
+}
+
+/*!
+ * Check and create lockfile
+ */
+int create_lockfile(const char *program, const char *pidfile)
+{
+    FILE *pf;
+    int mask;
+  
+    if (check_lockfile(program, pidfile) != 0)
+        return -1;
 
     /* Write PID to pidfile */
     mask = umask(022);