-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2000 from ghaerr/shutdown
[cmds] Add -s, -r, and -p options to shutdown, remove reboot, poweroff
- Loading branch information
Showing
5 changed files
with
57 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,33 @@ | ||
.TH SHUTDOWN 8 | ||
.SH NAME | ||
shutdown \- shut down the system quickly | ||
shutdown \- shut down, power off or reboot the system quickly | ||
.SH SYNOPSIS | ||
.B shutdown | ||
.RB [ -f ] | ||
.RB [ -s ][ -r ][ -p ][ -f ] | ||
.SS OPTIONS | ||
.TP 5 | ||
.B \-s | ||
Perform shut down operation and halt the system (default action). | ||
.TP 5 | ||
.B \-r | ||
Reboot the system. | ||
.TP 5 | ||
.B \-p | ||
Power off the system. | ||
.TP 5 | ||
.B \-f | ||
Force shutdown even if root volume cannot be remounted read-only. | ||
Continue even if root volume cannot be remounted read-only. | ||
.SH DESCRIPTION | ||
.B Shutdown | ||
is a program that allows the superuser to shut down the system immediately. | ||
A | ||
.B sync | ||
and unmount of the root filesystem and all other mounted filesystems | ||
are performed, and after 3 seconds have elapsed, the system is halted. | ||
.SH BUGS | ||
Not all systems support powering off, in which case the system | ||
will remain on but halted. | ||
.SH "SEE ALSO" | ||
.BR sync (1), | ||
.BR unmount (1), | ||
.BR reboot (8), | ||
.BR poweroff (8), | ||
.BR reboot (2). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,33 @@ | ||
/* | ||
* reboot/shutdown/poweroff | ||
* | ||
* Original version from | ||
* Usage: {shutdown,reboot,poweroff} [-s][-r][-p][-f] | ||
* | ||
* Completely rewritten from original version of | ||
* Copyright 2000 Alistair Riddoch | ||
* [email protected] | ||
* | ||
* This file may be distributed under the terms of the GNU General Public | ||
* License v2, or at your option any later version. | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <unistd.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <sys/mount.h> | ||
#include <linuxmt/limits.h> | ||
#include <arch/system.h> | ||
|
||
#define errmsg(str) write(STDERR_FILENO, str, sizeof(str) - 1) | ||
|
||
static int f_flag; /* continue even if unmounts fail */ | ||
|
||
static void usage(void) | ||
{ | ||
errmsg("Usage: shutdown [-s][-r][-p][-f]\n"); | ||
exit(1); | ||
} | ||
|
||
static int try_unmount(dev_t dev) | ||
{ | ||
struct statfs statfs; | ||
|
@@ -32,25 +44,43 @@ static int try_unmount(dev_t dev) | |
|
||
int main(int argc, char **argv) | ||
{ | ||
int i, force, flag, ret; | ||
char *progname; | ||
char *p, *progname; | ||
int i, how; | ||
|
||
force = (argc >= 2 && argv[1][0] == '-' && argv[1][1] == 'f'); | ||
if ((progname = strrchr(argv[0], '/')) != NULL) | ||
progname++; | ||
else progname = argv[0]; | ||
flag = !strcmp(progname, "reboot")? RB_REBOOT : | ||
how = !strcmp(progname, "reboot")? RB_REBOOT : | ||
!strcmp(progname, "poweroff")? RB_POWEROFF: | ||
RB_SHUTDOWN; | ||
|
||
while (argv[1] && argv[1][0] == '-') { | ||
for (p = &argv[1][1]; *p; p++) { | ||
switch (*p) { | ||
case 's': | ||
how = RB_SHUTDOWN; break; | ||
case 'r': | ||
how = RB_REBOOT; break; | ||
case 'p': | ||
how = RB_POWEROFF; break; | ||
case 'f': | ||
f_flag = 1; break; | ||
default: | ||
usage(); | ||
} | ||
} | ||
argv++; | ||
argc--; | ||
} | ||
if (argc > 1) usage(); | ||
|
||
sync(); | ||
for (i = NR_SUPER - 1; i >= 0; --i) { | ||
ret = try_unmount(i); | ||
if (ret && !force) /* -f forces reboot even if mount fails */ | ||
return 1; | ||
if (try_unmount(i) && !f_flag) | ||
return 1; /* stop on failed unmount unless -f specified */ | ||
} | ||
sleep(2); | ||
if (reboot(0, 0, flag)) { | ||
if (reboot(0, 0, how)) { | ||
perror(progname); | ||
return 1; | ||
} | ||
|