From 6fbc50ca58772d5ad1c6622dec646c74bc39e471 Mon Sep 17 00:00:00 2001 From: Bjorn Andersson Date: Tue, 5 Oct 2021 10:41:48 -0700 Subject: [PATCH] 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 --- device.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/device.c b/device.c index 42115d8..e323c6f 100644 --- a/device.c +++ b/device.c @@ -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);