// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // // Copyright (c) 2002-2005, Haiku // // This software is part of the Haiku distribution and is covered // by the MIT license. // // File: shutdown.cpp // Author: Francois Revol (mmu_man@users.sf.net) // Description: shuts down the system, either halting or rebooting. // // Notes: // This program behaves identically as the BeOS R5 version, with these // added arguments: // // -a asks the user to confirm the shutdown // -c cancels any running shutdown // // Some code from Shard's Archiver from BeBits (was BSD/MIT too :). // // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ #include #include #include #include #include #include #include #include #include #include uint32 gTimeToSleep = 0; bool gReboot = false; // we get here when shutdown is cancelled. // then sleep() returns void handle_usr1(int sig) { while (0); } bool parseTime(char *arg, char *argv, int32 *_i) { char *unit; if (isdigit(arg[0])) { gTimeToSleep = strtoul(arg, &unit, 10); } else if (argv && isdigit(argv[0])) { (*_i)++; gTimeToSleep = strtoul(argv, &unit, 10); } else return false; if (unit[0] == '\0' || !strcmp(unit, "s")) return true; if (!strcmp(unit, "m")) { gTimeToSleep *= 60; return true; } return false; } void usage(const char *arg0) { const char *program = strrchr(arg0, '/'); if (program == NULL) program = arg0; else program++; fprintf(stderr, "usage: %s [-rqca] [-d time]\n" "\t-r reboot,\n" "\t-q quick shutdown (don't broadcast apps),\n" "\t-a ask user to confirm the shutdown (ignored when -q is given),\n" "\t-c cancel a running shutdown,\n" "\t-d delay shutdown by