From: Junio C Hamano <gitster@pobox.com>
To: "Carlo Marcelo Arenas Belón via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org,
"Carlo Marcelo Arenas Belón" <carenas@gmail.com>,
"Chris Torek" <chris.torek@gmail.com>
Subject: Re: [PATCH v2 2/3] daemon: use sigaction() to install child_handler()
Date: Wed, 25 Jun 2025 09:22:58 -0700 [thread overview]
Message-ID: <xmqqsejnx02l.fsf@gitster.g> (raw)
In-Reply-To: <xmqqfrfnyff1.fsf@gitster.g> (Junio C. Hamano's message of "Wed, 25 Jun 2025 09:06:10 -0700")
Junio C Hamano <gitster@pobox.com> writes:
> Does this #ifndef block with #else lack its #endif probably before
> the service_loop() is defined ...
> ...
> ... around here?
>
> I am wondering if it would make it even cleaner to also define
> rearm_signal_handler() in this "if sigaction() can be used, do this,
> otherwise do that" block, and move the whole thing a bit earlier in
> this file. That way, the primary code paths do not have to see much
> of the #ifdef conditionals. With IPV6 related #ifdef noise already
> contaminating the file, it may not be a huge deal, but these crufts
> tend to build up unless we tightly control them with discipline.
Applying this on top of your series would illustrate what I meant.
I didn't spend enough braincycles on the naming issues for the
conditional compilation so I left it as USE_NON_POSIX_SIGNAL even
though I know it has to be fixed before we move forward.
Thanks.
daemon.c | 81 +++++++++++++++++++++++++++++++++-------------------------------
1 file changed, 42 insertions(+), 39 deletions(-)
diff --git c/daemon.c w/daemon.c
index 01337fcfed..8a371518b8 100644
--- c/daemon.c
+++ w/daemon.c
@@ -912,19 +912,54 @@ static void handle(int incoming, struct sockaddr *addr, socklen_t addrlen)
add_child(&cld, addr, addrlen);
}
-static void child_handler(int signo MAYBE_UNUSED)
+#ifndef USE_NON_POSIX_SIGNAL
+
+static void set_signal_handler(struct sigaction *psa, void (*child_handler)(int))
+{
+ sigemptyset(&psa->sa_mask);
+ psa->sa_flags = SA_NOCLDSTOP | SA_RESTART;
+ psa->sa_handler = child_handler;
+ sigaction(SIGCHLD, psa, NULL);
+}
+
+static void rearm_signal_handler(int signo UNUSED, void (*child_handler)(int) UNUSED)
+{
+}
+
+static void set_sa_restart(struct sigaction *psa, int enable)
+{
+ if (enable)
+ psa->sa_flags |= SA_RESTART;
+ else
+ psa->sa_flags &= ~SA_RESTART;
+ sigaction(SIGCHLD, psa, NULL);
+}
+
+#else
+
+static void set_signal_handler(struct sigaction *psa UNUSED, void (*child_handler)(int))
+{
+ signal(SIGCHLD, child_handler);
+}
+
+static void rearm_signal_handler(int signo, void (*child_handler)(int))
{
- /*
- * Otherwise empty handler because systemcalls should get interrupted
- * upon signal receipt.
- */
-#ifdef USE_NON_POSIX_SIGNAL
/*
* SysV needs the handler to be rearmed, but this is known
* to trigger infinite recursion crashes at least in AIX.
*/
signal(signo, child_handler);
+}
+
+static void set_sa_restart(struct sigaction *psa UNUSED, int enable UNUSED)
+{
+}
+
#endif
+
+static void child_handler(int signo)
+{
+ rearm_signal_handler(signo, child_handler);
}
static int set_reuse_addr(int sockfd)
@@ -1123,38 +1158,6 @@ static void socksetup(struct string_list *listen_addr, int listen_port, struct s
}
}
-#ifndef USE_NON_POSIX_SIGNAL
-
-static void set_signal_handler(struct sigaction *psa)
-{
- sigemptyset(&psa->sa_mask);
- psa->sa_flags = SA_NOCLDSTOP | SA_RESTART;
- psa->sa_handler = child_handler;
- sigaction(SIGCHLD, psa, NULL);
-}
-
-static void set_sa_restart(struct sigaction *psa, int enable)
-{
- if (enable)
- psa->sa_flags |= SA_RESTART;
- else
- psa->sa_flags &= ~SA_RESTART;
- sigaction(SIGCHLD, psa, NULL);
-}
-
-#else
-
-static void set_signal_handler(struct sigaction *psa UNUSED)
-{
- signal(SIGCHLD, child_handler);
-}
-
-static void set_sa_restart(struct sigaction *psa UNUSED, int enable UNUSED)
-{
-}
-
-#endif
-
static int service_loop(struct socketlist *socklist)
{
struct sigaction sa;
@@ -1167,7 +1170,7 @@ static int service_loop(struct socketlist *socklist)
pfd[i].events = POLLIN;
}
- set_signal_handler(&sa);
+ set_signal_handler(&sa, child_handler);
for (;;) {
check_dead_children();
next prev parent reply other threads:[~2025-06-25 16:23 UTC|newest]
Thread overview: 70+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-24 14:08 [PATCH 0/3] daemon: explicitly allow EINTR during poll() Carlo Marcelo Arenas Belón via GitGitGadget
2025-06-24 14:08 ` [PATCH 1/3] compat/posix.h: track SA_RESTART fallback Carlo Marcelo Arenas Belón via GitGitGadget
2025-06-24 15:34 ` Junio C Hamano
2025-06-24 16:28 ` Junio C Hamano
2025-06-24 14:08 ` [PATCH 2/3] daemon: use sigaction() to install child_handler() Carlo Marcelo Arenas Belón via GitGitGadget
2025-06-24 15:37 ` Junio C Hamano
2025-06-24 22:29 ` Carlo Marcelo Arenas Belón
2025-06-24 23:27 ` Chris Torek
2025-06-24 16:20 ` Junio C Hamano
2025-06-24 21:28 ` Carlo Marcelo Arenas Belón
2025-06-24 21:32 ` Junio C Hamano
2025-06-24 14:08 ` [PATCH 3/3] daemon: explicitly allow EINTR during poll() Carlo Marcelo Arenas Belón via GitGitGadget
2025-06-24 14:33 ` Carlo Marcelo Arenas Belón
2025-06-24 15:43 ` Junio C Hamano
2025-06-25 7:35 ` [PATCH v2 0/3] " Carlo Marcelo Arenas Belón via GitGitGadget
2025-06-25 7:35 ` [PATCH v2 1/3] compat/posix.h: track SA_RESTART fallback Carlo Marcelo Arenas Belón via GitGitGadget
2025-06-25 16:07 ` Junio C Hamano
2025-06-25 22:24 ` Carlo Marcelo Arenas Belón
2025-06-26 0:33 ` Junio C Hamano
2025-06-26 1:35 ` Carlo Marcelo Arenas Belón
2025-06-26 0:45 ` Junio C Hamano
2025-06-25 7:35 ` [PATCH v2 2/3] daemon: use sigaction() to install child_handler() Carlo Marcelo Arenas Belón via GitGitGadget
2025-06-25 16:06 ` Junio C Hamano
2025-06-25 16:22 ` Junio C Hamano [this message]
2025-06-25 7:35 ` [PATCH v2 3/3] daemon: explicitly allow EINTR during poll() Carlo Marcelo Arenas Belón via GitGitGadget
2025-06-25 16:11 ` Junio C Hamano
2025-06-25 8:39 ` [PATCH v2 0/3] " Phillip Wood
2025-06-25 16:24 ` Junio C Hamano
2025-06-25 19:35 ` Phillip Wood
2025-06-26 18:24 ` [RFC PATCH] daemon: add a self pipe to trigger reaping of children Carlo Marcelo Arenas Belón
2025-06-26 21:22 ` [RFC PATCH 0/2] daemon: tracking childs without signals Carlo Marcelo Arenas Belón
2025-06-26 21:22 ` [RFC PATCH 1/2] run-command: add a pipe() write end to childs Carlo Marcelo Arenas Belón
2025-06-26 21:22 ` [RFC PATCH 2/2] daemon: poor man's pidfd like POC Carlo Marcelo Arenas Belón
2025-06-27 8:38 ` [RFC PATCH] daemon: add a self pipe to trigger reaping of children Phillip Wood
2025-06-28 6:19 ` Carlo Marcelo Arenas Belón
2025-07-01 13:38 ` Phillip Wood
2025-06-30 15:16 ` Junio C Hamano
2025-06-25 16:07 ` [PATCH v2 0/3] daemon: explicitly allow EINTR during poll() Junio C Hamano
2025-06-26 8:50 ` Carlo Marcelo Arenas Belón
2025-06-26 8:53 ` [PATCH v3 0/4] " Carlo Marcelo Arenas Belón via GitGitGadget
2025-06-26 8:53 ` [PATCH v3 1/4] compat/posix.h: track SA_RESTART fallback Carlo Marcelo Arenas Belón via GitGitGadget
2025-06-27 1:41 ` Junio C Hamano
2025-06-26 8:53 ` [PATCH v3 2/4] compat/mingw: allow sigaction(SIGCHLD) Carlo Marcelo Arenas Belón via GitGitGadget
2025-06-26 12:52 ` Phillip Wood
2025-06-26 13:15 ` Carlo Marcelo Arenas Belón
2025-06-26 13:56 ` Phillip Wood
2025-06-26 14:58 ` Carlo Marcelo Arenas Belón
2025-06-26 15:19 ` phillip.wood123
2025-06-26 20:09 ` Carlo Marcelo Arenas Belón
2025-07-09 14:13 ` Phillip Wood
2025-07-09 16:36 ` Carlo Marcelo Arenas Belón
2025-06-26 8:53 ` [PATCH v3 3/4] daemon: use sigaction() to install child_handler() Carlo Marcelo Arenas Belón via GitGitGadget
2025-06-26 13:11 ` Phillip Wood
2025-06-26 15:33 ` Junio C Hamano
2025-06-26 16:36 ` Carlo Marcelo Arenas Belón
2025-06-26 18:04 ` Phillip Wood
2025-07-07 22:14 ` Junio C Hamano
2025-06-26 8:53 ` [PATCH v3 4/4] daemon: explicitly allow EINTR during poll() Carlo Marcelo Arenas Belón via GitGitGadget
2025-06-26 13:14 ` Phillip Wood
2025-07-09 14:12 ` [PATCH v3 0/4] " Phillip Wood
2025-07-09 17:04 ` Carlo Marcelo Arenas Belón
2025-07-10 19:45 ` [PATCH v4 0/2] " Carlo Marcelo Arenas Belón via GitGitGadget
2025-07-10 19:45 ` [PATCH v4 1/2] compat/mingw: allow sigaction(SIGCHLD) Carlo Marcelo Arenas Belón via GitGitGadget
2025-07-10 21:38 ` Eric Sunshine
2025-07-10 19:45 ` [PATCH v4 2/2] daemon: use sigaction() to install child_handler() Carlo Marcelo Arenas Belón via GitGitGadget
2025-07-10 21:26 ` [PATCH v4 0/2] daemon: explicitly allow EINTR during poll() Junio C Hamano
2025-07-10 23:18 ` Carlo Arenas
2025-07-11 13:14 ` Phillip Wood
2025-07-14 21:52 ` Junio C Hamano
2025-07-15 9:29 ` Phillip Wood
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqsejnx02l.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=carenas@gmail.com \
--cc=chris.torek@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).