Skip to content

Commit

Permalink
Merge pull request #76 from lumag/lock-who
Browse files Browse the repository at this point in the history
Fix quitting if the board is locked
  • Loading branch information
konradybcio authored May 31, 2024
2 parents 02210fe + cbad92a commit 6113960
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
8 changes: 7 additions & 1 deletion cdba-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
20 changes: 13 additions & 7 deletions device.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 6113960

Please sign in to comment.