[PATCH] syslogd: fork after init on a regular system, not before
Michael Tokarev
mjt at tls.msk.ru
Wed Jun 14 20:52:34 UTC 2023
14.06.2023 23:30, Michael Tokarev пишет:
> 13.06.2023 17:30, Denys Vlasenko wrote:
>> I think we can delay daemonizing in both cases.
>>
>> Please try current git.
>
> Yes, your version is better, it is definitely cleaner, especially
> after the preparational patch.
>
> But does it work for non-MMU case?
> Or will it just open /dev/log twice and everything will be ok?
Actually it doesn't work on regular system too, the fd#0 is redirected
from /dev/null somewhere down the line and enters a tight loop:
44138 readlink("/dev/log", "/run/systemd/journal/dev-log", 80) = 28
44138 readlink("/run/systemd/journal/dev-log", 0x5611c6c26ee0, 80) = -1 EINVAL (Invalid argument)
44138 unlink("/run/systemd/journal/dev-log") = 0
44138 socket(AF_UNIX, SOCK_DGRAM, 0) = 3
44138 bind(3, {sa_family=AF_UNIX, sun_path="/run/systemd/journal/dev-log"}, 110) = 0
44138 chmod("/dev/log", 0666) = 0
44138 dup2(3, 0) = 0
44138 close(3) = 0
44138 chdir("/") = 0
44138 openat(AT_FDCWD, "/dev/null", O_RDWR) = 3
44138 clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7fb6bc72fa10) = 44139
44138 exit_group(0) = ?
44138 +++ exited with 0 +++
44139 set_robust_list(0x7fb6bc72fa20, 24) = 0
44139 setsid() = 44139
44139 dup2(3, 0) = 0
44139 dup2(3, 1) = 1
44139 dup2(3, 2) = 2
44139 close(3) = 0
It is done in bb_daemonize_or_rexec(). Which, it seems,
can be optimized too, to avoid duplicate dup(0,1,2) case.
This is why I used extra variable 'int fd = .. xmove_fd(fd)'.
(btw, should it chmod the result of readlink, not /dev/log? - probably doesn't matter).
Thanks,
/mjt
/mjt
More information about the busybox
mailing list