Busybox reboot has no effect on buildroot Linux

Viewed 712

I run an Embedded Linux system, which is created with Buildroot 2021.02.2 and has BusyBox v1.33.0, Linux 5.4.8, glibc 2.32.

When I run

# reboot

It does nothing, and there is no error or warning in syslog.

However, when I run with -f force option, it reboots the device.

# reboot --help
BusyBox v1.33.0 () multi-call binary.

Usage: reboot [-d DELAY] [-nf]

Reboot the system

    -d SEC  Delay interval
    -n  Do not sync
    -f  Force (don't go through init)

# reboot -f
< reboots OK >

I have debug messages in /etc/init.d/rcK and in inittab, but it looks like the execution after reboot is not reaching the inittab nor rcK. The "shutdown" part of /etc/inittab:

# Stuff to do before rebooting
::shutdown:/bin/echo "MY DEBUG" | /usr/bin/logger
::shutdown:/etc/init.d/rcK
::shutdown:/sbin/swapoff -a
::shutdown:/bin/umount -a -r
::respawn:/usr/bin/monit -Ic /etc/monitrc

I have confirmed the libc.so has the reboot functionality:

nm build/glibc-2.32-37-g760e1d287825fa91d4d5a0cc921340c740d803e2/build/libc.so.6 | grep reboot
000cb2e0 T reboot

This makes me think there is a mistake in the communication with init. The system has Busybox init: BR2_INIT_BUSYBOX=y.

Signals accepted by init:

# init --help
BusyBox v1.33.0 () multi-call binary.

Usage: init

Init is the first process started during boot. It never exits.
It (re)spawns children according to /etc/inittab.
Signals:
HUP: reload /etc/inittab
TSTP: stop respawning until CONT
QUIT: re-exec another init
USR1/TERM/USR2/INT: run halt/reboot/poweroff/Ctrl-Alt-Del script

Do you have any ideas how to debug this situation? I want the reboot to work with proper shutdown and without having to omit the init.

EDIT:

The reboot command from busybox sometimes has effect, and sometimes not, this is why this case is especially confusing.

When it works, it gives the following log in syslog:

Jan  1 00:20:26 : starting pid 494, tty '': '/etc/init.d/rcK'                                                                              
Jan  1 00:20:26 [my_service: signal_handler] MyService terminated                                                                  
Jan  1 00:20:26 bluetoothd[368]: Terminating                                                                                               
Jan  1 00:20:26 bluetoothd[368]: Stopping SDP server                                                                                       
Jan  1 00:20:26 bluetoothd[368]: Exit                                                                                                                                                                         
Jan  1 00:20:27 dropbear[346]: Early exit: Terminated by signal                                                                            
Jan  1 00:20:27 ntpd[318]: ntpd exiting on signal 15 (Terminated)                                                                          
Jan  1 00:20:28 ModemManager[312]: <info>  caught signal, shutting down...                                                                 
Jan  1 00:20:28 ModemManager[312]: <info>  ModemManager is shut down                                                                       
Jan  1 00:20:29 syslog-ng[236]: syslog-ng shutting down; version='3.30.1'                                                                  
Jan  1 00:20:29 : starting pid 575, tty '': '/sbin/swapoff -a'                                                                             
Jan  1 00:20:29 : starting pid 576, tty '': '/bin/umount -a -r'     

When it has no effect, there is no evidence in logs, not even calling the rcK. Do you have ideas what could be the reason for such behavior? As a last resort, I can move to SysVinit if this would solve the problem.

EDIT: SOLUTION

Posting the solution here since the question was closed.

When writing init scripts, always use start-stop-daemon with either -b -m -p, or with just -p.

Using -m without -b option can cause problems similar to the one described in question.

Examples of good usage:

start-stop-daemon -S -q -m -b -p /var/run/logrotate.pid --exec /usr/sbin/logrotate.sh

or

start-stop-daemon -S -q -p "$PIDFILE" -x "/usr/sbin/$DAEMON"

More info:

0 Answers
Related