Skip to content

Commit 9c8f476

Browse files
committed
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 <[email protected]>
1 parent 52a9dd5 commit 9c8f476

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

libcontainer/nsenter/nsexec.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -637,12 +637,14 @@ void join_namespaces(char *nsspec)
637637
__close_namespaces(to_join, joined, ns_list, ns_len);
638638
}
639639

640-
static inline int sane_kill(pid_t pid, int signum)
640+
static inline void sane_kill(pid_t pid, int signum)
641641
{
642-
if (pid > 0)
643-
return kill(pid, signum);
644-
else
645-
return 0;
642+
if (pid <= 0)
643+
return;
644+
645+
int saved_errno = errno;
646+
kill(pid, signum);
647+
errno = saved_errno;
646648
}
647649

648650
void try_unshare(int flags, const char *msg)

0 commit comments

Comments
 (0)