#define WRCRLF write(fd, "\r\n", 2)
#define ERRSTRING strerror(errno)
-#define UMOUNT_ARGS "umount", "-a", "-t", "nodevfs"
+#define UMOUNT_ARGS "umount", "-a", "-t", "nodevfs,devtmpfs"
#define SWAPOFF_ARGS "swapoff", "-a"
void
{
fprintf(stderr,
_("Usage: shutdown [-h|-r] [-fqs] [now|hh:ss|+mins]\n"));
- exit(1);
+ exit(EXIT_FAILURE);
}
static void
fflush(stdout);
}
-void
+void
int_handler(int sig)
{
unlink(_PATH_NOLOGIN);
signal(SIGINT, SIG_DFL);
my_puts(_("Shutdown process aborted"));
- _exit(1);
+ _exit(EXIT_FAILURE);
}
static int
textdomain(PACKAGE);
#ifndef DEBUGGING
- if(setreuid (0, 0)) {
- fprintf(stderr, _("%s: Only root can shut a system down.\n"),
- argv[0]);
- exit(1);
- }
+ if(setreuid (0, 0))
+ errx(EXIT_FAILURE, _("only root can shut a system down."));
#endif
if(*argv[0] == '-') argv[0]++; /* allow shutdown as login shell */
opt_fast = 0;
timeout = 2*60;
}
-
+
c = 0;
while(++c < argc) {
if(argv[c][0] == '-') {
case 'C':
opt_use_config_file = 1;
break;
- case 'h':
+ case 'h':
opt_reboot = 0;
break;
case 'r':
break;
case 's':
opt_single = 1;
- break;
-
+
default:
usage();
}
time_t tics;
struct tm *tt;
int now, then;
-
+
if((colon = strchr(argv[c], ':'))) {
*colon = '\0';
hour = atoi(argv[c]);
minute = atoi(++colon);
} else usage();
-
+
(void) time(&tics);
tt = localtime(&tics);
-
+
now = 3600 * tt->tm_hour + 60 * tt->tm_min;
then = 3600 * hour + 60 * minute;
timeout = then - now;
- if(timeout < 0) {
- fprintf(stderr, _("That must be tomorrow, "
- "can't you wait till then?\n"));
- exit(1);
- }
+ if(timeout < 0)
+ errx(EXIT_FAILURE, _("that must be tomorrow, "
+ "can't you wait till then?"));
} else {
xstrncpy(message, argv[c], sizeof(message));
opt_msgset = 1;
/* now ask for message, gets() is insecure */
int cnt = sizeof(message)-1;
char *ptr;
-
+
printf("Why? "); fflush(stdout);
-
+
ptr = message;
- while(--cnt >= 0 && (*ptr = getchar()) && *ptr != '\n') {
+ while(--cnt >= 0 && (*ptr = getchar()) && *ptr != '\n') {
ptr++;
}
*ptr = '\0';
printf("timeout = %d, quiet = %d, reboot = %d\n",
timeout, opt_quiet, opt_reboot);
#endif
-
+
/* so much for option-processing, now begin termination... */
if(!(whom = getlogin()) || !*whom) whom = "ghost";
if(strlen(whom) > 40) whom[40] = 0; /* see write_user() */
timeout = 5*60;
}
-
if((fd = open(_PATH_NOLOGIN, O_WRONLY|O_CREAT, 0644)) >= 0) {
/* keep xgettext happy and leave \r\n outside strings */
WRCRLF;
WRCRLF;
close(fd);
}
-
+
signal(SIGPIPE, SIG_IGN);
if(timeout > 0) {
if(opt_single)
if((fd = open(_PATH_SINGLE, O_CREAT|O_WRONLY, 0644)) >= 0)
close(fd);
-
+
sync();
signal(SIGTERM, SIG_IGN);
do_halt(halt_action);
}
/* NOTREACHED */
- exit(0); /* to quiet gcc */
+ exit(EXIT_SUCCESS); /* to quiet gcc */
}
/*** end of main() ***/
{
/* write to all users, that the system is going down. */
struct utmp *ut;
-
+
utmpname(_PATH_UTMP);
setutent();
-
+
while((ut = getutent())) {
if(ut->ut_type == USER_PROCESS)
write_user(ut);
/* write in wtmp that we are dying */
int fd;
struct utmp ut;
-
+
memset((char *)&ut, 0, sizeof(ut));
strcpy(ut.ut_line, "~");
memcpy(ut.ut_name, "shutdown", sizeof(ut.ut_name));
time(&ut.ut_time);
ut.ut_type = BOOT_TIME;
-
+
if((fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0644)) >= 0) {
write(fd, (char *)&ut, sizeof(ut));
close(fd);
execlp("swapoff", SWAPOFF_ARGS, NULL);
my_puts(_("Cannot exec swapoff, "
"hoping umount will do the trick."));
- exit(0);
+ exit(EXIT_SUCCESS);
}
while ((result = wait(&status)) != -1 && result != pid)
;
execlp("umount", UMOUNT_ARGS, NULL);
my_puts(_("Cannot exec umount, giving up on umount."));
- exit(0);
+ exit(EXIT_SUCCESS);
}
while ((result = wait(&status)) != -1 && result != pid)
;
int i;
int n;
char *filesys;
-
+
sync();
if (!(mtab = setmntent(_PATH_MOUNTED, "r"))) {
my_puts("shutdown: Cannot open " _PATH_MOUNTED ".");