For compatibility with Linux and Solaris add poweroff(8).

It is implemented as a hard link to shutdown(8) and it is equivalent of:

	# shutdown -p now

While I'm here put one line of usage into one line of C code so it is easier to
grep(1) and separate unrelated code with empty line.

MFC after:	2 weeks
This commit is contained in:
Pawel Jakub Dawidek 2010-12-30 18:06:31 +00:00
parent 4a9ef3f833
commit 6868734cbe
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=216823
3 changed files with 39 additions and 4 deletions

View File

@ -3,6 +3,8 @@
PROG= shutdown PROG= shutdown
MAN= shutdown.8 MAN= shutdown.8
LINKS= ${BINDIR}/shutdown ${BINDIR}/poweroff
MLINKS= shutdown.8 poweroff.8
BINOWN= root BINOWN= root
BINGRP= operator BINGRP= operator

View File

@ -28,11 +28,12 @@
.\" @(#)shutdown.8 8.2 (Berkeley) 4/27/95 .\" @(#)shutdown.8 8.2 (Berkeley) 4/27/95
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd December 23, 2008 .Dd December 30, 2010
.Dt SHUTDOWN 8 .Dt SHUTDOWN 8
.Os .Os
.Sh NAME .Sh NAME
.Nm shutdown .Nm shutdown ,
.Nm poweroff
.Nd "close down the system at a given time" .Nd "close down the system at a given time"
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
@ -47,6 +48,7 @@
.Oc .Oc
.Ar time .Ar time
.Op Ar warning-message ... .Op Ar warning-message ...
.Nm poweroff
.Sh DESCRIPTION .Sh DESCRIPTION
The The
.Nm .Nm
@ -173,6 +175,13 @@ When run without options, the
utility will place the system into single user mode at the utility will place the system into single user mode at the
.Ar time .Ar time
specified. specified.
.Pp
Calling utility as
.Nm poweroff
is equivalent of calling:
.Bd -literal -offset indent
shutdown -p now
.Ed
.Sh FILES .Sh FILES
.Bl -tag -width /var/run/nologin -compact .Bl -tag -width /var/run/nologin -compact
.It Pa /var/run/nologin .It Pa /var/run/nologin

View File

@ -115,8 +115,31 @@ main(int argc, char **argv)
if (geteuid()) if (geteuid())
errx(1, "NOT super-user"); errx(1, "NOT super-user");
#endif #endif
nosync = NULL; nosync = NULL;
readstdin = 0; readstdin = 0;
/*
* Test for the special case where the utility is called as
* "poweroff", for which it runs 'shutdown -p now'.
*/
if ((p = rindex(argv[0], '/')) == NULL)
p = argv[0];
else
++p;
if (strcmp(p, "poweroff") == 0) {
if (getopt(argc, argv, "") != -1)
usage((char *)NULL);
argc -= optind;
argv += optind;
if (argc != 0)
usage((char *)NULL);
dopower = 1;
offset = 0;
(void)time(&shuttime);
goto poweroff;
}
while ((ch = getopt(argc, argv, "-hknopr")) != -1) while ((ch = getopt(argc, argv, "-hknopr")) != -1)
switch (ch) { switch (ch) {
case '-': case '-':
@ -161,6 +184,7 @@ main(int argc, char **argv)
getoffset(*argv++); getoffset(*argv++);
poweroff:
if (*argv) { if (*argv) {
for (p = mbuf, len = sizeof(mbuf); *argv; ++argv) { for (p = mbuf, len = sizeof(mbuf); *argv; ++argv) {
arglen = strlen(*argv); arglen = strlen(*argv);
@ -510,7 +534,7 @@ usage(const char *cp)
if (cp != NULL) if (cp != NULL)
warnx("%s", cp); warnx("%s", cp);
(void)fprintf(stderr, (void)fprintf(stderr,
"usage: shutdown [-] [-h | -p | -r | -k] [-o [-n]]" "usage: shutdown [-] [-h | -p | -r | -k] [-o [-n]] time [warning-message ...]\n"
" time [warning-message ...]\n"); " poweroff\n");
exit(1); exit(1);
} }