-
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.
Add shutdown and poweroff into reboot.c
- Loading branch information
Showing
2 changed files
with
42 additions
and
34 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 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,6 +1,7 @@ | ||
/* | ||
* reboot.c | ||
* reboot/shutdown/poweroff | ||
* | ||
* Original version from | ||
* Copyright 2000 Alistair Riddoch | ||
* [email protected] | ||
* | ||
|
@@ -9,44 +10,49 @@ | |
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <errno.h> | ||
#include <time.h> | ||
#include <string.h> | ||
#include <sys/mount.h> | ||
#include <sys/select.h> | ||
#include <linuxmt/limits.h> | ||
#include <arch/system.h> | ||
|
||
int try_unmount(dev_t dev) | ||
static int try_unmount(dev_t dev) | ||
{ | ||
struct statfs statfs; | ||
if (ustatfs(dev, &statfs, UF_NOFREESPACE) < 0) { | ||
return 0; | ||
} | ||
if (umount(statfs.f_mntonname)) { | ||
perror("umount"); | ||
return 1; | ||
} | ||
return 0; | ||
struct statfs statfs; | ||
|
||
if (ustatfs(dev, &statfs, UF_NOFREESPACE) < 0) { | ||
return 0; | ||
} | ||
if (umount(statfs.f_mntonname)) { | ||
perror("umount"); | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
int i, ret; | ||
int force = 1; | ||
if (argc < 2 || argv[1][0] != '-' || argv[1][1] != 'f') | ||
force = 0; | ||
int i, force, flag, ret; | ||
char *progname; | ||
|
||
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 : | ||
!strcmp(progname, "poweroff")? RB_POWEROFF: | ||
RB_SHUTDOWN; | ||
|
||
sync(); | ||
for (i = NR_SUPER - 1; i >= 0; --i) { | ||
ret = try_unmount(i); | ||
/* -f forces reboot even if mount fails */ | ||
if (ret && !force) return 1; | ||
} | ||
sleep(3); | ||
if (reboot(0x1D1E,0xC0DE,0x0123)) { | ||
perror("reboot"); | ||
return 1; | ||
} | ||
return 0; | ||
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; | ||
} | ||
sleep(2); | ||
if (reboot(0, 0, flag)) { | ||
perror(progname); | ||
return 1; | ||
} | ||
return 0; | ||
} |