troglobit / finit

Fast init for Linux. Cookies included
https://troglobit.com/projects/finit/
MIT License
621 stars 61 forks source link

finit hangs during system shutting down #397

Closed liuming50 closed 3 months ago

liuming50 commented 3 months ago

We observed a issue that finit hangs during system shutting down, when there is a serial debug console connected to the machine.

After some investigation, we found it hangs on this line: https://github.com/troglobit/finit/blob/master/src/util.c#L620

troglobit commented 3 months ago

Which commands exactly did you use to initiate the shutdown/reboot?

mandelmassa commented 3 months ago

I was using reboot which symlinks to initctl. Sending a couple newlines on the console will allow the reboot to proceed.

I was thinking it was related to the fact that ttinit sets attributes for STDERR_FILENO while the scanf requires raw (?) input from stdin. However, simply applying the same cflag/lflag on STDIN_FILENO was not sufficient to resolve the hang in every situation - if nobody logged in on the console it still hangs.

troglobit commented 3 months ago

Yeah this is not right. I'll have a look at it. The reboot command should bypass all terminal screen probing

troglobit commented 3 months ago

OK, I believe I've identified the root cause: https://github.com/troglobit/finit/blob/5998342b3e55638b0f7248383e939a64f53fa8ff/src/log.c#L54-L64

At shutdown all subsystems are called to exit, so too the logging subsystem. Pretty sure this is the instance of ttinit() you run into. Could you verify by removing or commenting out lines 60 & 61?

I'll have a chat with a colleague, but we'll likely just drop those two lines. No point in probing screen at shutdown anymore. ([OK] progress is displayed differently these days.)

mandelmassa commented 3 months ago

I have verified it, it works on our system. Thanks for the quick feedback!

troglobit commented 3 months ago

I have verified it, it works on our system. Thanks for the quick feedback!

Great, thanks! :smiley::+1:

I'll push an official fix later today, which will be part of the next release.