-
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.
Create hard links of reboot and poweroff to shutdown
- Loading branch information
Showing
6 changed files
with
40 additions
and
135 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 |
---|---|---|
|
@@ -17,9 +17,7 @@ min_init | |
mouse | ||
mount | ||
passwd | ||
poweroff | ||
ps | ||
reboot | ||
sercat | ||
shutdown | ||
sysctl | ||
|
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,50 +1,58 @@ | ||
/* | ||
* shutdown.c | ||
* reboot/shutdown/poweroff | ||
* | ||
* Derived from reboot.c by: | ||
* Original version from | ||
* 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. | ||
*/ | ||
|
||
/* | ||
* This is a small version of shutdown for use in the ELKS project. | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <errno.h> | ||
#include <string.h> | ||
#include <sys/mount.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; | ||
sync(); | ||
for (i = NR_SUPER - 1; i >= 0; --i) { | ||
ret = try_unmount(i); | ||
if (ret) return 1; | ||
} | ||
sleep(3); | ||
if (reboot(0x1D1E,0xC0DE,0x6789)) { | ||
perror("shutdown"); | ||
return 1; | ||
} | ||
return 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); | ||
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; | ||
} |