init.c (85010) | init.c (92806) |
---|---|
1/*- 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Donn Seeley at Berkeley Software Design, Inc. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 31 unchanged lines hidden (view full) --- 40 The Regents of the University of California. All rights reserved.\n"; 41#endif /* not lint */ 42 43#ifndef lint 44#if 0 45static char sccsid[] = "@(#)init.c 8.1 (Berkeley) 7/15/93"; 46#endif 47static const char rcsid[] = | 1/*- 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Donn Seeley at Berkeley Software Design, Inc. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 31 unchanged lines hidden (view full) --- 40 The Regents of the University of California. All rights reserved.\n"; 41#endif /* not lint */ 42 43#ifndef lint 44#if 0 45static char sccsid[] = "@(#)init.c 8.1 (Berkeley) 7/15/93"; 46#endif 47static const char rcsid[] = |
48 "$FreeBSD: head/sbin/init/init.c 85010 2001-10-15 20:34:43Z des $"; | 48 "$FreeBSD: head/sbin/init/init.c 92806 2002-03-20 17:55:10Z obrien $"; |
49#endif /* not lint */ 50 51#include <sys/param.h> 52#include <sys/ioctl.h> 53#include <sys/mount.h> 54#include <sys/sysctl.h> 55#include <sys/wait.h> 56#include <sys/stat.h> --- 148 unchanged lines hidden (view full) --- 205 errx(1, "%s", strerror(EPERM)); 206 207 /* System V users like to reexec init. */ 208 if (getpid() != 1) { 209#ifdef COMPAT_SYSV_INIT 210 /* So give them what they want */ 211 if (argc > 1) { 212 if (strlen(argv[1]) == 1) { | 49#endif /* not lint */ 50 51#include <sys/param.h> 52#include <sys/ioctl.h> 53#include <sys/mount.h> 54#include <sys/sysctl.h> 55#include <sys/wait.h> 56#include <sys/stat.h> --- 148 unchanged lines hidden (view full) --- 205 errx(1, "%s", strerror(EPERM)); 206 207 /* System V users like to reexec init. */ 208 if (getpid() != 1) { 209#ifdef COMPAT_SYSV_INIT 210 /* So give them what they want */ 211 if (argc > 1) { 212 if (strlen(argv[1]) == 1) { |
213 register char runlevel = *argv[1]; 214 register int sig; | 213 char runlevel = *argv[1]; 214 int sig; |
215 216 switch (runlevel) { 217 case '0': /* halt + poweroff */ 218 sig = SIGUSR2; 219 break; 220 case '1': /* single-user */ 221 sig = SIGTERM; 222 break; --- 716 unchanged lines hidden (view full) --- 939/* 940 * Construct an argument vector from a command line. 941 */ 942char ** 943construct_argv(command) 944 char *command; 945{ 946 char *strk (char *); | 215 216 switch (runlevel) { 217 case '0': /* halt + poweroff */ 218 sig = SIGUSR2; 219 break; 220 case '1': /* single-user */ 221 sig = SIGTERM; 222 break; --- 716 unchanged lines hidden (view full) --- 939/* 940 * Construct an argument vector from a command line. 941 */ 942char ** 943construct_argv(command) 944 char *command; 945{ 946 char *strk (char *); |
947 register int argc = 0; 948 register char **argv = (char **) malloc(((strlen(command) + 1) / 2 + 1) | 947 int argc = 0; 948 char **argv = (char **) malloc(((strlen(command) + 1) / 2 + 1) |
949 * sizeof (char *)); 950 951 if ((argv[argc++] = strk(command)) == 0) { 952 free(argv); 953 return (NULL); 954 } 955 while ((argv[argc++] = strk((char *) 0)) != NULL) 956 continue; 957 return argv; 958} 959 960/* 961 * Deallocate a session descriptor. 962 */ 963void 964free_session(sp) | 949 * sizeof (char *)); 950 951 if ((argv[argc++] = strk(command)) == 0) { 952 free(argv); 953 return (NULL); 954 } 955 while ((argv[argc++] = strk((char *) 0)) != NULL) 956 continue; 957 return argv; 958} 959 960/* 961 * Deallocate a session descriptor. 962 */ 963void 964free_session(sp) |
965 register session_t *sp; | 965 session_t *sp; |
966{ 967 free(sp->se_device); 968 if (sp->se_getty) { 969 free(sp->se_getty); 970 free(sp->se_getty_argv_space); 971 free(sp->se_getty_argv); 972 } 973 if (sp->se_window) { --- 9 unchanged lines hidden (view full) --- 983/* 984 * Allocate a new session descriptor. 985 * Mark it SE_PRESENT. 986 */ 987session_t * 988new_session(sprev, session_index, typ) 989 session_t *sprev; 990 int session_index; | 966{ 967 free(sp->se_device); 968 if (sp->se_getty) { 969 free(sp->se_getty); 970 free(sp->se_getty_argv_space); 971 free(sp->se_getty_argv); 972 } 973 if (sp->se_window) { --- 9 unchanged lines hidden (view full) --- 983/* 984 * Allocate a new session descriptor. 985 * Mark it SE_PRESENT. 986 */ 987session_t * 988new_session(sprev, session_index, typ) 989 session_t *sprev; 990 int session_index; |
991 register struct ttyent *typ; | 991 struct ttyent *typ; |
992{ | 992{ |
993 register session_t *sp; | 993 session_t *sp; |
994 int fd; 995 996 if ((typ->ty_status & TTY_ON) == 0 || 997 typ->ty_name == 0 || 998 typ->ty_getty == 0) 999 return 0; 1000 1001 sp = (session_t *) calloc(1, sizeof (session_t)); --- 86 unchanged lines hidden (view full) --- 1088 1089/* 1090 * Walk the list of ttys and create sessions for each active line. 1091 */ 1092state_func_t 1093read_ttys() 1094{ 1095 int session_index = 0; | 994 int fd; 995 996 if ((typ->ty_status & TTY_ON) == 0 || 997 typ->ty_name == 0 || 998 typ->ty_getty == 0) 999 return 0; 1000 1001 sp = (session_t *) calloc(1, sizeof (session_t)); --- 86 unchanged lines hidden (view full) --- 1088 1089/* 1090 * Walk the list of ttys and create sessions for each active line. 1091 */ 1092state_func_t 1093read_ttys() 1094{ 1095 int session_index = 0; |
1096 register session_t *sp, *snext; 1097 register struct ttyent *typ; | 1096 session_t *sp, *snext; 1097 struct ttyent *typ; |
1098 1099 /* 1100 * Destroy any previous session state. 1101 * There shouldn't be any, but just in case... 1102 */ 1103 for (sp = sessions; sp; sp = snext) { 1104 if (sp->se_process) 1105 clear_session_logs(sp); --- 134 unchanged lines hidden (view full) --- 1240void 1241#ifdef __STDC__ 1242collect_child(pid_t pid) 1243#else 1244collect_child(pid) 1245 pid_t pid; 1246#endif 1247{ | 1098 1099 /* 1100 * Destroy any previous session state. 1101 * There shouldn't be any, but just in case... 1102 */ 1103 for (sp = sessions; sp; sp = snext) { 1104 if (sp->se_process) 1105 clear_session_logs(sp); --- 134 unchanged lines hidden (view full) --- 1240void 1241#ifdef __STDC__ 1242collect_child(pid_t pid) 1243#else 1244collect_child(pid) 1245 pid_t pid; 1246#endif 1247{ |
1248 register session_t *sp, *sprev, *snext; | 1248 session_t *sp, *sprev, *snext; |
1249 1250 if (! sessions) 1251 return; 1252 1253 if (! (sp = find_session(pid))) 1254 return; 1255 1256 clear_session_logs(sp); --- 54 unchanged lines hidden (view full) --- 1311 1312/* 1313 * Take the system multiuser. 1314 */ 1315state_func_t 1316multi_user() 1317{ 1318 pid_t pid; | 1249 1250 if (! sessions) 1251 return; 1252 1253 if (! (sp = find_session(pid))) 1254 return; 1255 1256 clear_session_logs(sp); --- 54 unchanged lines hidden (view full) --- 1311 1312/* 1313 * Take the system multiuser. 1314 */ 1315state_func_t 1316multi_user() 1317{ 1318 pid_t pid; |
1319 register session_t *sp; | 1319 session_t *sp; |
1320 1321 requested_transition = 0; 1322 1323 /* 1324 * If the administrator has not set the security level to -1 1325 * to indicate that the kernel should not run multiuser in secure 1326 * mode, and the run script has not set a higher level of security 1327 * than level 1, then put the kernel into secure mode. --- 22 unchanged lines hidden (view full) --- 1350} 1351 1352/* 1353 * This is an (n*2)+(n^2) algorithm. We hope it isn't run often... 1354 */ 1355state_func_t 1356clean_ttys() 1357{ | 1320 1321 requested_transition = 0; 1322 1323 /* 1324 * If the administrator has not set the security level to -1 1325 * to indicate that the kernel should not run multiuser in secure 1326 * mode, and the run script has not set a higher level of security 1327 * than level 1, then put the kernel into secure mode. --- 22 unchanged lines hidden (view full) --- 1350} 1351 1352/* 1353 * This is an (n*2)+(n^2) algorithm. We hope it isn't run often... 1354 */ 1355state_func_t 1356clean_ttys() 1357{ |
1358 register session_t *sp, *sprev; 1359 register struct ttyent *typ; 1360 register int session_index = 0; 1361 register int devlen; | 1358 session_t *sp, *sprev; 1359 struct ttyent *typ; 1360 int session_index = 0; 1361 int devlen; |
1362 char *old_getty, *old_window, *old_type; 1363 1364 if (! sessions) 1365 return (state_func_t) multi_user; 1366 1367 /* 1368 * mark all sessions for death, (!SE_PRESENT) 1369 * as we find or create new ones they'll be marked as keepers, --- 78 unchanged lines hidden (view full) --- 1448} 1449 1450/* 1451 * Block further logins. 1452 */ 1453state_func_t 1454catatonia() 1455{ | 1362 char *old_getty, *old_window, *old_type; 1363 1364 if (! sessions) 1365 return (state_func_t) multi_user; 1366 1367 /* 1368 * mark all sessions for death, (!SE_PRESENT) 1369 * as we find or create new ones they'll be marked as keepers, --- 78 unchanged lines hidden (view full) --- 1448} 1449 1450/* 1451 * Block further logins. 1452 */ 1453state_func_t 1454catatonia() 1455{ |
1456 register session_t *sp; | 1456 session_t *sp; |
1457 1458 for (sp = sessions; sp; sp = sp->se_next) 1459 sp->se_flags |= SE_SHUTDOWN; 1460 1461 return (state_func_t) multi_user; 1462} 1463 1464/* --- 8 unchanged lines hidden (view full) --- 1473} 1474 1475/* 1476 * Bring the system down to single user. 1477 */ 1478state_func_t 1479death() 1480{ | 1457 1458 for (sp = sessions; sp; sp = sp->se_next) 1459 sp->se_flags |= SE_SHUTDOWN; 1460 1461 return (state_func_t) multi_user; 1462} 1463 1464/* --- 8 unchanged lines hidden (view full) --- 1473} 1474 1475/* 1476 * Bring the system down to single user. 1477 */ 1478state_func_t 1479death() 1480{ |
1481 register session_t *sp; 1482 register int i; | 1481 session_t *sp; 1482 int i; |
1483 pid_t pid; 1484 static const int death_sigs[2] = { SIGTERM, SIGKILL }; 1485 1486 /* NB: should send a message to the session logger to avoid blocking. */ 1487 logwtmp("~", "shutdown", ""); 1488 1489 for (sp = sessions; sp; sp = sp->se_next) { 1490 sp->se_flags |= SE_SHUTDOWN; --- 221 unchanged lines hidden --- | 1483 pid_t pid; 1484 static const int death_sigs[2] = { SIGTERM, SIGKILL }; 1485 1486 /* NB: should send a message to the session logger to avoid blocking. */ 1487 logwtmp("~", "shutdown", ""); 1488 1489 for (sp = sessions; sp; sp = sp->se_next) { 1490 sp->se_flags |= SE_SHUTDOWN; --- 221 unchanged lines hidden --- |