device: Hack around EPERM issue

Opening the lock files fails on one of my boards if the files exists and
are owned by someone else, if O_CREAT is set. This doesn't make sense,
but hack around it for now by first creating the file if it's not there,
ignoring any errors and then just opening it O_RDONLY.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
This commit is contained in:
Bjorn Andersson
2021-10-05 10:41:48 -07:00
parent af03ecd94f
commit 6fbc50ca58

View File

@@ -64,7 +64,11 @@ static void device_lock(struct device *device)
if (n >= sizeof(lock))
errx(1, "failed to build lockfile path");
fd = open(lock, O_RDONLY | O_CREAT | O_CLOEXEC, 0666);
fd = open(lock, O_RDONLY | O_CREAT, 0666);
if (fd >= 0)
close(fd);
fd = open(lock, O_RDONLY | O_CLOEXEC);
if (fd < 0)
err(1, "failed to open lockfile %s", lock);