By popular request reinstate fakeidentd's standalone mode.

Since this is also needed for other applets like telnetd,
introduce generic driver for such things.
It even supports inetd-wait ('linger') mode, when inetd
hands out listen socket to child and waits to it to die,
instead of handing out accepted socket and continuing
listening itself (nowait mode).
Code growth ~200 bytes.
NB: our inetd doesn't support wait mode yet (or mabe it is buggy).
This commit is contained in:
Denis Vlasenko
2007-01-14 01:29:06 +00:00
parent 150f402b36
commit 7a431b3715
7 changed files with 524 additions and 25 deletions

View File

@@ -1289,31 +1289,28 @@ inetd_main(int argc, char *argv[])
if (CONFIG == NULL)
bb_error_msg_and_die("non-root must specify a config file");
if (!(opt & 2)) {
#ifdef BB_NOMMU
if (!(opt & 2)) {
/* reexec for vfork() do continue parent */
vfork_daemon_rexec(0, 0, argc, argv, "-f");
#else
xdaemon(0, 0);
#endif
} else {
setsid();
}
bb_sanitize_stdio(0);
#else
bb_sanitize_stdio(!(opt & 2));
#endif
logmode = LOGMODE_SYSLOG;
if (uid == 0) {
gid_t gid = getgid();
/* If run by hand, ensure groups vector gets trashed */
gid_t gid = getgid();
setgroups(1, &gid);
}
{
FILE *fp = fopen(_PATH_INETDPID, "w");
if (fp != NULL) {
fprintf(fp, "%u\n", getpid());
(void) fclose(fp);
fclose(fp);
}
}