mirror of
https://github.com/linux-msm/cdba.git
synced 2026-02-25 13:11:56 -08:00
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 <dmitry.baryshkov@linaro.org>
This commit is contained in:
20
device.c
20
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;
|
||||
|
||||
warnx("board is in use, waiting...");
|
||||
n = flock(fd, LOCK_EX | LOCK_NB);
|
||||
if (!n)
|
||||
return;
|
||||
|
||||
n = flock(fd, LOCK_EX);
|
||||
if (n < 0)
|
||||
err(1, "failed to lock lockfile %s", lock);
|
||||
warnx("board is in use, waiting...");
|
||||
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user