From 598a4a00a573dfdc08268060bf909eed92bc7717 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Wed, 10 Dec 2014 15:01:53 -0600 Subject: [PATCH] More cleanup; thanks to WilliamH for the patch. --- init | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/init b/init index dc0f2ac..11b05ca 100755 --- a/init +++ b/init @@ -3,25 +3,26 @@ require 'socket' -def do_cmd(*cmd) - ctl = UNIXSocket.open('/run/initctl') - ctl.puts(cmd.join(' ')) - puts(ctl.readline.chomp) - exit -end - - # These are hashes - $daemons = {} $daemonCmds = {} # Needed to prevent respawning during a reboot... - $shuttingDown = false -# Here we do some process monitoring... +def launch(id, cmd) + puts('Starting %s...' % id) + pid = fork do + Process.setsid() + exec(*cmd) + end + $daemons[id] = pid + $daemonCmds[id] = cmd +end + + +# Here we do some process monitoring... Signal.trap(:SIGCHLD) do loop do begin @@ -47,17 +48,6 @@ Signal.trap(:SIGCHLD) do end -def launch(id, cmd) - puts('Starting %s...' % id) - pid = fork do - Process.setsid() - exec(*cmd) - end - $daemons[id] = pid - $daemonCmds[id] = cmd -end - - def init puts('*** init-ng v1.0.0 starting...') @@ -84,8 +74,15 @@ def shutdown end -# This shows the one of the hazards of coding this in Ruby... +def do_cmd(*cmd) + ctl = UNIXSocket.open('/run/initctl') + ctl.puts(cmd.join(' ')) + puts(ctl.readline.chomp) + exit +end + +# This shows the one of the hazards of coding this in Ruby... def sys_reboot(cmd) # LINUX_REBOOT_CMD_POWER_OFF == 0x4321FEDC # LINUX_REBOOT_CMD_RESTART == 0x01234567 -- 2.37.2