From: | "Alexander 'alxl' Lobachov" <alxl@xxxxxxxxx> |
Date: | Thu, 21 Jul 2005 19:30:00 +0300 |
- deregister variables - use STDERR_FILENO instead of numeric value - apply some style(9) -- Alexander 'alxl' Lobachov mailto:alxl@xxxxxxxxx KeyID: 0x0ACA53C6 Key fingerprint: 8C07 4350 C429 C4E6 B4A9 BF59 1103 9E47 0ACA 53C6
--- src/sbin/init/init.c.OLD 2005-07-21 16:46:33.000000000 +0300 +++ src/sbin/init/init.c 2005-07-21 19:00:21.000000000 +0300 @@ -81,12 +81,12 @@ /* * Sleep times; used to prevent thrashing. */ -#define GETTY_SPACING 5 /* N secs minimum getty spacing */ -#define GETTY_SLEEP 30 /* sleep N secs after spacing problem */ -#define GETTY_NSPACE 3 /* max. spacing count to bring reaction */ -#define WINDOW_WAIT 3 /* wait N secs after starting window */ -#define STALL_TIMEOUT 30 /* wait N secs after warning */ -#define DEATH_WATCH 10 /* wait N secs for procs to die */ +#define GETTY_SPACING 5 /* N secs minimum getty spacing */ +#define GETTY_SLEEP 30 /* sleep N secs after spacing problem */ +#define GETTY_NSPACE 3 /* max. spacing count to bring reaction */ +#define WINDOW_WAIT 3 /* wait N secs after starting window */ +#define STALL_TIMEOUT 30 /* wait N secs after warning */ +#define DEATH_WATCH 10 /* wait N secs for procs to die */ #define DEATH_SCRIPT 120 /* wait for 2min for /etc/rc.shutdown */ #define RESOURCE_RC "daemon" #define RESOURCE_WINDOW "default" @@ -191,7 +191,6 @@ main(int argc, char **argv) sigset_t mask; struct stat sts; - /* Dispose of random users. */ if (getuid() != 0) errx(1, "%s", strerror(EPERM)); @@ -202,8 +201,8 @@ main(int argc, char **argv) /* So give them what they want */ if (argc > 1) { if (strlen(argv[1]) == 1) { - register char runlevel = *argv[1]; - register int sig; + char runlevel = *argv[1]; + int sig; switch (runlevel) { case '0': /* halt + poweroff */ @@ -306,7 +305,7 @@ invalid: delset(&mask, SIGABRT, SIGFPE, SIGILL, SIGSEGV, SIGBUS, SIGSYS, SIGXCPU, SIGXFSZ, SIGHUP, SIGINT, SIGTERM, SIGTSTP, SIGALRM, SIGUSR1, SIGUSR2, 0); - sigprocmask(SIG_SETMASK, &mask, (sigset_t *) 0); + sigprocmask(SIG_SETMASK, &mask, (sigset_t *)0); sigemptyset(&sa.sa_mask); sa.sa_flags = 0; sa.sa_handler = SIG_IGN; @@ -328,7 +327,7 @@ invalid: /* * Should never reach here. */ - return 1; + return(1); } /* @@ -351,7 +350,7 @@ handle(sig_t handler, ...) sa.sa_mask = mask_everything; /* XXX SA_RESTART? */ sa.sa_flags = sig == SIGCHLD ? SA_NOCLDSTOP : 0; - sigaction(sig, &sa, (struct sigaction *) 0); + sigaction(sig, &sa, (struct sigaction *)0); } va_end(ap); } @@ -461,15 +460,15 @@ getsecuritylevel(void) name[0] = CTL_KERN; name[1] = KERN_SECURELVL; - len = sizeof curlevel; + len = sizeof(curlevel); if (sysctl(name, 2, &curlevel, &len, NULL, 0) == -1) { emergency("cannot get kernel security level: %s", strerror(errno)); - return (-1); + return(-1); } - return (curlevel); + return(curlevel); #else - return (-1); + return(-1); #endif } @@ -493,11 +492,11 @@ get_chroot(void) oidlen = __arysize(real_oid); if (sysctlnametomib("kern.environment", real_oid, &oidlen)) { warning("cannot find kern.environment base sysctl OID"); - return NULL; + return(NULL); } if (oidlen + 1 >= __arysize(real_oid)) { warning("kern.environment OID is too large!"); - return NULL; + return(NULL); } res = NULL; real_oid[oidlen] = 0; @@ -541,7 +540,7 @@ setsecuritylevel(int newlevel) return; name[0] = CTL_KERN; name[1] = KERN_SECURELVL; - if (sysctl(name, 2, NULL, NULL, &newlevel, sizeof newlevel) == -1) { + if (sysctl(name, 2, NULL, NULL, &newlevel, sizeof(newlevel)) == -1) { emergency( "cannot change kernel security level from %d to %d: %s", curlevel, newlevel, strerror(errno)); @@ -562,7 +561,7 @@ static void transition(state_t s) { for (;;) - s = (state_t) (*s)(); + s = (state_t)(*s)(); } /* @@ -645,7 +644,7 @@ single_user(void) pp = getpwnam("root"); if (typ && (typ->ty_status & TTY_SECURE) == 0 && pp && *pp->pw_passwd) { - write(2, banner, sizeof banner - 1); + write(STDERR_FILENO, banner, sizeof(banner) - 1); for (;;) { clear = getpass("Password:"); if (clear == 0 || *clear == '\0') @@ -684,7 +683,7 @@ single_user(void) * and those are reset to SIG_DFL on exec. */ sigemptyset(&mask); - sigprocmask(SIG_SETMASK, &mask, (sigset_t *) 0); + sigprocmask(SIG_SETMASK, &mask, (sigset_t *)0); /* * Fire off a shell. @@ -705,9 +704,9 @@ single_user(void) * We are seriously hosed. Do our best. */ emergency("can't fork single-user shell, trying again"); - while (waitpid(-1, (int *) 0, WNOHANG) > 0) + while (waitpid(-1, (int *)0, WNOHANG) > 0) continue; - return (state_func_t) single_user; + return((state_func_t) single_user); } requested_transition = 0; @@ -718,7 +717,7 @@ single_user(void) if (errno == EINTR) continue; warning("wait for single-user shell failed: %m; restarting"); - return (state_func_t) single_user; + return((state_func_t) single_user); } if (wpid == pid && WIFSTOPPED(status)) { warning("init: shell stopped, restarting\n"); @@ -728,7 +727,7 @@ single_user(void) } while (wpid != pid && !requested_transition); if (requested_transition) - return (state_func_t) requested_transition; + return((state_func_t)requested_transition); if (!WIFEXITED(status)) { if (WTERMSIG(status) == SIGKILL) { @@ -740,12 +739,12 @@ single_user(void) _exit(0); } else { warning("single user shell terminated, restarting"); - return (state_func_t) single_user; + return((state_func_t)single_user); } } runcom_mode = FASTBOOT; - return (state_func_t) runcom; + return((state_func_t)runcom); } /* @@ -773,7 +772,7 @@ runcom(void) argv[2] = runcom_mode == AUTOBOOT ? "autoboot" : 0; argv[3] = 0; - sigprocmask(SIG_SETMASK, &sa.sa_mask, (sigset_t *) 0); + sigprocmask(SIG_SETMASK, &sa.sa_mask, (sigset_t *)0); #ifdef LOGIN_CAP setprocresources(RESOURCE_RC); @@ -786,10 +785,10 @@ runcom(void) if (pid == -1) { emergency("can't fork for %s on %s: %m", _PATH_BSHELL, _PATH_RUNCOM); - while (waitpid(-1, (int *) 0, WNOHANG) > 0) + while (waitpid(-1, (int *)0, WNOHANG) > 0) continue; sleep(STALL_TIMEOUT); - return (state_func_t) single_user; + return((state_func_t)single_user); } /* @@ -801,12 +800,12 @@ runcom(void) collect_child(wpid); if (wpid == -1) { if (requested_transition == death) - return (state_func_t) death; + return((state_func_t)death); if (errno == EINTR) continue; warning("wait for %s on %s failed: %m; going to single user mode", _PATH_BSHELL, _PATH_RUNCOM); - return (state_func_t) single_user; + return((state_func_t)single_user); } if (wpid == pid && WIFSTOPPED(status)) { warning("init: %s on %s stopped, restarting\n", @@ -829,16 +828,16 @@ runcom(void) if (!WIFEXITED(status)) { warning("%s on %s terminated abnormally, going to single user mode", _PATH_BSHELL, _PATH_RUNCOM); - return (state_func_t) single_user; + return((state_func_t)single_user); } if (WEXITSTATUS(status)) - return (state_func_t) single_user; + return((state_func_t)single_user); runcom_mode = AUTOBOOT; /* the default */ /* NB: should send a message to the session logger to avoid blocking. */ logwtmp("~", "reboot", ""); - return (state_func_t) read_ttys; + return((state_func_t)read_ttys); } /* @@ -853,9 +852,9 @@ start_session_db(void) emergency("session database close: %s", strerror(errno)); if ((session_db = dbopen(NULL, O_RDWR, 0, DB_HASH, NULL)) == 0) { emergency("session database open: %s", strerror(errno)); - return (1); + return(1); } - return (0); + return(0); } @@ -869,9 +868,9 @@ add_session(session_t *sp) DBT data; key.data = &sp->se_process; - key.size = sizeof sp->se_process; + key.size = sizeof(sp->se_process); data.data = &sp; - data.size = sizeof sp; + data.size = sizeof(sp); if ((*session_db->put)(session_db, &key, &data, 0)) emergency("insert %d: %s", sp->se_process, strerror(errno)); @@ -886,7 +885,7 @@ del_session(session_t *sp) DBT key; key.data = &sp->se_process; - key.size = sizeof sp->se_process; + key.size = sizeof(sp->se_process); if ((*session_db->del)(session_db, &key, 0)) emergency("delete %d: %s", sp->se_process, strerror(errno)); @@ -903,11 +902,11 @@ find_session(pid_t pid) session_t *ret; key.data = &pid; - key.size = sizeof pid; + key.size = sizeof(pid); if ((*session_db->get)(session_db, &key, &data, 0) != 0) - return 0; + return(0); bcopy(data.data, (char *)&ret, sizeof(ret)); - return ret; + return(ret); } /* @@ -918,22 +917,22 @@ construct_argv(char *command) { int argc = 0; char **argv = malloc(((strlen(command) + 1) / 2 + 1) - * sizeof (char *)); + * sizeof(char *)); if ((argv[argc++] = strk(command)) == 0) { free(argv); - return (NULL); + return(NULL); } - while ((argv[argc++] = strk((char *) 0)) != NULL) + while ((argv[argc++] = strk((char *)0)) != NULL) continue; - return argv; + return(argv); } /* * Deallocate a session descriptor. */ static void -free_session(register session_t *sp) +free_session(session_t *sp) { free(sp->se_device); if (sp->se_getty) { @@ -956,17 +955,17 @@ free_session(register session_t *sp) * Mark it SE_PRESENT. */ static session_t * -new_session(session_t *sprev, int session_index, register struct ttyent *typ) +new_session(session_t *sprev, int session_index, struct ttyent *typ) { - register session_t *sp; + session_t *sp; int fd; if ((typ->ty_status & TTY_ON) == 0 || typ->ty_name == 0 || typ->ty_getty == 0) - return 0; + return(0); - sp = (session_t *) calloc(1, sizeof (session_t)); + sp = (session_t *) calloc(1, sizeof(session_t)); sp->se_index = session_index; sp->se_flags |= SE_PRESENT; @@ -981,14 +980,14 @@ new_session(session_t *sprev, int sessio if ((fd = open(sp->se_device, O_RDONLY | O_NONBLOCK, 0)) < 0) { if (errno == ENXIO) { free_session(sp); - return (0); + return(0); } } else close(fd); if (setupargv(sp, typ) == 0) { free_session(sp); - return (0); + return(0); } sp->se_next = 0; @@ -1000,7 +999,7 @@ new_session(session_t *sprev, int sessio sp->se_prev = sprev; } - return sp; + return(sp); } /* @@ -1024,7 +1023,7 @@ setupargv(session_t *sp, struct ttyent * free(sp->se_getty); free(sp->se_getty_argv_space); sp->se_getty = sp->se_getty_argv_space = 0; - return (0); + return(0); } if (sp->se_window) { free(sp->se_window); @@ -1043,13 +1042,13 @@ setupargv(session_t *sp, struct ttyent * free(sp->se_window_argv_space); free(sp->se_window); sp->se_window = sp->se_window_argv_space = 0; - return (0); + return(0); } } if (sp->se_type) free(sp->se_type); sp->se_type = typ->ty_type ? strdup(typ->ty_type) : 0; - return (1); + return(1); } /* @@ -1059,8 +1058,8 @@ static state_func_t read_ttys(void) { int session_index = 0; - register session_t *sp, *snext; - register struct ttyent *typ; + session_t *sp, *snext; + struct ttyent *typ; /* * Destroy any previous session state. @@ -1074,7 +1073,7 @@ read_ttys(void) } sessions = 0; if (start_session_db()) - return (state_func_t) single_user; + return((state_func_t)single_user); /* * Allocate a session entry for each active port. @@ -1086,7 +1085,7 @@ read_ttys(void) endttyent(); - return (state_func_t) multi_user; + return((state_func_t)multi_user); } /* @@ -1110,7 +1109,7 @@ start_window_system(session_t *sp) return; sigemptyset(&mask); - sigprocmask(SIG_SETMASK, &mask, (sigset_t *) 0); + sigprocmask(SIG_SETMASK, &mask, (sigset_t *)0); if (setsid() < 0) emergency("setsid failed (window) %m"); @@ -1141,7 +1140,7 @@ start_getty(session_t *sp) { pid_t pid; sigset_t mask; - time_t current_time = time((time_t *) 0); + time_t current_time = time((time_t *)0); int too_quick = 0; char term[64], *env[2]; @@ -1159,16 +1158,16 @@ start_getty(session_t *sp) */ if ((pid = fork()) == -1) { emergency("can't fork for getty on port %s: %m", sp->se_device); - return -1; + return(-1); } if (pid) - return pid; + return(pid); if (too_quick) { warning("getty repeating too quickly on port %s, sleeping %d secs", sp->se_device, GETTY_SLEEP); - sleep((unsigned) GETTY_SLEEP); + sleep((unsigned)GETTY_SLEEP); } if (sp->se_window) { @@ -1177,7 +1176,7 @@ start_getty(session_t *sp) } sigemptyset(&mask); - sigprocmask(SIG_SETMASK, &mask, (sigset_t *) 0); + sigprocmask(SIG_SETMASK, &mask, (sigset_t *)0); #ifdef LOGIN_CAP setprocresources(RESOURCE_GETTY); @@ -1204,12 +1203,12 @@ start_getty(session_t *sp) static void collect_child(pid_t pid) { - register session_t *sp, *sprev, *snext; + session_t *sp, *sprev, *snext; - if (! sessions) + if (!sessions) return; - if (! (sp = find_session(pid))) + if (!(sp = find_session(pid))) return; clear_session_logs(sp); @@ -1234,7 +1233,7 @@ collect_child(pid_t pid) } sp->se_process = pid; - sp->se_started = time((time_t *) 0); + sp->se_started = time((time_t *)0); add_session(sp); } @@ -1274,7 +1273,7 @@ static state_func_t multi_user(void) { pid_t pid; - register session_t *sp; + session_t *sp; requested_transition = 0; @@ -1296,15 +1295,15 @@ multi_user(void) break; } sp->se_process = pid; - sp->se_started = time((time_t *) 0); + sp->se_started = time((time_t *)0); add_session(sp); } while (!requested_transition) - if ((pid = waitpid(-1, (int *) 0, 0)) != -1) + if ((pid = waitpid(-1, (int *)0, 0)) != -1) collect_child(pid); - return (state_func_t) requested_transition; + return((state_func_t)requested_transition); } /* @@ -1313,14 +1312,14 @@ multi_user(void) static state_func_t clean_ttys(void) { - register session_t *sp, *sprev; - register struct ttyent *typ; - register int session_index = 0; - register int devlen; + session_t *sp, *sprev; + struct ttyent *typ; + int session_index = 0; + int devlen; char *old_getty, *old_window, *old_type; - if (! sessions) - return (state_func_t) multi_user; + if (!sessions) + return((state_func_t)multi_user); /* * mark all sessions for death, (!SE_PRESENT) @@ -1402,7 +1401,7 @@ clean_ttys(void) } } - return (state_func_t) multi_user; + return((state_func_t)multi_user); } /* @@ -1411,12 +1410,12 @@ clean_ttys(void) static state_func_t catatonia(void) { - register session_t *sp; + session_t *sp; for (sp = sessions; sp; sp = sp->se_next) sp->se_flags |= SE_SHUTDOWN; - return (state_func_t) multi_user; + return((state_func_t)multi_user); } /* @@ -1452,7 +1451,7 @@ death(void) for (i = 0; i < 2; ++i) { if (kill(-1, death_sigs[i]) == -1 && errno == ESRCH) - return (state_func_t) single_user; + return((state_func_t)single_user); clang = 0; alarm(DEATH_WATCH); @@ -1462,12 +1461,12 @@ death(void) while (clang == 0 && errno != ECHILD); if (errno == ECHILD) - return (state_func_t) single_user; + return((state_func_t)single_user); } warning("some processes would not die; ps axl advised"); - return (state_func_t) single_user; + return((state_func_t)single_user); } /* @@ -1497,10 +1496,10 @@ runshutdown(void) * reasons, we'll let the shell complain. */ if (stat(_PATH_RUNDOWN, &sb) == -1 && errno == ENOENT) - return 0; + return(0); if ((pid = fork()) == 0) { - int fd; + int fd; /* Assume that init already grab console as ctty before */ @@ -1531,7 +1530,7 @@ runshutdown(void) argv[2] = "single"; argv[3] = 0; - sigprocmask(SIG_SETMASK, &sa.sa_mask, (sigset_t *) 0); + sigprocmask(SIG_SETMASK, &sa.sa_mask, (sigset_t *)0); #ifdef LOGIN_CAP setprocresources(RESOURCE_RC); @@ -1544,10 +1543,10 @@ runshutdown(void) if (pid == -1) { emergency("can't fork for %s on %s: %m", _PATH_BSHELL, _PATH_RUNDOWN); - while (waitpid(-1, (int *) 0, WNOHANG) > 0) + while (waitpid(-1, (int *)0, WNOHANG) > 0) continue; sleep(STALL_TIMEOUT); - return -1; + return(-1); } len = sizeof(shutdowntimeout); @@ -1569,14 +1568,14 @@ runshutdown(void) kill(wpid, SIGTERM); warning("timeout expired for %s on %s: %m; going to single user mode", _PATH_BSHELL, _PATH_RUNDOWN); - return -1; + return(-1); } if (wpid == -1) { if (errno == EINTR) continue; warning("wait for %s on %s failed: %m; going to single user mode", _PATH_BSHELL, _PATH_RUNDOWN); - return -1; + return(-1); } if (wpid == pid && WIFSTOPPED(status)) { warning("init: %s on %s stopped, restarting\n", @@ -1605,13 +1604,13 @@ runshutdown(void) if (!WIFEXITED(status)) { warning("%s on %s terminated abnormally, going to single user mode", _PATH_BSHELL, _PATH_RUNDOWN); - return -2; + return(-2); } if ((status = WEXITSTATUS(status)) != 0) warning("%s returned status %d", _PATH_RUNDOWN, status); - return status; + return(status); } static char * @@ -1624,14 +1623,14 @@ strk(char *p) if (p) t = p; if (!t) - return 0; + return(0); c = *t; while (c == ' ' || c == '\t' ) c = *++t; if (!c) { t = 0; - return 0; + return(0); } q = t; if (c == '\'') { @@ -1650,7 +1649,7 @@ strk(char *p) if (!c) t = 0; } - return q; + return(q); } #ifdef LOGIN_CAP
Attachment:
pgp00010.pgp
Description: PGP signature