From 04b77312db0c7977311d2438bf19604e10cf464d Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Thu, 11 May 2023 18:22:06 -0600 Subject: Work around a macOS a kernel bug where tcsetpgrp() does not restart. I reported this bug to Apple over 12 years ago. --- plugins/sudoers/visudo.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugins/sudoers/visudo.c b/plugins/sudoers/visudo.c index 2f6289e28..a2f39b8c8 100644 --- a/plugins/sudoers/visudo.c +++ b/plugins/sudoers/visudo.c @@ -983,12 +983,19 @@ run_command(const char *path, char *const *argv) * (suspending visudo itself if running in the background). */ if (ttyfd != -1) { + retry: if (tcsetpgrp(ttyfd, pid) == 0) { sudo_debug_printf(SUDO_DEBUG_DIAG, "%s: %d: continuing", __func__, (int)pid); killpg(pid, SIGCONT); break; } else { + /* + * macOS suffers from a kernel bug where tcsetpgrp() + * is not restarted so we have to do it manually. + */ + if (errno == EINTR && tcgetpgrp(ttyfd) == visudo_pgrp) + goto retry; sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO, "%s: unable to set foreground pgrp to %d (visudo)", __func__, (int)visudo_pgrp); -- cgit v1.2.1