summaryrefslogtreecommitdiffstats
path: root/sbin/shutdown/shutdown.c
diff options
context:
space:
mode:
authorpjd <pjd@FreeBSD.org>2010-12-30 18:06:31 +0000
committerpjd <pjd@FreeBSD.org>2010-12-30 18:06:31 +0000
commit7a575413cdc4c11c26f5d9578b5458a6cbaecdbd (patch)
tree841e4912bb3223fec4f317ed614a2a385cbb5dec /sbin/shutdown/shutdown.c
parent839236cbc1d5d457989fd137b9f17d9eaf1648dd (diff)
downloadFreeBSD-src-7a575413cdc4c11c26f5d9578b5458a6cbaecdbd.zip
FreeBSD-src-7a575413cdc4c11c26f5d9578b5458a6cbaecdbd.tar.gz
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
Diffstat (limited to 'sbin/shutdown/shutdown.c')
-rw-r--r--sbin/shutdown/shutdown.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/sbin/shutdown/shutdown.c b/sbin/shutdown/shutdown.c
index 9032866..8e722ca 100644
--- a/sbin/shutdown/shutdown.c
+++ b/sbin/shutdown/shutdown.c
@@ -115,8 +115,31 @@ main(int argc, char **argv)
if (geteuid())
errx(1, "NOT super-user");
#endif
+
nosync = NULL;
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)
switch (ch) {
case '-':
@@ -161,6 +184,7 @@ main(int argc, char **argv)
getoffset(*argv++);
+poweroff:
if (*argv) {
for (p = mbuf, len = sizeof(mbuf); *argv; ++argv) {
arglen = strlen(*argv);
@@ -510,7 +534,7 @@ usage(const char *cp)
if (cp != NULL)
warnx("%s", cp);
(void)fprintf(stderr,
- "usage: shutdown [-] [-h | -p | -r | -k] [-o [-n]]"
- " time [warning-message ...]\n");
+ "usage: shutdown [-] [-h | -p | -r | -k] [-o [-n]] time [warning-message ...]\n"
+ " poweroff\n");
exit(1);
}
OpenPOWER on IntegriCloud