diff options
| author | Michael Forney <mforney@mforney.org> | 2021-07-24 18:04:04 -0700 |
|---|---|---|
| committer | Michael Forney <mforney@mforney.org> | 2021-07-24 18:08:16 -0700 |
| commit | 995b307746340db5a569d8c0f35f3a9938838d46 (patch) | |
| tree | 3f0b9b1367e70f3d2ef67ea4b000ef9043801fa5 /src | |
| parent | d7116615c1f14c90a5d30088910a8f62e853ae89 (diff) | |
Move shutdown helper to sinit package
Diffstat (limited to 'src')
| -rw-r--r-- | src/gen.lua | 1 | ||||
| -rw-r--r-- | src/shutdown.c | 87 |
2 files changed, 0 insertions, 88 deletions
diff --git a/src/gen.lua b/src/gen.lua index 0567ffd2..e2a04f5a 100644 --- a/src/gen.lua +++ b/src/gen.lua @@ -5,4 +5,3 @@ cflags{ file('libexec/applyperms', '755', exe('applyperms', {'applyperms.c'})) file('libexec/mergeperms', '755', exe('mergeperms', {'mergeperms.c'})) -file('libexec/shutdown', '755', exe('shutdown', {'shutdown.c'})) diff --git a/src/shutdown.c b/src/shutdown.c deleted file mode 100644 index 87ddc010..00000000 --- a/src/shutdown.c +++ /dev/null @@ -1,87 +0,0 @@ -/* See LICENSE file for copyright and license details. */ -#define _XOPEN_SOURCE 700 -#include <errno.h> -#include <mntent.h> -#include <signal.h> -#include <stdio.h> -#include <stdlib.h> -#include <stdnoreturn.h> -#include <string.h> -#include <sys/mount.h> -#include <sys/reboot.h> -#include <unistd.h> - -static noreturn void -usage(void) -{ - fprintf(stderr, "usage: shutdown [-hpr]\n"); - exit(2); -} - -int -main(int argc, char *argv[]) -{ - FILE *fp; - char **dirs = NULL; - size_t n = 0; - struct mntent *mnt; - int cmd = RB_POWER_OFF; - - while (*++argv && (*argv)[0] == '-' && (*argv)[1]) { - switch ((*argv)[1]) { - case 'h': - cmd = RB_HALT_SYSTEM; - break; - case 'p': - cmd = RB_POWER_OFF; - break; - case 'r': - cmd = RB_AUTOBOOT; - break; - default: - usage(); - } - } - if (*argv) - usage(); - - if (getsid(0) != getpid()) { - fprintf(stderr, "must be session leader\n"); - return 1; - } - - sync(); - kill(-1, SIGTERM); - sleep(2); - kill(-1, SIGKILL); - - sync(); - fp = setmntent("/proc/mounts", "r"); - if (!fp) { - perror("setmntent"); - goto reboot; - } - while ((mnt = getmntent(fp))) { - if (!(dirs = realloc(dirs, ++n * sizeof(*dirs)))) { - perror("realloc"); - break; - } - if (!(dirs[n - 1] = strdup(mnt->mnt_dir))) { - perror("strdup"); - break; - } - } - endmntent(fp); - while (n) { - if (umount(dirs[--n]) < 0) - fprintf(stderr, "umount %s: %s\n", dirs[n], strerror(errno)); - free(dirs[n]); - } - free(dirs); - -reboot: - if (reboot(cmd) < 0) { - perror("reboot"); - return 1; - } -} |
