diff --git a/cdba-server.c b/cdba-server.c index 2b16661..c463f19 100644 --- a/cdba-server.c +++ b/cdba-server.c @@ -201,6 +201,11 @@ static void sigpipe_handler(int signo) watch_quit(); } +static void atexit_handler(void) +{ + syslog(LOG_INFO, "exiting"); +} + int main(int argc, char **argv) { int flags; @@ -216,7 +221,8 @@ int main(int argc, char **argv) if (!username) username = "nobody"; - openlog("cdba-server", 0, LOG_DAEMON); + openlog("cdba-server", LOG_PID, LOG_DAEMON); + atexit(atexit_handler); ret = device_parser(".cdba"); if (ret) { diff --git a/device.c b/device.c index 848f552..79856bb 100644 --- a/device.c +++ b/device.c @@ -64,15 +64,21 @@ static void device_lock(struct device *device) if (fd < 0) err(1, "failed to open lockfile %s", lock); - n = flock(fd, LOCK_EX | LOCK_NB); - if (!n) - return; + while (1) { + char c; + + n = flock(fd, LOCK_EX | LOCK_NB); + if (!n) + return; - warnx("board is in use, waiting..."); + warnx("board is in use, waiting..."); - n = flock(fd, LOCK_EX); - if (n < 0) - err(1, "failed to lock lockfile %s", lock); + sleep(3); + + /* check that connection isn't gone */ + if (read(STDIN_FILENO, &c, 1) == 0) + errx(1, "connection is gone"); + } } static bool device_check_access(struct device *device,