eis: handle a lock file open failure correctly

Assisted-by: Claude:claude-opus-4-6
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/388>
This commit is contained in:
Peter Hutterer 2026-05-11 13:43:50 +10:00 committed by Marge Bot
parent c352f16b4a
commit dc5bd1396f

View file

@ -147,11 +147,15 @@ eis_setup_backend_socket(struct eis *eis, const char *socketpath)
* socket file. */
_cleanup_free_ char *lockfile = xaprintf("%s.lock", path);
_cleanup_close_ int lockfd =
open(lockfile, O_CREAT | O_CLOEXEC | O_RDWR, S_IRUSR | S_IWUSR);
int rc = flock(lockfd, LOCK_EX | LOCK_NB);
xerrno(open(lockfile, O_CREAT | O_CLOEXEC | O_RDWR, S_IRUSR | S_IWUSR));
int rc;
if (lockfd >= 0)
rc = xerrno(flock(lockfd, LOCK_EX | LOCK_NB));
else
rc = lockfd;
if (rc < 0) {
log_error(eis, "Failed to create lockfile %s, is another EIS running?", lockfile);
return -errno;
return -rc;
}
struct stat st;