Skip to content

Commit 6113960

Browse files
authored
Merge pull request #76 from lumag/lock-who
Fix quitting if the board is locked
2 parents 02210fe + cbad92a commit 6113960

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

cdba-server.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@ static void sigpipe_handler(int signo)
201201
watch_quit();
202202
}
203203

204+
static void atexit_handler(void)
205+
{
206+
syslog(LOG_INFO, "exiting");
207+
}
208+
204209
int main(int argc, char **argv)
205210
{
206211
int flags;
@@ -216,7 +221,8 @@ int main(int argc, char **argv)
216221
if (!username)
217222
username = "nobody";
218223

219-
openlog("cdba-server", 0, LOG_DAEMON);
224+
openlog("cdba-server", LOG_PID, LOG_DAEMON);
225+
atexit(atexit_handler);
220226

221227
ret = device_parser(".cdba");
222228
if (ret) {

device.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,21 @@ static void device_lock(struct device *device)
6464
if (fd < 0)
6565
err(1, "failed to open lockfile %s", lock);
6666

67-
n = flock(fd, LOCK_EX | LOCK_NB);
68-
if (!n)
69-
return;
67+
while (1) {
68+
char c;
69+
70+
n = flock(fd, LOCK_EX | LOCK_NB);
71+
if (!n)
72+
return;
7073

71-
warnx("board is in use, waiting...");
74+
warnx("board is in use, waiting...");
7275

73-
n = flock(fd, LOCK_EX);
74-
if (n < 0)
75-
err(1, "failed to lock lockfile %s", lock);
76+
sleep(3);
77+
78+
/* check that connection isn't gone */
79+
if (read(STDIN_FILENO, &c, 1) == 0)
80+
errx(1, "connection is gone");
81+
}
7682
}
7783

7884
static bool device_check_access(struct device *device,

0 commit comments

Comments
 (0)