Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 22 Aug 2004 17:41:29 +0300
From:      Giorgos Keramidas <keramida@ceid.upatras.gr>
To:        Brian Somers <brian@Awfulhak.org>, Tom Rhodes <trhodes@freebsd.org>
Cc:        freebsd-arch@freebsd.org
Subject:   Re: Introducing a poweroff(8) command
Message-ID:  <20040822144129.GA785@gothmog.gr>
In-Reply-To: <20040822095918.60146e21@dev.lan.Awfulhak.org> <20040822020609.15d7cb27@localhost.pittgoth.com> <20040821235048.6244270a@dev.lan.Awfulhak.org>
References:  <20040821235048.6244270a@dev.lan.Awfulhak.org> <20040822020609.15d7cb27@localhost.pittgoth.com> <20040822095918.60146e21@dev.lan.Awfulhak.org> <20040821191659.GA94336@gothmog.gr> <20040821202252.GB94336@gothmog.gr> <20040821235048.6244270a@dev.lan.Awfulhak.org> <20040822020609.15d7cb27@localhost.pittgoth.com> <20040821191659.GA94336@gothmog.gr> <20040821202252.GB94336@gothmog.gr> <20040821235048.6244270a@dev.lan.Awfulhak.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On 2004-08-21 23:50, Brian Somers <brian@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@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@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);
 }
%%%



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040822144129.GA785>