[PATCH] syslogd: fork after init on a regular system, not before

Denys Vlasenko vda.linux at googlemail.com
Tue Jun 13 14:30:17 UTC 2023


I think we can delay daemonizing in both cases.

Please try current git.

On Thu, Jun 8, 2023 at 10:44 AM Michael Tokarev <mjt at tls.msk.ru> wrote:
>
> Current syslogd performs all init after daemonizing, meanwhile
> main process exits successfully. This means any errors during init
> will not be even shown up because at this time the process has its
> stderr redirected to /dev/null already.
>
> On a MMU system, delay daemonizing to after init.
> On non-MMU system, keep current code.
>
> Signed-off-by: Michael Tokarev <mjt at tls.msk.ru>
> ---
> This is a generic problem with many busybox daemons, I think its
> root is within the no-MMU system support (where we can't fork).
> I think this should be solved in a more generic way too, but this
> is just an example of how this can be fixed in principle.  The
> prob with syslogd is real, any error and it doesn't start but
> does not show error messages and reports success, - this is hardly
> acceptable behavour.
>
>  sysklogd/syslogd.c | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c
> index 6ddfd771a..2f9a727cd 100644
> --- a/sysklogd/syslogd.c
> +++ b/sysklogd/syslogd.c
> @@ -1025,7 +1025,6 @@ static void do_syslogd(void)
>         signal(SIGALRM, do_mark);
>         alarm(G.markInterval);
>  #endif
> -       xmove_fd(create_socket(), STDIN_FILENO);
>
>         if (option_mask32 & OPT_circularlog)
>                 ipcsyslog_init();
> @@ -1033,6 +1032,16 @@ static void do_syslogd(void)
>         if (option_mask32 & OPT_kmsg)
>                 kmsg_init();
>
> +       {
> +               int fd = create_socket();
> +#if BB_MMU
> +               if (!(option_mask32 & OPT_nofork)) {
> +                       bb_daemonize(DAEMON_CHDIR_ROOT);
> +               }
> +#endif
> +               xmove_fd(fd, STDIN_FILENO);
> +       }
> +
>         timestamp_and_log_internal("syslogd started: BusyBox v" BB_VER);
>         write_pidfile_std_path_and_ext("syslogd");
>
> @@ -1179,9 +1188,11 @@ int syslogd_main(int argc UNUSED_PARAM, char **argv)
>         G.hostname = safe_gethostname();
>         *strchrnul(G.hostname, '.') = '\0';
>
> +#if !BB_MMU
>         if (!(opts & OPT_nofork)) {
>                 bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv);
>         }
> +#endif
>
>         do_syslogd();
>         /* return EXIT_SUCCESS; */
> _______________________________________________
> busybox mailing list
> busybox at busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox


More information about the busybox mailing list