Lines Matching +full:syscon +full:- +full:wakeup
34 * University Copyright- Copyright (c) 1982, 1986, 1988
38 * University Acknowledgment- Portions of this document are derived from
45 * start and restart svc.startd for smf(7). For backwards-compatibility it also
47 * run-level. It reads /etc/default/inittab for general configuration.
49 * To change run-levels the system administrator runs init from the command
53 * run-levels are [sS0123456]. Additionally, init can be given directives
57 * spawned at various run-levels. inittab contains the set of the levels for
62 * init(8) will be immediately re-executed, retaining its original PID. (PID
83 * fork(2)-exec(2)-waitpid(3C) sequence with the parent waiting for repair or
146 #define FAILURE -1
153 * nothing else requires this "init" wakeup.
166 #define EXEC (sizeof ("exec ") - 1)
188 * common mapping between level-name (like 'S'), signal number (state),
189 * run-level mask, and specific properties associated with a run-level.
416 * The following structure contains a set of modes for /dev/syscon
417 * and should match the default contents of /etc/ioctl.syscon.
431 static int write_ioctl = 0; /* Rewrite /etc/ioctl.syscon */
433 static union WAKEUP { union
440 } wakeup; variable
450 #define cur_state (g_state->ist_runlevel)
451 #define num_proc (g_state->ist_num_proc)
452 #define proc_table (g_state->ist_proc_table)
453 #define utmpx_ok (g_state->ist_utmpx_ok)
481 INIT_STATE_DIR "/init-next.state";
489 static char *SYSCON = "/dev/syscon"; /* Virtual System console */ variable
490 static char *IOCTLSYSCON = "/etc/ioctl.syscon"; /* Last syscon modes */
492 static char *SU = "/etc/sulogin"; /* Super-user program for single user */
508 static int Pfd = -1; /* fd to receive pids thru */
514 static int sflg = 0; /* Set if we were booted -s to single user */
515 static int rflg = 0; /* Set if booted -r, reconfigure devices */
516 static int bflg = 0; /* Set if booted -b, don't run rc scripts */
543 static int legacy_tmpl = -1; /* fd for legacy contract template */
544 static int startd_tmpl = -1; /* fd for svc.startd's template */
680 * but we do not have that luxury in non-global zones, in main()
698 "\n\n%s Release %s Version %s %s-bit\r\n", in main()
709 * Get the ioctl settings for /dev/syscon from /etc/ioctl.syscon in main()
711 * system went down; or set to defaults if ioctl.syscon isn't in main()
786 if (rl != -1) in main()
823 if (wakeup.w_flags.w_powerhit) { in main()
856 if (wakeup.w_mask == 0) { in main()
870 * the current wakeup. in main()
882 if (wakeup.w_flags.w_usersignal) { in main()
908 if (wakeup.w_flags.w_powerhit) in main()
912 * Clear all wakeup reasons. in main()
914 wakeup.w_mask = 0; in main()
938 (void) system("/sbin/bootadm -ea update_all"); in update_boot_archive()
966 fd = open(SYSCON, O_RDWR | O_NOCTTY); in enter_maintenance()
975 getpid(), SYSCON, strerror(errno)); in enter_maintenance()
981 (void) execle(SU, SU, "-", (char *)0, glob_envp); in enter_maintenance()
995 * single-user mode. The only child we are interested in enter_maintenance()
998 wakeup.w_mask = 0; in enter_maintenance()
1024 process->p_flags &= ~TOUCHED; in remv()
1034 if ((process->p_flags & OCCUPIED) == 0 || in remv()
1035 !id_eq(process->p_id, cmd.c_id)) in remv()
1051 (process->p_flags & DEMANDREQUEST) == 0)) { in remv()
1052 if (process->p_flags & LIVING) { in remv()
1062 process->p_flags |= TOUCHED; in remv()
1064 if ((process->p_flags & KILLED) == 0) { in remv()
1066 process->p_flags in remv()
1069 process->p_pid, in remv()
1080 process->p_pid); in remv()
1082 process->p_flags |= KILLED; in remv()
1095 if (process->p_flags & in remv()
1097 process->p_flags |= TOUCHED; in remv()
1118 * wakeup in TWARN seconds whether we need to or not. in remv()
1134 (process->p_flags & (WARNED|LIVING|OCCUPIED)) == in remv()
1152 if ((process->p_flags & in remv()
1155 (void) kill(process->p_pid, SIGKILL); in remv()
1170 if ((process->p_flags & (LIVING|NAMED|TOUCHED|KILLED|OCCUPIED)) in remv()
1172 killproc(process->p_pid); in remv()
1173 process->p_flags |= KILLED; in remv()
1174 } else if ((process->p_flags & (LIVING|NAMED|OCCUPIED)) == in remv()
1183 if ((process->p_flags & TOUCHED) == 0) in remv()
1184 process->p_flags = 0; in remv()
1203 /* Also append -r or -s. */ in process_startd_line()
1205 (void) strlcat(startd_cline, " -", sizeof (startd_cline)); in process_startd_line()
1241 if (wakeup.w_flags.w_powerhit) { in spawn_processes()
1242 wakeup.w_flags.w_powerhit = 0; in spawn_processes()
1282 if (((pp->p_flags & (LIVING|DEMANDREQUEST)) == DEMANDREQUEST) && in spawn_processes()
1293 if ((cmd.c_action & op_modes) == 0 || pp->p_flags & LIVING || in spawn_processes()
1326 pp->p_flags = 0; in spawn_processes()
1350 if (process->p_flags & DEMANDREQUEST || cur_state == LVLa || in spawn()
1353 if ((cmd->c_action & (M_SYSINIT | M_WAIT | M_BOOTWAIT | M_PWAIT)) != 0) in spawn()
1360 if (cmd->c_action & M_RESPAWN) { in spawn()
1373 if (process->p_time == 0L) in spawn()
1374 process->p_time = now; in spawn()
1376 if (process->p_count++ == SPAWN_LIMIT) { in spawn()
1378 if ((now - process->p_time) < SPAWN_INTERVAL) { in spawn()
1386 &cmd->c_id[0], &cmd->c_command[EXEC]); in spawn()
1389 process->p_time = now; in spawn()
1390 process->p_count = 0; in spawn()
1392 } else if (process->p_count > SPAWN_LIMIT) { in spawn()
1398 if (now - process->p_time < SPAWN_INTERVAL + INHIBIT) in spawn()
1400 process->p_time = now; in spawn()
1401 process->p_count = 0; in spawn()
1411 while ((process = efork(cmd->c_action, oprocess, modes)) == NO_ROOM) in spawn()
1427 tmproc.p_id[0] = cmd->c_id[0]; in spawn()
1428 tmproc.p_id[1] = cmd->c_id[1]; in spawn()
1429 tmproc.p_id[2] = cmd->c_id[2]; in spawn()
1430 tmproc.p_id[3] = cmd->c_id[3]; in spawn()
1434 prog_name(&cmd->c_command[EXEC])); in spawn()
1440 * Now exec a shell with the -c option and the command in spawn()
1443 (void) execle(SH, "INITSH", "-c", cmd->c_command, (char *)0, in spawn()
1446 "= %d (exec of shell failed)\n", cmd->c_command, errno); in spawn()
1461 process->p_id[0] = cmd->c_id[0]; in spawn()
1462 process->p_id[1] = cmd->c_id[1]; in spawn()
1463 process->p_id[2] = cmd->c_id[2]; in spawn()
1464 process->p_id[3] = cmd->c_id[3]; in spawn()
1483 if (process->p_flags & OCCUPIED && in findpslot()
1484 id_eq(process->p_id, cmd->c_id)) in findpslot()
1492 if (empty == NULLPROC && (process->p_flags & OCCUPIED) == 0) { in findpslot()
1494 process->p_id[0] = '\0'; in findpslot()
1495 process->p_id[1] = '\0'; in findpslot()
1496 process->p_id[2] = '\0'; in findpslot()
1497 process->p_id[3] = '\0'; in findpslot()
1498 process->p_pid = 0; in findpslot()
1499 process->p_time = 0L; in findpslot()
1500 process->p_count = 0; in findpslot()
1501 process->p_flags = 0; in findpslot()
1502 process->p_exit = 0; in findpslot()
1546 * are specified for single-user mode. in getcmd()
1558 if (stat(INITTAB, &sbuf) == -1) { in getcmd()
1645 * Detect comments (lines whose first non-whitespace in getcmd()
1668 if ((i = ptr - shcmd) < 1 || i > 4) { in getcmd()
1671 bcopy(shcmd, &cmd->c_id[0], i); in getcmd()
1682 for (cmd->c_levels = 0, ptr1 = shcmd; in getcmd()
1686 &mask) == -1) { in getcmd()
1690 cmd->c_levels |= mask; in getcmd()
1707 if (isdigit(cmd->c_id[0]) && in getcmd()
1708 (cmd->c_id[1] == '\0' || in getcmd()
1709 isdigit(cmd->c_id[1])) && in getcmd()
1710 (cmd->c_id[2] == '\0' || in getcmd()
1711 isdigit(cmd->c_id[2])) && in getcmd()
1712 (cmd->c_id[3] == '\0' || in getcmd()
1713 isdigit(cmd->c_id[3]))) in getcmd()
1714 cmd->c_action = M_RESPAWN; in getcmd()
1716 cmd->c_action = M_OFF; in getcmd()
1718 for (cmd->c_action = 0, i = 0, in getcmd()
1724 if ((cmd->c_levels & MASKSU) && in getcmd()
1726 cmd->c_action = 0; in getcmd()
1728 cmd->c_action = in getcmd()
1739 if (cmd->c_action == 0) { in getcmd()
1768 if (ptr >= shcmd + MAXCMDL - 1) in getcmd()
1788 cmd->c_command = shcmd; in getcmd()
1794 if (cmd->c_levels == 0) in getcmd()
1795 cmd->c_levels = MASK_NUMERIC; in getcmd()
1801 if (cmd->c_action == 0) in getcmd()
1802 cmd->c_action = M_OFF; in getcmd()
1838 return (-1); in lvlname_to_state()
1852 return (-1); in state_to_name()
1882 return (-1); in lvlname_to_mask()
1968 glob_envn < MAXENVENT - 2) { in init_env()
1970 if (strncmp(tokp, "CMASK=", sizeof ("CMASK=") - 1) == 0) { in init_env()
1988 if (++glob_envn >= MAXENVENT - 1) { in init_env()
2074 (void) execle(SH, "INITSH", "-c", in boot_init()
2084 process->p_flags = 0; in boot_init()
2100 * If the /etc/ioctl.syscon didn't exist or had invalid contents write in boot_init()
2111 if (startd_run(startd_cline, startd_tmpl, 0) == -1) in boot_init()
2130 * Start by ignoring all signals, then selectively re-enable some. in init_signals()
2139 * Handle all level-changing signals using siglvl() and set sa_mask so in init_signals()
2140 * that all level-changing signals are blocked while in siglvl(). in init_signals()
2226 * siglvl - handle an asynchronous signal from init(8) telling us that we
2250 (sig != SIGFPE || sip->si_code == 0)) { in siglvl()
2257 (void) sigfillset(&ucp->uc_sigmask); in siglvl()
2258 (void) sigdelset(&ucp->uc_sigmask, sig); in siglvl()
2259 ucp->uc_flags |= UC_SIGMASK; in siglvl()
2286 process->p_time = 0L; in siglvl()
2287 process->p_count = 0; in siglvl()
2293 wakeup.w_flags.w_usersignal = 1; in siglvl()
2336 if ((process->p_flags & (LIVING|OCCUPIED)) == in childeath_single()
2337 (LIVING|OCCUPIED) && process->p_pid == pid) { in childeath_single()
2341 * status. Also set the wakeup flag for a dead child in childeath_single()
2344 process->p_flags &= ~LIVING; in childeath_single()
2345 process->p_exit = (short)status; in childeath_single()
2346 wakeup.w_flags.w_childdeath = 1; in childeath_single()
2358 if (pid > pp->pl_pid) { in childeath_single()
2362 pp = pp->pl_next; in childeath_single()
2364 } else if (pid < pp->pl_pid) { in childeath_single()
2373 pp->pl_dflag = 1; in childeath_single()
2374 pp->pl_exit = (short)status; in childeath_single()
2375 wakeup.w_flags.w_childdeath = 1; in childeath_single()
2391 while ((pid = waitpid(-1, &status, WNOHANG)) > 0) in childeath()
2398 (void) nice(-19); in powerfail()
2399 wakeup.w_flags.w_powerhit = 1; in powerfail()
2427 if ((proc->p_flags & (OCCUPIED|LIVING|NOCLEANUP)) == in efork()
2433 if (proc->p_flags & NAMED) in efork()
2439 proc->p_flags = 0; in efork()
2468 for (process = proc_table; process->p_flags != 0 && in efork()
2486 process->p_time = 0L; in efork()
2487 process->p_count = 0; in efork()
2489 process->p_id[0] = '\0'; in efork()
2490 process->p_id[1] = '\0'; in efork()
2491 process->p_id[2] = '\0'; in efork()
2492 process->p_id[3] = '\0'; in efork()
2493 process->p_pid = childpid; in efork()
2494 process->p_flags = (LIVING | OCCUPIED | modes); in efork()
2495 process->p_exit = 0; in efork()
2550 if (process->p_flags & LIVING) in waitproc()
2557 if (process->p_flags & LIVING) in waitproc()
2564 answer = (process->p_exit & 0xffff); in waitproc()
2569 process->p_flags = 0; in waitproc()
2580 char user[sizeof (up->ut_user) + 1]; in notify_pam_dead()
2581 char ttyn[sizeof (up->ut_line) + 1]; in notify_pam_dead()
2582 char host[sizeof (up->ut_host) + 1]; in notify_pam_dead()
2587 (void) snprintf(user, sizeof (user), "%s", up->ut_user); in notify_pam_dead()
2588 (void) snprintf(ttyn, sizeof (ttyn), "%s", up->ut_line); in notify_pam_dead()
2589 (void) snprintf(host, sizeof (host), "%s", up->ut_host); in notify_pam_dead()
2600 * Check you can access utmpx (As / may be read-only and
2620 * Returns non-zero if write failed.
2631 return (-1); in account()
2643 u->ut_id[0] = process->p_id[0]; in account()
2644 u->ut_id[1] = process->p_id[1]; in account()
2645 u->ut_id[2] = process->p_id[2]; in account()
2646 u->ut_id[3] = process->p_id[3]; in account()
2647 u->ut_pid = process->p_pid; in account()
2652 u->ut_exit.e_termination = WTERMSIG(process->p_exit); in account()
2653 u->ut_exit.e_exit = WEXITSTATUS(process->p_exit); in account()
2654 u->ut_type = state; in account()
2656 (void) time(&u->ut_tv.tv_sec); in account()
2674 bcopy(oldu->ut_user, u->ut_user, sizeof (u->ut_user)); in account()
2675 bcopy(oldu->ut_line, u->ut_line, sizeof (u->ut_line)); in account()
2676 bcopy(oldu->ut_host, u->ut_host, sizeof (u->ut_host)); in account()
2677 u->ut_syslen = (tmplen = strlen(u->ut_host)) ? in account()
2678 min(tmplen + 1, sizeof (u->ut_host)) : 0; in account()
2680 if (oldu->ut_type == USER_PROCESS && state == DEAD_PROCESS) { in account()
2692 (void) strncpy(u->ut_user, program, sizeof (u->ut_user)); in account()
2697 (void) strlcpy(fail_buf, u->ut_id, sizeof (u->ut_id) + 1); in account()
2709 return (-1); in account()
2743 if (up->ut_pid == pid) { in clearent()
2744 if (up->ut_type == DEAD_PROCESS) { in clearent()
2753 up->ut_type = DEAD_PROCESS; in clearent()
2754 up->ut_exit.e_termination = WTERMSIG(status); in clearent()
2755 up->ut_exit.e_exit = WEXITSTATUS(status); in clearent()
2756 (void) time(&up->ut_tv.tv_sec); in clearent()
2791 * If the first non-space non-tab character is not one allowed in in prog_name()
2828 * associated with SYSCON that has the same device number as CONSOLE.
2835 if (stat(SYSCON, &sconbuf) != -1 && in realcon()
2836 stat(CONSOLE, &conbuf) != -1 && in realcon()
2848 * get_ioctl_syscon() retrieves the SYSCON settings from the IOCTLSYSCON file.
2860 * Read in the previous modes for SYSCON from IOCTLSYSCON. in get_ioctl_syscon()
2920 (void) unlink(SYSCON); in write_ioctl_syscon()
2921 (void) link(SYSTTY, SYSCON); in write_ioctl_syscon()
2948 * we keep in stored_syscon_termios (which we read out of /etc/ioctl.syscon).
2962 * We open SYSCON anew each time in case it has changed (see in console()
2965 if ((fd = open(SYSCON, O_RDWR | O_NOCTTY)) < 0 || in console()
3021 * ENOMEM - out of memory
3022 * ECONNABORTED - repository connection broken
3023 * EPERM - permission denied
3024 * EACCES - backend access denied
3025 * EROFS - backend readonly
3055 /* Make sure we're right, since we're adding piece-by-piece. */ in get_or_add_startd()
3203 * ECONNABORTED - repository connection broken
3204 * ECANCELED - the transaction's property group was deleted
3495 if ((init_signal = lvlname_to_state((char)argv[1][0])) == -1) { in userinit()
3505 * and that /dev/syscon is linked to this line. in userinit()
3516 if ((stat(ln, &sconbuf) != -1) && in userinit()
3517 (stat(SYSCON, &conbuf) == -1 || in userinit()
3520 * /dev/syscon needs to change. in userinit()
3521 * Unlink /dev/syscon and relink it to the current line. in userinit()
3523 if (lstat(SYSCON, &conbuf) != -1 && in userinit()
3524 unlink(SYSCON) == FAILURE) { in userinit()
3525 perror("Can't unlink /dev/syscon"); in userinit()
3532 if (symlink(ln, SYSCON) == FAILURE) { in userinit()
3534 "Can't symlink /dev/syscon to %s: %s", ln, in userinit()
3537 /* Try to leave a syscon */ in userinit()
3538 (void) link(SYSTTY, SYSCON); in userinit()
3546 * /dev/syscon is currently connected. in userinit()
3550 "\n**** SYSCON CHANGED TO %s ****\n", in userinit()
3565 (void) fprintf(stderr, "Must be super-user\n"); in userinit()
3602 switch (p->pd_type) { in sigpoll()
3623 for (i = 0; i < DELTA - 2; i++) { in sigpoll()
3624 tp->pl_next = tp + 1; in sigpoll()
3629 Plfree = plp->pl_next; in sigpoll()
3631 plp->pl_pid = p->pd_pid; in sigpoll()
3632 plp->pl_dflag = 0; in sigpoll()
3633 plp->pl_next = NULL; in sigpoll()
3635 * Note - pid list is kept in increasing order of pids. in sigpoll()
3644 if (plp->pl_pid > tp->pl_pid) { in sigpoll()
3646 tp = tp->pl_next; in sigpoll()
3648 } else if (plp->pl_pid < tp->pl_pid) { in sigpoll()
3650 plp->pl_next = Plhead; in sigpoll()
3653 plp->pl_next = in sigpoll()
3654 savetp->pl_next; in sigpoll()
3655 savetp->pl_next = plp; in sigpoll()
3660 plp->pl_next = Plfree; in sigpoll()
3667 savetp->pl_next = plp; in sigpoll()
3684 if (p->pd_pid > tp->pl_pid) { in sigpoll()
3687 tp = tp->pl_next; in sigpoll()
3689 } else if (p->pd_pid < tp->pl_pid) { in sigpoll()
3695 Plhead = tp->pl_next; in sigpoll()
3697 savetp->pl_next = tp->pl_next; in sigpoll()
3698 tp->pl_next = Plfree; in sigpoll()
3721 Gchild = 0; /* Note - Safe to do this here since no SIGCLDs */ in cleanaux()
3725 if (p->pl_dflag) { in cleanaux()
3730 pid = p->pl_pid; in cleanaux()
3731 status = p->pl_exit; in cleanaux()
3733 Plhead = p->pl_next; in cleanaux()
3734 p->pl_next = Plfree; in cleanaux()
3738 savep->pl_next = p->pl_next; in cleanaux()
3739 p->pl_next = Plfree; in cleanaux()
3741 p = savep->pl_next; in cleanaux()
3747 p = p->pl_next; in cleanaux()
3813 if (g_state_sz != sizeof (struct init_state) + (num_proc - 1) * in st_sane()
3820 if (!(ptp->p_flags & OCCUPIED)) in st_sane()
3824 if (ptp->p_flags & ~(PF_MASK)) in st_sane()
3828 if (ptp->p_pid < 5 || ptp->p_pid > MAXPID) in st_sane()
3832 if (ptp->p_count < 0) in st_sane()
3836 if (ptp->p_time < 0) in st_sane()
3872 } while (st_fd == -1 && errno == EINTR); in st_init()
3873 if (st_fd != -1) in st_init()
3880 } while (st_fd == -1 && errno == EINTR); in st_init()
3881 if (st_fd == -1) in st_init()
3887 while (ret == -1 && errno == EINTR) in st_init()
3889 if (ret == -1) in st_init()
3912 to_be_read -= read_ret; in st_init()
3938 ((init_num_proc - 1) * sizeof (struct PROC_TABLE)); in st_init()
3948 g_state->ist_runlevel = -1; in st_init()
4001 sz -= ret; in st_write()
4006 st_fd = -1; in st_write()
4055 return (-1); in contract_make_template()
4102 legacy_tmpl = -1; in contracts_init()
4112 if (dup2(legacy_tmpl, 255) == -1) { in contracts_init()
4125 if (dup2(startd_tmpl, 254) == -1) { in contracts_init()
4157 if (dup2(fd, 253) == -1) { in contracts_init()
4200 return (-1); in contract_cookie()
4207 return (-1); in contract_cookie()
4244 if (!(poll->revents & POLLIN)) { in contract_event()
4245 if (poll->revents & POLLERR) in contract_event()
4252 err = ct_event_read(poll->fd, &e); in contract_event()
4336 return (-1); in startd_run()
4343 } while (ret == -1 && errno == EINTR); in startd_run()
4349 return (-1); in startd_run()
4416 malloc(sizeof ("SMF_OPTIONS=") - 1 + in startd_run()
4434 (void) execle(SH, "INITSH", "-c", cline, NULL, glob_envp); in startd_run()
4486 (startd_failure_time[(n - 1) % NSTARTD_FAILURE_TIMES] - in startd_failure_rate_critical()
4540 * an attributed record (auid = -2 is unattributed) in audit_put_record()
4552 event->adt_init_solaris.info = msg; /* NULL is ok here */ in audit_put_record()