From: Shamus Hammons Date: Wed, 10 Dec 2014 19:47:29 +0000 (-0600) Subject: Edited script for clarity. X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=init-ng;a=commitdiff_plain;h=96f2cf3474b5723cb42186f5950a008d3775ff2a Edited script for clarity. --- diff --git a/init b/init index f281acd..dc0f2ac 100755 --- a/init +++ b/init @@ -11,25 +11,6 @@ def do_cmd(*cmd) end -# If we're not PID 1, parse & send commands to /run/initctl - -if $$ != 1 - case ARGV[0] - when 'poweroff', 'restart', 'halt' - do_cmd(ARGV[0].to_sym) - when 'status' - do_cmd(ARGV.shift.to_sym, *ARGV) - when 'test' - map = { poweroff: 0x4321fedc, restart: 0x01234567, halt: 0xcdef0123 } - # 169 == SYS_reboot - syscall(169, 0xfee1dead, 0x20112000, map[:poweroff]) - else - puts('I know the following commands: poweroff, restart, halt, status, test') - exit 1 - end -end - - # These are hashes $daemons = {} @@ -66,17 +47,6 @@ Signal.trap(:SIGCHLD) do end -def action(name) - print(name) - begin - yield - rescue => e - print(' (error: %s)' % e) - end - puts -end - - def launch(id, cmd) puts('Starting %s...' % id) pid = fork do @@ -114,25 +84,6 @@ def shutdown end -init - -ARGV.each do |e| - case e - when 'emergency' - $emergency = true - end -end - -if $emergency - launch('agetty1', %w[/sbin/agetty tty1 --noclear --autologin root]) -else - # Launch TTYs... - (1..5).each do |n| - launch("agetty#{n}", %W[/sbin/agetty tty#{n} --noclear]) - end -end - - # This shows the one of the hazards of coding this in Ruby... def sys_reboot(cmd) @@ -153,6 +104,45 @@ def sys_sync end +# +# Start of the script proper +# +# If we're not PID 1, parse & send commands to /run/initctl +# +if $$ != 1 + case ARGV[0] + when 'poweroff', 'restart', 'halt' + do_cmd(ARGV[0].to_sym) + when 'status' + do_cmd(ARGV.shift.to_sym, *ARGV) + when 'test' + map = { poweroff: 0x4321fedc, restart: 0x01234567, halt: 0xcdef0123 } + # 169 == SYS_reboot + syscall(169, 0xfee1dead, 0x20112000, map[:poweroff]) + else + puts('I know the following commands: poweroff, restart, halt, status, test') + exit 1 + end +end + +init + +ARGV.each do |e| + case e + when 'emergency' + $emergency = true + end +end + +if $emergency + launch('agetty1', %w[/sbin/agetty tty1 --noclear --autologin root]) +else + # Launch TTYs... + (1..5).each do |n| + launch("agetty#{n}", %W[/sbin/agetty tty#{n} --noclear]) + end +end + begin server = UNIXServer.open('/run/initctl') rescue Errno::EADDRINUSE