static int do_site(void) { int fd; int rv = -1; if (!cl.debug) { if (daemon(0, 0) < 0) { perror("daemon error"); exit(EXIT_FAILURE); } } setup_logging(); fd = lockfile(); if (fd < 0) return fd; log_info("BOOTH cluster site daemon started"); set_scheduler(); set_oom_adj(-16); rv = loop(SITE); if (rv < 0) goto fail; unlink_lockfile(fd); close_logging(); return 0; fail: return -1; }
static void server_exit(void) { int rv; if (lock_fd >= 0) { /* We might not be able to delete it, but at least * make it empty. */ rv = ftruncate(lock_fd, 0); (void)rv; unlink_lockfile(lock_fd); } log_info("exiting"); }
static int do_server(int type) { int fd = -1; int rv = -1; rv = setup(type); if (rv < 0) goto out; if (!daemonize) { if (daemon(0, 0) < 0) { perror("daemon error"); exit(EXIT_FAILURE); } } /* The lock cannot be obtained before the call to daemon(), otherwise the lockfile would contain the pid of the parent, not the daemon. */ fd = lockfile(); if (fd < 0) return fd; if (type == ARBITRATOR) log_info("BOOTH arbitrator daemon started"); else if (type == SITE) log_info("BOOTH cluster site daemon started"); set_scheduler(); set_oom_adj(-16); rv = loop(); out: if (fd >= 0) unlink_lockfile(fd); return rv; }