git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Phillip Wood <phillip.wood123@gmail.com>
To: "Carlo Marcelo Arenas Belón" <carenas@gmail.com>,
	phillip.wood@dunelm.org.uk
Cc: git@vger.kernel.org, chris.torek@gmail.com, gitster@pobox.com
Subject: Re: [RFC PATCH] daemon: add a self pipe to trigger reaping of children
Date: Tue, 1 Jul 2025 14:38:44 +0100	[thread overview]
Message-ID: <de0d02a8-37fd-4a24-9042-972398d72adb@gmail.com> (raw)
In-Reply-To: <zy6xtfqnncs3kuipgvdb7jiu7ynodbf7mld4r2ojy3jwkkthm6@jtnzecikxda2>

Hi Carlo

On 28/06/2025 07:19, Carlo Marcelo Arenas Belón wrote:
> On Fri, Jun 27, 2025 at 09:38:36AM -0800, Phillip Wood wrote:
>>
>> On 26/06/2025 19:24, Carlo Marcelo Arenas Belón wrote:
>>>
>>> diff --git a/daemon.c b/daemon.c
>>> index d1be61fd57..d3b9421575 100644
>>> --- a/daemon.c
>>> +++ b/daemon.c
>>> @@ -912,14 +912,17 @@ static void handle(int incoming, struct sockaddr *addr, socklen_t addrlen)
>>>    		add_child(&cld, addr, addrlen);
>>>    }
>>> -static void child_handler(int signo UNUSED)
>>> +int poll_pipe[2] = { -1, -1 };
>> Maybe call this signal_pipe? I'm not sure what poll_pipe means.
>>
>>> +
>>> +static void child_handler(int signo)
>>>    {
>>>    	/*
>>> -	 * Otherwise empty handler because systemcalls will get interrupted
>>> -	 * upon signal receipt
>>>    	 * SysV needs the handler to be rearmed
>>>    	 */
>>>    	signal(SIGCHLD, child_handler);
>>
>> I think from Chris' email that it is conventional to do this at the end of
>> the handler.
> 
> It really depends on which flags the signal was expected to use.  For maximum
> portability it would seem better to have it at the beginning to minimize the
> inherent race condition from when SA_RESETHAND is on effect (which was more
> of a SysV signal() tradition).
> 
> Will move it to the end, regardless, as it won't be needed once the call is
> setup using sigaction().
> 
>> As I said above we could add an additional commit that moves
>> this into the event loop to fix the infinite recursion on AIX.
> 
> Not sure I understant what you mean by this.

Delete the call to signal() from child_handler() and move it to the 
event loop so it is called just before poll()

> I think Chris made clear that
> the AIX issue comes from the handler being expected to do the wait() calls,

The issue is calling signal() without calling wait() first. By removing 
signal() from the signal handler there can be no recursion.

>>> +
>>> +	if (poll_pipe[1] >= 0)
>>> +		write(poll_pipe[1], &signo, 1);
>>
>> write() might fail so we should save errno around it. Conventionally one
>> would re-try on EINTR as well though in this case the most likely reason for
>> that is another child exiting which means the pipe would be written to
>> anyway.
> 
> EINTR shouldn't be possible here from SIGCHLD, because that signal is
> blocked here, 

Hmm I'm not sure that is guaranteed by POSIX though it is true with BSD 
or SysV semantics I think. From a maintainability point of view we could 
see EINTR here if we added a handler for another signal in the future so 
I think we should make sure it is handled correctly.

I wrote it this way because it was only meant to be used as
> a fallback to the EINTR being triggered in poll() and so it wouldn't matter
> if it was lost (for example because of a SIGPIPE).

I'm not convinced about making it a fallback - to me that just means 
we'll never notice if it is broken.

> Once we move to sigaction, SIGPIPE could be added to the mask for this
> handler, but that code can't be implemented on the current base.

I'm not sure I understand. The signal mask supplied to sigaction just 
blocks those signals while the handler is running, they're still 
delivered afterwards so we'd still receive SIGPIPE if the read end was 
closed. We could ignore SIGPIPE so that we get an error from write() 
instead but I'm not sure it is worth worrying about as if the read end 
of the pipe has been closed we have a bug.

>>>    }
>>>    static int set_reuse_addr(int sockfd)
>>> @@ -1121,20 +1124,43 @@ static void socksetup(struct string_list *listen_addr, int listen_port, struct s
>>>    static int service_loop(struct socketlist *socklist)
>>>    {
>>>    	struct pollfd *pfd;
>>> +	unsigned long nfds = 1 + socklist->nr;
>>> +
>>> +	ALLOC_ARRAY(pfd, nfds);
>>> +	if (!pipe(poll_pipe)) {
>>
>> If we cannot create a pipe here then things have gone pretty badly wrong and
>> I think it is unlikely we're going to be able to accept incoming connections
>> so it would be best to die().
> 
> True, but since this is "optional", there is no harm on letting this continue
> even in failure.

Except that we'd never know if this code was broken. We don't expect it 
to fail so why make it optional?

Thanks

Phillip


  reply	other threads:[~2025-07-01 13:38 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
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 [this message]
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=de0d02a8-37fd-4a24-9042-972398d72adb@gmail.com \
    --to=phillip.wood123@gmail.com \
    --cc=carenas@gmail.com \
    --cc=chris.torek@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=phillip.wood@dunelm.org.uk \
    /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).