Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix quitting if the board is locked #76

Merged
merged 3 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading