Dear courageous Reader,

The 6.0 to 6.4 diff show the go_daemon ( why not
https://man.openbsd.org/daemon ??? )
function changed a lot, before it was working through automation software
now it creates zombie, that NEVER dies.

do_daemon Diff Below.

One way to produce this would be :

perl
unless ( fork ) {
close STDIN; close STDOUT; close STDERR;
open STDIN, '/dev/null';
open STDOUT, '>/dev/null';
open STDERR, '>/dev/null';
exec('dhclient', 'if0'); #choose your if
}
^D

The code of dhclient regarding the privsep is quite complex
and apparently the isatty is quite late.


Going to daemon super early 'fix' the problem
( I have another diff in this stable tree so don't mind the line number )

@@ -554,6 +558,11 @@ main(int argc, char *argv[])
        if ((cmd_opts & OPT_NOACTION) != 0)
                return 0;
+       if (isatty(STDERR_FILENO) != 0
+           && (cmd_opts & OPT_FOREGROUND) == 0 ) {
+// cmd_opts |= OPT_VERBOSE;
+               go_daemon();
+       }
        /*
         * Set default client identifier, if needed, *before* reading
         * the leases file! Changes to the lladdr will trigger a restart

go_daemon maybe over kill , so far I don't understand which FD stay open
I guess only reading ktrace would help.

o: Thank you for reading :o

 - - - - - - - - -

 void
 go_daemon(void)
 {
- static int state = 0;
+ static int daemonized = 0;

- if (no_daemon || state)
+ if ((cmd_opts & OPT_FOREGROUND) != 0 || daemonized != 0)
  return;

- state = 1;
+ daemonized = 1;

+ if (rdaemon(nullfd) == -1)
+ fatal("daemonize");
+
  /* Stop logging to stderr. */
- log_perror = 0;
+ log_init(0, LOG_DAEMON);
+ if ((cmd_opts & OPT_VERBOSE) != 0)
+ log_setverbose(1); /* Show log_debug() messages. */
+ log_procinit(log_procname);

- if (daemon(1, 0) == -1)
- error("daemon");
-
- /* we are chrooted, daemon(3) fails to open /dev/null */
- if (nullfd != -1) {
- dup2(nullfd, STDIN_FILENO);
- dup2(nullfd, STDOUT_FILENO);
- dup2(nullfd, STDERR_FILENO);
- close(nullfd);
- nullfd = -1;
- }
-
- /* Catch stuff that might be trying to terminate the program. */
+ setproctitle("%s", log_procname);
  signal(SIGHUP, sighdlr);
- signal(SIGINT, sighdlr);
- signal(SIGTERM, sighdlr);
- signal(SIGUSR1, sighdlr);
- signal(SIGUSR2, sighdlr);
-
  signal(SIGPIPE, SIG_IGN);
 }



--
--
---------------------------------------------------------------------------------------------------------------------
Knowing is not enough; we must apply. Willing is not enough; we must do

Reply via email to