NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: bin/55278: inetd dies while starting Samba smbd
The following reply was made to PR bin/55278; it has been noted by GNATS.
From: RVP <rvp%SDF.ORG@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc:
Subject: Re: bin/55278: inetd dies while starting Samba smbd
Date: Mon, 6 Nov 2023 23:11:26 +0000 (UTC)
On Mon, 12 Apr 2021, Hauke Fath wrote:
> 0x0000760f81244bba in _sys___kevent50 () from /usr/lib/libc.so.12
> (gdb) cont
> Continuing.
> [New process 25550]
>
> Thread 2 received signal SIGTERM, Terminated.
>
smbd registers a cleanup function via atexit() in main() called killkids()
which does[1]:
```
133 if(am_parent) kill(0,SIGTERM);
```
[1]: https://gitlab.com/samba-team/samba/-/blob/master/source3/smbd/server.c?ref_type=heads
When running in the foreground (-d) inetd does setsid(), but, it _doesn't_
do this when running in the background, And, since smbd is run as root, inetd
gets the SIGTERM sent to the process-group by samba to kill its children.
A simple reproducer is this "server":
```
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
int
main(void)
{
sleep(5);
kill(0, SIGTERM);
exit(EXIT_FAILURE);
}
```
which you can (temporarily) run in /etc/inetd.conf instead of smbd:
```
netbios-ssn stream tcp nowait root /tmp/foo foo
```
It should kill inetd just as effectively.
This should fix the issue:
```
diff -urN a/src/usr.sbin/inetd/inetd.c b/src/usr.sbin/inetd/inetd.c
--- a/src/usr.sbin/inetd/inetd.c 2022-08-10 08:37:53.000000000 +0000
+++ b/src/usr.sbin/inetd/inetd.c 2023-11-06 22:43:54.650415000 +0000
@@ -499,9 +499,9 @@
for (n = 0; n < __arraycount(my_signals); n++)
(void) signal(my_signals[n], SIG_DFL);
- /* Don't put services in terminal session */
- if (foreground)
- setsid();
+ /* Always create new process-group: PR #55278 */
+ if (setsid() == -1)
+ syslog(LOG_ERR, "setsid: %m");
}
}
if (pid == 0) {
```
Should eventually be pulled-up to -8, -9, -10.
-RVP
Home |
Main Index |
Thread Index |
Old Index