allow fshalt to power off the system Reference: /n/atom/patch/applied2013/fshalth Date: Tue Oct 22 10:54:31 CES 2013 Signed-off-by: quanstro@quanstro.net --- /rc/bin/fshalt Tue Oct 22 10:54:08 2013 +++ /rc/bin/fshalt Tue Oct 22 10:54:08 2013 @@ -1,17 +1,19 @@ #!/bin/rc -# fshalt [-r] - sync (flush) and, if possible, halt all file servers -# and optionally reboot +# fshalt [-rh] - sync (flush) and, if possible, halt all file servers +# and optionally reboot or hard halt rfork nes kerncopy=() -reboot=no -switch ($#*) { -case 0 -case 1 - reboot=yes -case * - echo usage: $0 '[-r]' >[1=2] +flagfmt='r,h' +args='kern' +if(! ifs=() eval `{aux/getflags $*} || ! ~ $#* 0 1){ + aux/usage exit usage } +if(~ $#flagh 1 && {~ $#flagr 1 || ~ $#* 1}){ + aux/usage + exit usage +} +kern=$* path=(/bin) builtin cd / @@ -32,7 +34,8 @@ } fn isbootable { - test -e $1 && ~ `{file $1} *' plan 9 boot image' + test -e $1 && ~ `'' {file $1} *' plan 9 boot image' \ + *' plan 9 executable'* *ELF*' executable' } fn usekernel { kerncopy=kern @@ -40,9 +43,10 @@ } # make a copy of the right kernel -if (~ $reboot yes) { - kern=`{echo $terminal | - sed 's;^([^ ]+) .*/([^/]+)$;/n/boot/'$cputype'/9\2;'} +if (~ $#flagr 1) { + if (~ $#kern 0) + kern=`{echo $terminal | + sed 's;^([^ ]+) .*/([^/ ]+).*$;/n/boot/'$cputype'/9\2;'} if (isbootable $kern) usekernel $kern if not { @@ -136,8 +140,10 @@ echo echo done halting - if (~ $reboot yes) + if (~ $#flagr 1) echo reboot $kerncopy >'#c/reboot' + if(~ $#flagh 1) + echo power off > '#α/acpictl' } x --- /sys/man/8/fshalt Tue Oct 22 10:54:09 2013 +++ /sys/man/8/fshalt Tue Oct 22 10:54:10 2013 @@ -4,7 +4,7 @@ .SH SYNOPSIS .B fshalt [ -.B -r +.B -rh ] [ .I new-kernel ] @@ -23,6 +23,9 @@ and .IR kfs servers. +If given +.BR -h , +the machine will be powered down, if possible. If given .BR -r , .I fshalt