OpenRC / openrc

The OpenRC init system
BSD 2-Clause "Simplified" License
1.44k stars 244 forks source link

supervise-daemon segfaults if the "retry" parameter has a space instead of a slash as a separator #284

Open vaartis opened 5 years ago

vaartis commented 5 years ago
 * Caching service dependencies ... [ ok ]
 * Stopping tabun_rst ... [ ok ]
 * Starting tabun_rst ...
/lib/rc/sh/supervise-daemon.sh: line 27:  2547 Segmentation fault      supervise-daemon tabun_rst --start --retry SIGTERM/30 SIGKILL/5 --chdir /home/vaartis/tabun_rst --pidfile /var/run/tabun_rst.pid --respawn-delay 60 --respawn-max 10 --user vaartis:vaartis /home/vaartis/tabun_rst/target/release/tabun_rst -- comments
 * failed to start tabun_rst                                                                                                                                                                                                           [ !! ]
 * ERROR: tabun_rst failed to start

It works fine without that parameter though.

williamh commented 5 years ago

The first issue I see is the space after 30 instead of a /. It should read: --retry SIGTERM/30/SIGKILL/5. Once you fix that, you should be able to start. However, this is an issue, because that incorrect syntax shouldn't cause a segfault.

vaartis commented 5 years ago

Didn't know about the syntax. I just used the parameter in the init.d file, i'm not sure the manual says anything about that dot at the end.

vaartis commented 5 years ago

I actually had no idea about the / separator, since start-stop-daemon doesn't complain anything about separting with a space.

graywolf commented 4 years ago

The crash itself actually is not related to the parsing of retry but to the #326 . #327 therefore also fixes this bug.

Starting program: /home/wolf/tmp/openrc/src/rc/supervise-daemon test --start --retry SIGTERM/30 SIGKILL/5 --stdout /var/log/test.log --stderr /var/log/test.err --pidfile /run/test.pid --respawn-delay 15 --respawn-max 5 --respawn-period 180 /usr/bin/ruby -- /tmp/test.rb
 * supervise-daemon: SIGKILL/5 does not exist

However there is still a question if supervise-daemon.sh should not be able to forward arguments with spaces.

vaartis commented 4 years ago

Does the same thing happen when the argument is "SIGTERM/30 SIGKILL/5" (quoted)?

graywolf commented 4 years ago

Hm, quoted it works, good point.

#!/sbin/openrc-run
set -x

pidfile="/run/$RC_SVCNAME.pid"
command="/tmp/test.rb"
command_args="this \"is a test\" arg"
output_log=/var/log/"$RC_SVCNAME".log
error_log=/var/log/"$RC_SVCNAME".err

supervisor=supervise-daemon
respawn_delay=15
respawn_max=5
respawn_period=180
retry="\"SIGTERM/30 SIGKILL/5\""

Obvious in hindsight, but not very pretty I guess.

EDIT: That does not work for pidfile and chroot. It does start but the pid file is not removed due to shutdown not using eval. See my comment here https://github.com/OpenRC/openrc/issues/77#issuecomment-538439147 .