Re: [PATCH 3/3] daemon: explicitly allow EINTR during poll()
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jun 24, 2025, 15:43 UTC
- Message-ID
- <xmqqqzz916xu.fsf@gitster.g>
- In-Reply-To
- <a450bdb0066912d135dd242090b012de0bc18180.1750774122.git.gitgitgadget@gmail.com>
"Carlo Marcelo Arenas Belón via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 14 quoted lines
> -static void child_handler(int signo UNUSED)
> +static void child_handler(int signo)
> {
> /*
> - * Otherwise empty handler because systemcalls will get interrupted
> - * upon signal receipt
> + * Empty handler because systemcalls should get interrupted
> + * upon signal receipt.
> */
> +#ifdef NO_SIGINTERRUPT
> + /* SysV needs the handler to be rearmed */
> + signal(signo, child_handler);
> +#endif
> }On NO_SIGINTERRUPT systems, signo is UNUSED, isn't it?
Can we abstract this a bit better? #if/#else/#endif sprinkled everywhere is simply an eyesore.
Show 43 quoted lines
> static int set_reuse_addr(int sockfd)
> @@ -1118,8 +1122,10 @@ static void socksetup(struct string_list *listen_addr, int listen_port, struct s
>
> static int service_loop(struct socketlist *socklist)
> {
> - struct pollfd *pfd;
> +#ifndef NO_SIGINTERRUPT
> struct sigaction sa;
> +#endif
> + struct pollfd *pfd;
> CALLOC_ARRAY(pfd, socklist->nr);
>
> @@ -1128,14 +1134,22 @@ static int service_loop(struct socketlist *socklist)
> pfd[i].events = POLLIN;
> }
>
> +#ifdef NO_SIGINTERRUPT
> + signal(SIGCHLD, child_handler);
> +#else
> sigemptyset(&sa.sa_mask);
> sa.sa_flags = SA_NOCLDSTOP | SA_RESTART;
> sa.sa_handler = child_handler;
> sigaction(SIGCHLD, &sa, NULL);
> +#endif
>
> for (;;) {
> check_dead_children();
>
> +#ifndef NO_SIGINTERRUPT
> + sa.sa_flags &= ~SA_RESTART;
> + sigaction(SIGCHLD, &sa, NULL);
> +#endif
> if (poll(pfd, socklist->nr, -1) < 0) {
> if (errno != EINTR) {
> logerror("Poll failed, resuming: %s",
> @@ -1144,6 +1158,10 @@ static int service_loop(struct socketlist *socklist)
> }
> continue;
> }
> +#ifndef NO_SIGINTERRUPT
> + sa.sa_flags |= SA_RESTART;
> + sigaction(SIGCHLD, &sa, NULL);
> +#endif