Skip to content

Commit 5db3df3

Browse files
committed
device: loop around flock/warn
Loop around the flock(), sleeping in the middle. This allows CDBA to break early if user closes the terminal (by killing SSH or by Ctrl-A-Q sequence). Signed-off-by: Dmitry Baryshkov <[email protected]>
1 parent 02210fe commit 5db3df3

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

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)