]> arthur.barton.de Git - netatalk.git/commitdiff
Previous fix 9e4e07c1811edbaf3376ad6e238a1353b405002b resulted in the inability to...
authorFrank Lahm <franklahm@googlemail.com>
Sun, 28 Aug 2011 10:40:56 +0000 (12:40 +0200)
committerFrank Lahm <franklahm@googlemail.com>
Wed, 31 Aug 2011 06:10:53 +0000 (08:10 +0200)
etc/afpd/main.c
etc/cnid_dbd/cnid_metad.c
include/atalk/util.h
libatalk/util/server_lock.c

index c27755655db75a551aec0505ca20975e5ed1eb06..e8365a2848770efd0366e0e78d78e77e0ab403cc 100644 (file)
@@ -263,15 +263,14 @@ int main(int ac, char **av)
     if (!afp_options_parse(ac, av, &default_options))
         exit(EXITERR_CONF);
 
+    if (check_lockfile("afpd", default_options.pidfile) != 0)
+        exit(EXITERR_SYS);
+
     if (!(default_options.flags & OPTION_DEBUG) && (daemonize(0, 0) != 0))
         exit(EXITERR_SYS);
 
-    switch(check_lockfile("afpd", default_options.pidfile)) {
-    case 0:
-        break;
-    default:
+    if (create_lockfile("afpd", default_options.pidfile) != 0)
         exit(EXITERR_SYS);
-    }
 
     /* Log SIGBUS/SIGSEGV SBT */
     fault_setup(NULL);
index ad9727daab226d6dbb9b4bd5f789aacb9e301e94..5b2f76760825e3700aa039d81f1ee17418c0d488 100644 (file)
@@ -490,16 +490,16 @@ int main(int argc, char *argv[])
         }
     }
 
+    /* Check for PID lockfile */
+    if (check_lockfile("cnid_metad", _PATH_CNID_METAD_LOCK))
+        return -1;
+
     if (!debug && daemonize(0, 0) != 0)
         exit(EXITERR_SYS);
 
-    /* Check PID lockfile and become a daemon */
-    switch(check_lockfile("cnid_metad", _PATH_CNID_METAD_LOCK)) {
-    case 0:
-        break;
-    default:
-        exit(EXITERR_SYS);
-    }
+    /* Create PID lockfile */
+    if (create_lockfile("cnid_metad", _PATH_CNID_METAD_LOCK))
+        return -1;
 
     if (loglevel) {
         strlcpy(logconfig + 8, loglevel, 13);
index df7cfcc20b59221ba6664190dbaa66407ab6f35c..bcf7e70816b461d0869b0646ad16011eb82719c7 100644 (file)
@@ -74,6 +74,7 @@ extern int strdiacasecmp  (const char *, const char *);
 extern int strndiacasecmp (const char *, const char *, size_t);
 extern pid_t server_lock  (char * /*program*/, char * /*file*/, int /*debug*/);
 extern int check_lockfile (const char *program, const char *pidfile);
+extern int create_lockfile(const char *program, const char *pidfile);
 extern void fault_setup          (void (*fn)(void *));
 extern void netatalk_panic(const char *why);
 #define server_unlock(x)  (unlink(x))
index 68c7355645c5596bf3520a04d14f52126de28a62..eaa0c9a7b2c43d4034d4d9f99aaa075618f3c1cf 100644 (file)
@@ -98,15 +98,14 @@ pid_t server_lock(char *program, char *pidfile, int debug)
 }
 
 /*!
- * 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 +116,21 @@ 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)
+{
+    char buf[10];
+    FILE *pf;
+    pid_t pid;
+    int mask;
+  
+    if (check_lockfile(program, pidfile) != 0)
+        return -1;
 
     /* Write PID to pidfile */
     mask = umask(022);