Lines Matching +full:reboot +full:- +full:mode

1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
40 #include <sys/reboot.h>
125 static bool Reboot = false; variable
152 char *se_getty_argv_space; /* pre-parsed argument array space */
153 char **se_getty_argv; /* pre-parsed argument array */
155 char *se_window_argv_space; /* pre-parsed argument array space */
156 char **se_window_argv; /* pre-parsed argument array */
217 case '1': /* single-user */ in main()
220 case '6': /* reboot */ in main()
239 errx(1, "invalid run-level ``%s''", argv[1]); in main()
272 while ((c = getopt(argc, argv, "dsfr")) != -1) in main()
287 warning("unrecognized flag '-%c'", c); in main()
323 _exit(0); /* reboot */ in main()
378 if (i > 0 && s[i - 1] == '/') in main()
379 s[i - 1] = '\0'; in main()
507 _exit(sig); /* reboot */ in disaster()
523 if (sysctl(name, 2, &curlevel, &len, NULL, 0) == -1) { in getsecuritylevel()
525 return (-1); in getsecuritylevel()
529 return (-1); in getsecuritylevel()
547 if (sysctl(name, 2, NULL, NULL, &newlevel, sizeof newlevel) == -1) { in setsecuritylevel()
587 if ((fd = open(_PATH_CONSOLE, O_RDWR | O_NONBLOCK)) != -1) { in open_console()
595 if ((fd = open(_PATH_DEVNULL, O_RDWR)) == -1) { in open_console()
604 if (fd == -1) in open_console()
643 return (-1); in read_file()
691 return (-1); in create_file()
698 return (-1); in create_file()
704 return (-1); in create_file()
721 __DECONST(void *, "tmpfs"), (size_t)-1); in mount_tmpfs()
723 __DECONST(void *, fspath), (size_t)-1); in mount_tmpfs()
759 error = kill(-1, SIGKILL); in reroot()
782 execl(_PATH_REROOT_INIT, _PATH_REROOT_INIT, "-r", NULL); in reroot()
786 emergency("reroot failed; going to single user mode"); in reroot()
801 error = reboot(RB_REROOT); in reroot_phase_two()
838 emergency("reroot failed; going to single user mode"); in reroot_phase_two()
858 "Enter root password, or ^D to go multi-user\n"; in single_user()
865 if (Reboot) { in single_user()
866 /* Instead of going single user, let's reboot the machine */ in single_user()
871 if (reboot(howto) == -1) { in single_user()
872 emergency("reboot(%#x) failed, %m", howto); in single_user()
873 _exit(1); /* panic and reboot */ in single_user()
875 warning("reboot(%#x) returned", howto); in single_user()
879 BOOTTRACE("going to single user mode"); in single_user()
896 if (typ && (typ->ty_status & TTY_SECURE) == 0 && in single_user()
897 pp && *pp->pw_passwd) { in single_user()
903 password = crypt(clear, pp->pw_passwd); in single_user()
906 strcmp(password, pp->pw_passwd) == 0) in single_user()
908 warning("single-user login failed\n"); in single_user()
924 while ((num = read(STDIN_FILENO, cp, 1)) != -1 && in single_user()
946 char name[] = "-sh"; in single_user()
958 if (pid == -1) { in single_user()
962 emergency("can't fork single-user shell, trying again"); in single_user()
963 while (waitpid(-1, (int *) 0, WNOHANG) > 0) in single_user()
970 if ((wpid = waitpid(-1, &status, WUNTRACED)) != -1) in single_user()
972 if (wpid == -1) { in single_user()
975 warning("wait for single-user shell failed: %m; restarting"); in single_user()
981 wpid = -1; in single_user()
991 * reboot(8) killed shell? in single_user()
1071 sh_argv[1] = __DECONST(char*, "-o"); in execute_script()
1099 * - single_user if fork/execv/waitpid failed, or if the script
1101 * - death_single if a SIGTERM was delivered to init(8).
1123 _exit(1); /* force single user mode */ in run_script()
1126 if (pid == -1) { in run_script()
1128 while (waitpid(-1, (int *) 0, WNOHANG) > 0) in run_script()
1139 if ((wpid = waitpid(-1, &status, WUNTRACED)) != -1) in run_script()
1144 if (wpid == -1) { in run_script()
1148 "single user mode", shell, script); in run_script()
1155 wpid = -1; in run_script()
1161 /* /etc/rc executed /sbin/reboot; wait for the end quietly */ in run_script()
1171 "user mode", shell, script); in run_script()
1189 if (session_db && (*session_db->close)(session_db)) in start_session_db()
1208 key.data = &sp->se_process; in add_session()
1209 key.size = sizeof sp->se_process; in add_session()
1213 if ((*session_db->put)(session_db, &key, &data, 0)) in add_session()
1214 emergency("insert %d: %m", sp->se_process); in add_session()
1225 key.data = &sp->se_process; in del_session()
1226 key.size = sizeof sp->se_process; in del_session()
1228 if ((*session_db->del)(session_db, &key, 0)) in del_session()
1229 emergency("delete %d: %m", sp->se_process); in del_session()
1244 if ((*session_db->get)(session_db, &key, &data, 0) != 0) in find_session()
1275 free(sp->se_device); in free_session()
1276 if (sp->se_getty) { in free_session()
1277 free(sp->se_getty); in free_session()
1278 free(sp->se_getty_argv_space); in free_session()
1279 free(sp->se_getty_argv); in free_session()
1281 if (sp->se_window) { in free_session()
1282 free(sp->se_window); in free_session()
1283 free(sp->se_window_argv_space); in free_session()
1284 free(sp->se_window_argv); in free_session()
1286 if (sp->se_type) in free_session()
1287 free(sp->se_type); in free_session()
1300 if ((typ->ty_status & TTY_ON) == 0 || in new_session()
1301 typ->ty_name == 0 || in new_session()
1302 typ->ty_getty == 0) in new_session()
1307 sp->se_flags |= SE_PRESENT; in new_session()
1309 if ((typ->ty_status & TTY_IFEXISTS) != 0) in new_session()
1310 sp->se_flags |= SE_IFEXISTS; in new_session()
1312 if ((typ->ty_status & TTY_IFCONSOLE) != 0) in new_session()
1313 sp->se_flags |= SE_IFCONSOLE; in new_session()
1315 if (asprintf(&sp->se_device, "%s%s", _PATH_DEV, typ->ty_name) < 0) in new_session()
1323 sp->se_next = 0; in new_session()
1326 sp->se_prev = 0; in new_session()
1328 sprev->se_next = sp; in new_session()
1329 sp->se_prev = sprev; in new_session()
1342 if (sp->se_getty) { in setupargv()
1343 free(sp->se_getty); in setupargv()
1344 free(sp->se_getty_argv_space); in setupargv()
1345 free(sp->se_getty_argv); in setupargv()
1347 if (asprintf(&sp->se_getty, "%s %s", typ->ty_getty, typ->ty_name) < 0) in setupargv()
1349 sp->se_getty_argv_space = strdup(sp->se_getty); in setupargv()
1350 sp->se_getty_argv = construct_argv(sp->se_getty_argv_space); in setupargv()
1351 if (sp->se_getty_argv == NULL) { in setupargv()
1352 warning("can't parse getty for port %s", sp->se_device); in setupargv()
1353 free(sp->se_getty); in setupargv()
1354 free(sp->se_getty_argv_space); in setupargv()
1355 sp->se_getty = sp->se_getty_argv_space = 0; in setupargv()
1358 if (sp->se_window) { in setupargv()
1359 free(sp->se_window); in setupargv()
1360 free(sp->se_window_argv_space); in setupargv()
1361 free(sp->se_window_argv); in setupargv()
1363 sp->se_window = sp->se_window_argv_space = 0; in setupargv()
1364 sp->se_window_argv = 0; in setupargv()
1365 if (typ->ty_window) { in setupargv()
1366 sp->se_window = strdup(typ->ty_window); in setupargv()
1367 sp->se_window_argv_space = strdup(sp->se_window); in setupargv()
1368 sp->se_window_argv = construct_argv(sp->se_window_argv_space); in setupargv()
1369 if (sp->se_window_argv == NULL) { in setupargv()
1371 sp->se_device); in setupargv()
1372 free(sp->se_window_argv_space); in setupargv()
1373 free(sp->se_window); in setupargv()
1374 sp->se_window = sp->se_window_argv_space = 0; in setupargv()
1378 if (sp->se_type) in setupargv()
1379 free(sp->se_type); in setupargv()
1380 sp->se_type = typ->ty_type ? strdup(typ->ty_type) : 0; in setupargv()
1398 snext = sp->se_next; in read_ttys()
1429 if ((pid = fork()) == -1) { in start_window_system()
1431 sp->se_device); in start_window_system()
1436 waitpid(-1, &status, 0); in start_window_system()
1441 if ((pid = fork()) == -1) { in start_window_system()
1443 sp->se_device); in start_window_system()
1458 if (sp->se_type) { in start_window_system()
1461 strlcat(term, sp->se_type, sizeof(term)); in start_window_system()
1467 execve(sp->se_window_argv[0], sp->se_window_argv, env); in start_window_system()
1469 sp->se_window_argv[0], sp->se_device); in start_window_system()
1485 if (current_time >= sp->se_started && in start_getty()
1486 current_time - sp->se_started < GETTY_SPACING) { in start_getty()
1487 if (++sp->se_nspace > GETTY_NSPACE) { in start_getty()
1488 sp->se_nspace = 0; in start_getty()
1492 sp->se_nspace = 0; in start_getty()
1495 * fork(), not vfork() -- we can't afford to block. in start_getty()
1497 if ((pid = fork()) == -1) { in start_getty()
1498 emergency("can't fork for getty on port %s: %m", sp->se_device); in start_getty()
1499 return -1; in start_getty()
1507 sp->se_device, GETTY_SLEEP); in start_getty()
1511 if (sp->se_window) { in start_getty()
1522 if (sp->se_type) { in start_getty()
1525 strlcat(term, sp->se_type, sizeof(term)); in start_getty()
1530 execve(sp->se_getty_argv[0], sp->se_getty_argv, env); in start_getty()
1532 sp->se_getty_argv[0], sp->se_device); in start_getty()
1545 if ((sp->se_flags & SE_IFEXISTS) == 0 && in session_has_no_tty()
1546 (sp->se_flags & SE_IFCONSOLE) == 0) in session_has_no_tty()
1549 fd = open(sp->se_device, O_RDONLY | O_NONBLOCK, 0); in session_has_no_tty()
1576 sp->se_process = 0; in collect_child()
1578 if (sp->se_flags & SE_SHUTDOWN || in collect_child()
1580 if ((sprev = sp->se_prev) != NULL) in collect_child()
1581 sprev->se_next = sp->se_next; in collect_child()
1583 sessions = sp->se_next; in collect_child()
1584 if ((snext = sp->se_next) != NULL) in collect_child()
1585 snext->se_prev = sp->se_prev; in collect_child()
1590 if ((pid = start_getty(sp)) == -1) { in collect_child()
1596 sp->se_process = pid; in collect_child()
1597 sp->se_started = time((time_t *) 0); in collect_child()
1606 return ("single-user"); in get_current_state()
1610 return ("read-ttys"); in get_current_state()
1612 return ("multi-user"); in get_current_state()
1614 return ("clean-ttys"); in get_current_state()
1620 return ("death-single"); in get_current_state()
1637 action = "reboot"; in boottrace_transition()
1643 action = Reboot ? "reboot" : "single-user"; in boottrace_transition()
1676 Reboot = true; in transition_handler()
1712 * If the administrator has not set the security level to -1 in multi_user()
1714 * mode, and the run script has not set a higher level of security in multi_user()
1715 * than level 1, then put the kernel into secure mode. in multi_user()
1720 for (sp = sessions; sp; sp = sp->se_next) { in multi_user()
1721 if (sp->se_process) in multi_user()
1725 if ((pid = start_getty(sp)) == -1) { in multi_user()
1730 sp->se_process = pid; in multi_user()
1731 sp->se_started = time((time_t *) 0); in multi_user()
1737 /* This marks the change from boot-time tracing to run-time. */ in multi_user()
1738 RUNTRACE("multi-user start"); in multi_user()
1741 if ((pid = waitpid(-1, (int *) 0, 0)) != -1) in multi_user()
1763 for (sp = sessions; sp != NULL; sp = sp->se_next) in clean_ttys()
1764 sp->se_flags &= ~SE_PRESENT; in clean_ttys()
1766 devlen = sizeof(_PATH_DEV) - 1; in clean_ttys()
1768 for (sprev = 0, sp = sessions; sp; sprev = sp, sp = sp->se_next) in clean_ttys()
1769 if (strcmp(typ->ty_name, sp->se_device + devlen) == 0) in clean_ttys()
1774 sp->se_flags |= SE_PRESENT; in clean_ttys()
1775 if ((typ->ty_status & TTY_ON) == 0 || in clean_ttys()
1776 typ->ty_getty == 0) { in clean_ttys()
1777 sp->se_flags |= SE_SHUTDOWN; in clean_ttys()
1778 kill(sp->se_process, SIGHUP); in clean_ttys()
1781 sp->se_flags &= ~SE_SHUTDOWN; in clean_ttys()
1782 old_getty = sp->se_getty ? strdup(sp->se_getty) : 0; in clean_ttys()
1783 old_window = sp->se_window ? strdup(sp->se_window) : 0; in clean_ttys()
1784 old_type = sp->se_type ? strdup(sp->se_type) : 0; in clean_ttys()
1787 sp->se_device); in clean_ttys()
1788 sp->se_flags |= SE_SHUTDOWN; in clean_ttys()
1789 kill(sp->se_process, SIGHUP); in clean_ttys()
1792 || (!old_type && sp->se_type) in clean_ttys()
1793 || (old_type && !sp->se_type) in clean_ttys()
1794 || (!old_window && sp->se_window) in clean_ttys()
1795 || (old_window && !sp->se_window) in clean_ttys()
1796 || (strcmp(old_getty, sp->se_getty) != 0) in clean_ttys()
1797 || (old_window && strcmp(old_window, sp->se_window) != 0) in clean_ttys()
1798 || (old_type && strcmp(old_type, sp->se_type) != 0) in clean_ttys()
1801 sp->se_nspace = 0; in clean_ttys()
1802 sp->se_started = 0; in clean_ttys()
1803 kill(sp->se_process, SIGHUP); in clean_ttys()
1823 for (sp = sessions; sp != NULL; sp = sp->se_next) { in clean_ttys()
1824 if ((sp->se_flags & SE_PRESENT) == 0) { in clean_ttys()
1825 sp->se_flags |= SE_SHUTDOWN; in clean_ttys()
1826 kill(sp->se_process, SIGHUP); in clean_ttys()
1841 for (sp = sessions; sp; sp = sp->se_next) in catatonia()
1842 sp->se_flags |= SE_SHUTDOWN; in catatonia()
1871 &block, sizeof(block)) == -1) in death()
1894 * Do what is necessary to reinitialize single user mode or reboot
1908 if (kill(-1, death_sigs[i]) == -1 && errno == ESRCH) in death_single()
1914 if ((pid = waitpid(-1, (int *)0, 0)) != -1) in death_single()
1932 for (sp = sessions; sp; sp = sp->se_next) { in revoke_ttys()
1933 sp->se_flags |= SE_SHUTDOWN; in revoke_ttys()
1934 kill(sp->se_process, SIGHUP); in revoke_ttys()
1935 revoke(sp->se_device); in revoke_ttys()
1943 * -2 shutdown script terminated abnormally
1944 * -1 fatal error - can't run script
1966 if (stat(_PATH_RUNDOWN, &sb) == -1 && errno == ENOENT) in runshutdown()
1970 char _reboot[] = "reboot"; in runshutdown()
1975 argv[1] = Reboot ? _reboot : _single; in runshutdown()
1979 _exit(1); /* force single user mode */ in runshutdown()
1982 if (pid == -1) { in runshutdown()
1984 while (waitpid(-1, (int *) 0, WNOHANG) > 0) in runshutdown()
1987 return -1; in runshutdown()
1992 NULL, 0) == -1 || shutdowntimeout < 2) in runshutdown()
2001 if ((wpid = waitpid(-1, &status, WUNTRACED)) != -1) in runshutdown()
2004 /* we were waiting for the sub-shell */ in runshutdown()
2007 "single user mode", _PATH_RUNDOWN); in runshutdown()
2010 return -1; in runshutdown()
2012 if (wpid == -1) { in runshutdown()
2016 "single user mode", _PATH_RUNDOWN); in runshutdown()
2017 return -1; in runshutdown()
2023 wpid = -1; in runshutdown()
2033 * /etc/rc.shutdown executed /sbin/reboot; in runshutdown()
2045 "single user mode", _PATH_RUNDOWN); in runshutdown()
2046 return -2; in runshutdown()
2124 if (stat(_PATH_RUNFINAL, &sb) == -1 && errno == ENOENT) in runfinal()
2152 while ((other_pid = waitpid(-1, NULL, 0)) != pid && other_pid > 0) { in runfinal()