libct/nsenter: save errno in sane_kill

Since sane_kill after a failed read or write, but before reporting the
error from that read or write, it may change the errno value in case
kill(2) fails.

Save and restore the errno around the call to kill.

While at it,
 - change the code to return early;
 - don't return kill return value as no one is using it, and the errno
   value no longer correlates.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2025-10-11 17:36:54 -07:00
parent 52a9dd563d
commit 9c8f476cb6
+7 -5
View File
@@ -637,12 +637,14 @@ void join_namespaces(char *nsspec)
__close_namespaces(to_join, joined, ns_list, ns_len);
}
static inline int sane_kill(pid_t pid, int signum)
static inline void sane_kill(pid_t pid, int signum)
{
if (pid > 0)
return kill(pid, signum);
else
return 0;
if (pid <= 0)
return;
int saved_errno = errno;
kill(pid, signum);
errno = saved_errno;
}
void try_unshare(int flags, const char *msg)