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);
}
}
+ /* 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);
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))
}
/*!
- * 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)) {
}
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);