Introducing a poweroff(8) command
Giorgos Keramidas
keramida at ceid.upatras.gr
Sun Aug 22 08:06:59 PDT 2004
On 2004-08-21 23:50, Brian Somers <brian at Awfulhak.org> wrote:
>
> IMHO poweroff should behave like ``shutdown -p now'' rather than
> ``halt -p''.
This is relatively easy too. See below :-)
On 2004-08-22 02:06, Tom Rhodes <trhodes at freebsd.org> wrote:
>
> Otherwise, I'm an src/ and can approve this if Brian is ok and
> a 1 week timeout occurres on -arch.
If that's an offer for precommit review/approval, thanks :-)
On 2004-08-22 09:59, Brian Somers <brian at Awfulhak.org> wrote:
>
> Of course the big question is whether to implement poweroff as a shell
> script that runs shutdown or as a link to shutdown... Precidence is on
> the side of the link, simplicity is on the side of the script.
The good thing about implementing this as part of shutdown is that we
don't have to duplicate the option/command-line handling in a shell
script. It's easier to rely on the existing code for parsing and
validating command line arguments, with something similar to the
existing reboot.c trick:
p = rindex(*argv, '/')) ? p + 1 : *argv;
if (strcmp(p, "some magic name") == 0) {
magic_flag = 1;
}
Anyway. Here's a version of the poweroff command implemented as a hard
link to shutdown(8) instead of reboot(8). It's simpler because shutdown
doesn't have any hard-links yet, but does this look better?
%%%
Index: Makefile
===================================================================
RCS file: /home/ncvs/src/sbin/shutdown/Makefile,v
retrieving revision 1.8
diff -u -r1.8 Makefile
--- Makefile 4 Dec 2001 02:19:57 -0000 1.8
+++ Makefile 22 Aug 2004 13:30:43 -0000
@@ -3,6 +3,9 @@
PROG= shutdown
MAN= shutdown.8
+MLINKS= shutdown.8 poweroff.8
+LINKS= ${BINDIR}/shutdown ${BINDIR}/poweroff
+
BINOWN= root
BINGRP= operator
BINMODE=4550
Index: shutdown.8
===================================================================
RCS file: /home/ncvs/src/sbin/shutdown/shutdown.8,v
retrieving revision 1.23
diff -u -r1.23 shutdown.8
--- shutdown.8 2 Jul 2004 21:45:05 -0000 1.23
+++ shutdown.8 22 Aug 2004 13:12:38 -0000
@@ -32,7 +32,8 @@
.Dt SHUTDOWN 8
.Os
.Sh NAME
-.Nm shutdown
+.Nm shutdown ,
+.Nm poweroff
.Nd "close down the system at a given time"
.Sh SYNOPSIS
.Nm
@@ -47,6 +48,14 @@
.Oc
.Ar time
.Op Ar warning-message ...
+.Nm poweroff
+.Op Fl
+.Oo
+.Fl o
+.Op Fl n
+.Oc
+.Ar time
+.Op Ar warning-message ...
.Sh DESCRIPTION
The
.Nm
@@ -65,6 +74,9 @@
(hardware support required)
at the specified
.Ar time .
+This is the default behavior if
+.Nm poweroff
+is called.
.It Fl r
The system is rebooted at the specified
.Ar time .
@@ -83,6 +95,8 @@
.Fl r
is specified,
.Nm
+or
+.Nm poweroff
will execute
.Xr halt 8
or
@@ -103,6 +117,8 @@
.Ar Time
is the time at which
.Nm
+or
+.Nm poweroff
will bring the system down and
may be the word
.Ar now
@@ -188,3 +204,8 @@
.Nm
utility appeared in
.Bx 4.0 .
+.Pp
+The
+.Nm poweroff
+utility appeared in
+.Fx 6.0 .
Index: shutdown.c
===================================================================
RCS file: /home/ncvs/src/sbin/shutdown/shutdown.c,v
retrieving revision 1.26
diff -u -r1.26 shutdown.c
--- shutdown.c 9 Apr 2004 19:58:38 -0000 1.26
+++ shutdown.c 22 Aug 2004 13:33:39 -0000
@@ -115,6 +115,8 @@
if (geteuid())
errx(1, "NOT super-user");
#endif
+ if (strstr((p = rindex(*argv, '/')) ? p + 1 : *argv, "poweroff"))
+ dopower = 1;
nosync = NULL;
readstdin = 0;
while ((ch = getopt(argc, argv, "-hknopr")) != -1)
@@ -517,6 +519,7 @@
warnx("%s", cp);
(void)fprintf(stderr,
"usage: shutdown [-] [-h | -p | -r | -k] [-o [-n]]"
- " time [warning-message ...]\n");
+ " time [warning-message ...]\n"
+ " poweroff [-] [-o [-n]] time [warning-message ...]\n");
exit(1);
}
%%%
More information about the freebsd-arch
mailing list