Skip to content

Commit

Permalink
preload: Restore errno in ioctl_emulate_open()
Browse files Browse the repository at this point in the history
Don't clobber errno with the failures of checking for the emulation
socket.
  • Loading branch information
martinpitt committed Jan 2, 2025
1 parent f2f15a5 commit d65aa70
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/libumockdev-preload.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,13 +528,15 @@ ioctl_emulate_open(int fd, const char *dev_path, int must_exist)
is_default = 1;
}

int orig_errno = errno;
sock = _socket(AF_UNIX, SOCK_STREAM, 0);
if (sock == -1) {
if (must_exist) {
fprintf(stderr, "ERROR: libumockdev-preload: Failed to open ioctl socket for %s",
dev_path);
exit(1);
} else {
errno = orig_errno;
return;
}
}
Expand All @@ -546,6 +548,7 @@ ioctl_emulate_open(int fd, const char *dev_path, int must_exist)
dev_path);
exit(1);
} else {
errno = orig_errno;
return;
}
}
Expand All @@ -558,6 +561,7 @@ ioctl_emulate_open(int fd, const char *dev_path, int must_exist)

fd_map_add(&ioctl_wrapped_fds, fd, fdinfo);
DBG(DBG_IOCTL, "ioctl_emulate_open fd %i (%s): connected ioctl sockert\n", fd, dev_path);
errno = orig_errno;
}

static void
Expand Down

0 comments on commit d65aa70

Please sign in to comment.