History log of /openbsd-current/sbin/init/init.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.72 10-Sep-2022 cheloha

init(8): fix signal handler boolean type and qualifier

The variable "clang" is modified from a signal handler. Change it
from an 'int' to a 'sig_atomic_t' and mark it 'volatile', as we
recommend in signal(3).

ok millert@ kn@


Revision tags: OPENBSD_7_1_BASE
# 1.71 24-Oct-2021 deraadt

For open/openat, if the flags parameter does not contain O_CREAT, the
3rd (variadic) mode_t parameter is irrelevant. Many developers in the past
have passed mode_t (0, 044, 0644, or such), which might lead future people
to copy this broken idiom, and perhaps even believe this parameter has some
meaning or implication or application. Delete them all.
This comes out of a conversation where tb@ noticed that a strange (but
intentional) pledge behaviour is to always knock-out high-bits from
mode_t on a number of system calls as a safety factor, and his bewilderment
that this appeared to be happening against valid modes (at least visually),
but no sorry, they are all irrelevant junk. They could all be 0xdeafbeef.
ok millert


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.70 25-Mar-2020 cheloha

init(8): use err(3) instead of hand-rolled fprintf(3) messages


Revision tags: OPENBSD_6_6_BASE
# 1.69 28-Jun-2019 deraadt

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.68 24-Aug-2018 cheloha

Drop special handling of SIGSYS.

Tolerance for up to 25 SIGSYS deliveries was added to init(8) soon after
the addition of sysctl(2) at CSRG, presumably to ease the transition to
the new ABI.

After 25 years of work the ABI transition is finally complete and we can
now safely remove this splint.

In general, we now have better practices and methods for helping userspace
across kernel ABI breaks.

ok deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.67 31-Jan-2018 cheloha

Check GETTY_SPACING against the monotonic clock.

Ensures that we can use the check if the system clock is set backwards.

While here, move time retrieval into the child process in start_getty(),
and only get the time if se_started has been set.

ok millert@ tb@


# 1.66 06-Jan-2018 millert

unifdef LOGIN_CAP, we always want to use login.conf
OK jca@, no objection deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.65 16-Jun-2017 natano

s/CPU_LIDSUSPEND/CPU_LIDACTION/
ok mlarkin


# 1.64 03-May-2017 mestre

Use the safe idiom of cleaning sensitive data from memory with explicit_bzero,
instead of relying on other methods, after readpassphrase. Some programs on
this diff won't benefit that much since it happens near the terminal path, but
someone might copy the unsafe idiom to another program and place it where it
may leak sensitive data.

Discussed aeons ago with tb@, OK deraadt@ and beck@


Revision tags: OPENBSD_6_1_BASE
# 1.63 02-Mar-2017 natano

Add a new sysctl machdep.lidaction. The sysctl works as follows:

machdep.lidaction=0 # do nothing
machdep.lidaction=1 # suspend
machdep.lidaction=2 # hibernate

lidsuspend is just an alias for lidaction, so if you change one, the
other one will have the same value. The plan is to remove
machdep.lidsuspend eventually when people have upgraded their
/ets/sysctl.conf.

discussed with deraadt, who came up with the new MIB name
no objections mlarkin
ok stsp halex jcs


# 1.62 05-Sep-2016 gsoares

replace obsolete getpass() by readpassphrase()
OK tedu millert


# 1.61 04-Sep-2016 nicm

Use an RB tree instead of BDB to map process->session, ok tedu millert


# 1.60 27-Aug-2016 guenther

Pull in <sys/time.h> for struct timespec

ok deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.59 10-May-2016 bluhm

Do not close the stdio file desciptors in init(8), but dup2(2) them
from /dev/null. The code is taken from daemon(3). Also move this
operation to the beginning.
OK millert@ deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.58 01-Feb-2016 jca

Remove variable unneeded since introduction of crypt_checkpass

ok millert@


# 1.57 23-Dec-2015 mmcc

Use NULL rather than 0 for pointers. No binary change.


# 1.56 10-Dec-2015 mmcc

Remove NULL-checks before free(). ok tb@


# 1.55 18-Nov-2015 tedu

use _shadow getpwnam (and crypt_checkpass)


# 1.54 20-Aug-2015 deraadt

<stdlib.h> is included, so do not need to cast result from
malloc, calloc, realloc*
ok krw millert


Revision tags: OPENBSD_5_8_BASE
# 1.53 14-Jul-2015 millert

Use volatile sig_atomic_t for requested_transition since it is
modified inside signal handlers. Instead of returning a function
pointer, the state functions now return an enum for the next state.
This is used as an index into an array of function pointers to
do the actual state change in transition(). OK deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.52 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.51 06-Dec-2014 bluhm

Do not define the variable pid twice to avoid a compiler warning.
OK millert@


Revision tags: OPENBSD_5_6_BASE
# 1.50 22-Apr-2014 tedu

malloc/memset->calloc. with bonus null check. from peter malone.


Revision tags: OPENBSD_5_5_BASE
# 1.49 03-Jan-2014 millert

Do not raise the securelevel when transitioning from catatonia to
multiuser since we are not actually going multiuser. Fixes a problem
where the securelevel was raised for rc.shutdown even when reboot
was run from single user mode. OK deraadt@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.48 11-Feb-2013 millert

Ignore sysctl failure for CPU_LIDSUSPEND when errno is EOPNOTSUPP.
Just because CPU_LIDSUSPEND is defined in cpu.h does mean it is
actually supported by the hardware. OK halex@


# 1.47 11-Oct-2012 halex

fix "disable lidsuspend on shutdown":
- pull in machine/cpu.h so we can actually see CPU_LIDSUSPEND if it's there
- fix the resulting compilation errors now that the code is actually used

"Just go for it" deraadt@


Revision tags: OPENBSD_5_2_BASE
# 1.46 06-Apr-2012 deraadt

no need to (unsigned) a small constant


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.45 15-Oct-2010 dlg

freebsd uses SIGINT to request a reboot, we may as well be consistent.

pointed out by kettenis@ and deraadt@


# 1.44 14-Oct-2010 dlg

add a SIGQUIT handler that does the same as USR1 and USR2, except it
reboots the machine instead just halting or powering down.

diff from Jonathan Matthew
manpage tweaks from jmc@
ok deraadt@


# 1.43 29-Sep-2010 dcoppa

Add missing err.h include

OK deraadt@


Revision tags: OPENBSD_4_8_BASE
# 1.42 07-Aug-2010 phessler

disable lidsuspend when we are powering down

"I like this" marco@, "Sure" deraadt@


Revision tags: OPENBSD_4_7_BASE
# 1.41 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.40 03-Sep-2007 deraadt

malloc(n * m) -> calloc(n, m); ok espie


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.39 22-Jun-2006 deraadt

accept SIGUSR2. Like SIGUSR1, except it makes RB_POWERDOWN mandatory.
This will be used by kernel components which are trying to really really
power the system down. suggested and tested by jason


# 1.38 19-Mar-2006 otto

Fix mem leaks in error path. From NetBSD's coverity analysis. ok pat@
deraadt@


Revision tags: OPENBSD_3_9_BASE
# 1.37 12-Nov-2005 deraadt

use snprintf; dhill@mindcry.org


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE
# 1.36 13-Mar-2005 markus

turn off accounting when switching to single user;
report bluhm at genua.de; ok henning, krw, deraadt


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE
# 1.35 16-Mar-2004 tedu

errno is not specified to be int, but something from errno.h. ok millert@


# 1.34 30-Oct-2003 deraadt

malloc failures in init? never. but try to be reasonable for one dumb one


Revision tags: OPENBSD_3_4_BASE
# 1.33 29-Jul-2003 deraadt

spaces


# 1.32 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.31 30-Mar-2003 deraadt

snprintf; millert ok


Revision tags: OPENBSD_3_3_BASE
# 1.30 11-Dec-2002 millert

Minor cosmetic nits picked while reading though init.c:
o Use STD{IN,OUT,ERR}_FILENO, not 0-2
o Call exit() from main, not return() (code is never reached anyway)
o Change two cases of '!' into "== NULL"


# 1.29 10-Oct-2002 millert

Style nits. Use STDERR_FILENO, not just 2. Also use parens with
return; David Hill


Revision tags: OPENBSD_3_2_BASE
# 1.28 03-Jul-2002 deraadt

ansi


# 1.27 09-Jun-2002 todd

rm trailing whitespace


# 1.26 22-May-2002 deraadt

strcpy, sprintf death; mpech ok


Revision tags: OPENBSD_3_1_BASE
# 1.25 19-Feb-2002 millert

We live in an ANSI C world. Remove lots of gratuitous #ifdef __STDC__ cruft.


# 1.24 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.23 05-Nov-2001 mpech

kill more registers;

millert@ ok


Revision tags: OPENBSD_3_0_BASE
# 1.22 09-Jul-2001 deraadt

correct type on last arg to execl(); nordin@cse.ogi.edu


Revision tags: OPENBSD_2_9_BASE
# 1.21 19-Jan-2001 deraadt

mark signal races i cannot fix at the moment


Revision tags: OPENBSD_2_8_BASE
# 1.20 20-Aug-2000 millert

Add calls to setusercontext() and login_get*(). We basically call
setusercontext() in most places where previously we did a setlogin().
Add default login.conf file and put root in the "daemon" login class.


# 1.19 06-Aug-2000 millert

Add DEFAULT_STATE macro to allow ramdisk init to set default state to
single_user, not runcom (/etc/rc).


Revision tags: OPENBSD_2_7_BASE
# 1.18 22-Jan-2000 deraadt

remove extra externs not needed because of unistd.h (rest of tree will be done later.. contact me if you want to help)


Revision tags: OPENBSD_2_6_BASE
# 1.17 03-Sep-1999 deraadt

have shutdown code run /etc/rc with arg of "shutdown"; rc.shutdown becomes completely admin-editable


# 1.16 06-Jul-1999 deraadt

if SIGUSR1 is received, kill gettys, run /etc/rc.shutdown, and halt the machine


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.15 03-Jun-1998 deraadt

zero sigaction before use


# 1.14 04-May-1998 deraadt

LETS_GET_BIG


Revision tags: OPENBSD_2_3_BASE
# 1.13 13-Apr-1998 millert

Use _PATH_DEV, not "/dev/"
Make init(8) call login_fbtab() correctly.


# 1.12 03-Mar-1998 deraadt

sigset_t; jraynard


Revision tags: OPENBSD_2_2_BASE
# 1.11 14-Sep-1997 deraadt

some -Wall


# 1.10 25-Jun-1997 kstailey

(foo *)0 -> NULL


Revision tags: OPENBSD_2_1_BASE
# 1.9 25-Mar-1997 deraadt

closelog() more often


# 1.8 22-Feb-1997 millert

Update to lite2 -- man page is the only thing that changed.


Revision tags: OPENBSD_2_0_BASE
# 1.7 31-Jul-1996 deraadt

at session termination, login_fbtab devs back to root


# 1.6 12-Jul-1996 deraadt

precheck getty devices for existance; if not there shut then down


# 1.5 12-Jul-1996 deraadt

do not ask for password if none set; from freebsd


# 1.4 12-Jul-1996 weingart

Fix netbsd pr bin/2620. Fix dangling pointer while I am at it.


# 1.3 23-Jun-1996 deraadt

update rcsid


# 1.2 22-May-1996 deraadt

libutil


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.71 24-Oct-2021 deraadt

For open/openat, if the flags parameter does not contain O_CREAT, the
3rd (variadic) mode_t parameter is irrelevant. Many developers in the past
have passed mode_t (0, 044, 0644, or such), which might lead future people
to copy this broken idiom, and perhaps even believe this parameter has some
meaning or implication or application. Delete them all.
This comes out of a conversation where tb@ noticed that a strange (but
intentional) pledge behaviour is to always knock-out high-bits from
mode_t on a number of system calls as a safety factor, and his bewilderment
that this appeared to be happening against valid modes (at least visually),
but no sorry, they are all irrelevant junk. They could all be 0xdeafbeef.
ok millert


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.70 25-Mar-2020 cheloha

init(8): use err(3) instead of hand-rolled fprintf(3) messages


Revision tags: OPENBSD_6_6_BASE
# 1.69 28-Jun-2019 deraadt

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.68 24-Aug-2018 cheloha

Drop special handling of SIGSYS.

Tolerance for up to 25 SIGSYS deliveries was added to init(8) soon after
the addition of sysctl(2) at CSRG, presumably to ease the transition to
the new ABI.

After 25 years of work the ABI transition is finally complete and we can
now safely remove this splint.

In general, we now have better practices and methods for helping userspace
across kernel ABI breaks.

ok deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.67 31-Jan-2018 cheloha

Check GETTY_SPACING against the monotonic clock.

Ensures that we can use the check if the system clock is set backwards.

While here, move time retrieval into the child process in start_getty(),
and only get the time if se_started has been set.

ok millert@ tb@


# 1.66 06-Jan-2018 millert

unifdef LOGIN_CAP, we always want to use login.conf
OK jca@, no objection deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.65 16-Jun-2017 natano

s/CPU_LIDSUSPEND/CPU_LIDACTION/
ok mlarkin


# 1.64 03-May-2017 mestre

Use the safe idiom of cleaning sensitive data from memory with explicit_bzero,
instead of relying on other methods, after readpassphrase. Some programs on
this diff won't benefit that much since it happens near the terminal path, but
someone might copy the unsafe idiom to another program and place it where it
may leak sensitive data.

Discussed aeons ago with tb@, OK deraadt@ and beck@


Revision tags: OPENBSD_6_1_BASE
# 1.63 02-Mar-2017 natano

Add a new sysctl machdep.lidaction. The sysctl works as follows:

machdep.lidaction=0 # do nothing
machdep.lidaction=1 # suspend
machdep.lidaction=2 # hibernate

lidsuspend is just an alias for lidaction, so if you change one, the
other one will have the same value. The plan is to remove
machdep.lidsuspend eventually when people have upgraded their
/ets/sysctl.conf.

discussed with deraadt, who came up with the new MIB name
no objections mlarkin
ok stsp halex jcs


# 1.62 05-Sep-2016 gsoares

replace obsolete getpass() by readpassphrase()
OK tedu millert


# 1.61 04-Sep-2016 nicm

Use an RB tree instead of BDB to map process->session, ok tedu millert


# 1.60 27-Aug-2016 guenther

Pull in <sys/time.h> for struct timespec

ok deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.59 10-May-2016 bluhm

Do not close the stdio file desciptors in init(8), but dup2(2) them
from /dev/null. The code is taken from daemon(3). Also move this
operation to the beginning.
OK millert@ deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.58 01-Feb-2016 jca

Remove variable unneeded since introduction of crypt_checkpass

ok millert@


# 1.57 23-Dec-2015 mmcc

Use NULL rather than 0 for pointers. No binary change.


# 1.56 10-Dec-2015 mmcc

Remove NULL-checks before free(). ok tb@


# 1.55 18-Nov-2015 tedu

use _shadow getpwnam (and crypt_checkpass)


# 1.54 20-Aug-2015 deraadt

<stdlib.h> is included, so do not need to cast result from
malloc, calloc, realloc*
ok krw millert


Revision tags: OPENBSD_5_8_BASE
# 1.53 14-Jul-2015 millert

Use volatile sig_atomic_t for requested_transition since it is
modified inside signal handlers. Instead of returning a function
pointer, the state functions now return an enum for the next state.
This is used as an index into an array of function pointers to
do the actual state change in transition(). OK deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.52 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.51 06-Dec-2014 bluhm

Do not define the variable pid twice to avoid a compiler warning.
OK millert@


Revision tags: OPENBSD_5_6_BASE
# 1.50 22-Apr-2014 tedu

malloc/memset->calloc. with bonus null check. from peter malone.


Revision tags: OPENBSD_5_5_BASE
# 1.49 03-Jan-2014 millert

Do not raise the securelevel when transitioning from catatonia to
multiuser since we are not actually going multiuser. Fixes a problem
where the securelevel was raised for rc.shutdown even when reboot
was run from single user mode. OK deraadt@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.48 11-Feb-2013 millert

Ignore sysctl failure for CPU_LIDSUSPEND when errno is EOPNOTSUPP.
Just because CPU_LIDSUSPEND is defined in cpu.h does mean it is
actually supported by the hardware. OK halex@


# 1.47 11-Oct-2012 halex

fix "disable lidsuspend on shutdown":
- pull in machine/cpu.h so we can actually see CPU_LIDSUSPEND if it's there
- fix the resulting compilation errors now that the code is actually used

"Just go for it" deraadt@


Revision tags: OPENBSD_5_2_BASE
# 1.46 06-Apr-2012 deraadt

no need to (unsigned) a small constant


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.45 15-Oct-2010 dlg

freebsd uses SIGINT to request a reboot, we may as well be consistent.

pointed out by kettenis@ and deraadt@


# 1.44 14-Oct-2010 dlg

add a SIGQUIT handler that does the same as USR1 and USR2, except it
reboots the machine instead just halting or powering down.

diff from Jonathan Matthew
manpage tweaks from jmc@
ok deraadt@


# 1.43 29-Sep-2010 dcoppa

Add missing err.h include

OK deraadt@


Revision tags: OPENBSD_4_8_BASE
# 1.42 07-Aug-2010 phessler

disable lidsuspend when we are powering down

"I like this" marco@, "Sure" deraadt@


Revision tags: OPENBSD_4_7_BASE
# 1.41 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.40 03-Sep-2007 deraadt

malloc(n * m) -> calloc(n, m); ok espie


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.39 22-Jun-2006 deraadt

accept SIGUSR2. Like SIGUSR1, except it makes RB_POWERDOWN mandatory.
This will be used by kernel components which are trying to really really
power the system down. suggested and tested by jason


# 1.38 19-Mar-2006 otto

Fix mem leaks in error path. From NetBSD's coverity analysis. ok pat@
deraadt@


Revision tags: OPENBSD_3_9_BASE
# 1.37 12-Nov-2005 deraadt

use snprintf; dhill@mindcry.org


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE
# 1.36 13-Mar-2005 markus

turn off accounting when switching to single user;
report bluhm at genua.de; ok henning, krw, deraadt


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE
# 1.35 16-Mar-2004 tedu

errno is not specified to be int, but something from errno.h. ok millert@


# 1.34 30-Oct-2003 deraadt

malloc failures in init? never. but try to be reasonable for one dumb one


Revision tags: OPENBSD_3_4_BASE
# 1.33 29-Jul-2003 deraadt

spaces


# 1.32 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.31 30-Mar-2003 deraadt

snprintf; millert ok


Revision tags: OPENBSD_3_3_BASE
# 1.30 11-Dec-2002 millert

Minor cosmetic nits picked while reading though init.c:
o Use STD{IN,OUT,ERR}_FILENO, not 0-2
o Call exit() from main, not return() (code is never reached anyway)
o Change two cases of '!' into "== NULL"


# 1.29 10-Oct-2002 millert

Style nits. Use STDERR_FILENO, not just 2. Also use parens with
return; David Hill


Revision tags: OPENBSD_3_2_BASE
# 1.28 03-Jul-2002 deraadt

ansi


# 1.27 09-Jun-2002 todd

rm trailing whitespace


# 1.26 22-May-2002 deraadt

strcpy, sprintf death; mpech ok


Revision tags: OPENBSD_3_1_BASE
# 1.25 19-Feb-2002 millert

We live in an ANSI C world. Remove lots of gratuitous #ifdef __STDC__ cruft.


# 1.24 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.23 05-Nov-2001 mpech

kill more registers;

millert@ ok


Revision tags: OPENBSD_3_0_BASE
# 1.22 09-Jul-2001 deraadt

correct type on last arg to execl(); nordin@cse.ogi.edu


Revision tags: OPENBSD_2_9_BASE
# 1.21 19-Jan-2001 deraadt

mark signal races i cannot fix at the moment


Revision tags: OPENBSD_2_8_BASE
# 1.20 20-Aug-2000 millert

Add calls to setusercontext() and login_get*(). We basically call
setusercontext() in most places where previously we did a setlogin().
Add default login.conf file and put root in the "daemon" login class.


# 1.19 06-Aug-2000 millert

Add DEFAULT_STATE macro to allow ramdisk init to set default state to
single_user, not runcom (/etc/rc).


Revision tags: OPENBSD_2_7_BASE
# 1.18 22-Jan-2000 deraadt

remove extra externs not needed because of unistd.h (rest of tree will be done later.. contact me if you want to help)


Revision tags: OPENBSD_2_6_BASE
# 1.17 03-Sep-1999 deraadt

have shutdown code run /etc/rc with arg of "shutdown"; rc.shutdown becomes completely admin-editable


# 1.16 06-Jul-1999 deraadt

if SIGUSR1 is received, kill gettys, run /etc/rc.shutdown, and halt the machine


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.15 03-Jun-1998 deraadt

zero sigaction before use


# 1.14 04-May-1998 deraadt

LETS_GET_BIG


Revision tags: OPENBSD_2_3_BASE
# 1.13 13-Apr-1998 millert

Use _PATH_DEV, not "/dev/"
Make init(8) call login_fbtab() correctly.


# 1.12 03-Mar-1998 deraadt

sigset_t; jraynard


Revision tags: OPENBSD_2_2_BASE
# 1.11 14-Sep-1997 deraadt

some -Wall


# 1.10 25-Jun-1997 kstailey

(foo *)0 -> NULL


Revision tags: OPENBSD_2_1_BASE
# 1.9 25-Mar-1997 deraadt

closelog() more often


# 1.8 22-Feb-1997 millert

Update to lite2 -- man page is the only thing that changed.


Revision tags: OPENBSD_2_0_BASE
# 1.7 31-Jul-1996 deraadt

at session termination, login_fbtab devs back to root


# 1.6 12-Jul-1996 deraadt

precheck getty devices for existance; if not there shut then down


# 1.5 12-Jul-1996 deraadt

do not ask for password if none set; from freebsd


# 1.4 12-Jul-1996 weingart

Fix netbsd pr bin/2620. Fix dangling pointer while I am at it.


# 1.3 23-Jun-1996 deraadt

update rcsid


# 1.2 22-May-1996 deraadt

libutil


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.70 25-Mar-2020 cheloha

init(8): use err(3) instead of hand-rolled fprintf(3) messages


Revision tags: OPENBSD_6_6_BASE
# 1.69 28-Jun-2019 deraadt

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.68 24-Aug-2018 cheloha

Drop special handling of SIGSYS.

Tolerance for up to 25 SIGSYS deliveries was added to init(8) soon after
the addition of sysctl(2) at CSRG, presumably to ease the transition to
the new ABI.

After 25 years of work the ABI transition is finally complete and we can
now safely remove this splint.

In general, we now have better practices and methods for helping userspace
across kernel ABI breaks.

ok deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.67 31-Jan-2018 cheloha

Check GETTY_SPACING against the monotonic clock.

Ensures that we can use the check if the system clock is set backwards.

While here, move time retrieval into the child process in start_getty(),
and only get the time if se_started has been set.

ok millert@ tb@


# 1.66 06-Jan-2018 millert

unifdef LOGIN_CAP, we always want to use login.conf
OK jca@, no objection deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.65 16-Jun-2017 natano

s/CPU_LIDSUSPEND/CPU_LIDACTION/
ok mlarkin


# 1.64 03-May-2017 mestre

Use the safe idiom of cleaning sensitive data from memory with explicit_bzero,
instead of relying on other methods, after readpassphrase. Some programs on
this diff won't benefit that much since it happens near the terminal path, but
someone might copy the unsafe idiom to another program and place it where it
may leak sensitive data.

Discussed aeons ago with tb@, OK deraadt@ and beck@


Revision tags: OPENBSD_6_1_BASE
# 1.63 02-Mar-2017 natano

Add a new sysctl machdep.lidaction. The sysctl works as follows:

machdep.lidaction=0 # do nothing
machdep.lidaction=1 # suspend
machdep.lidaction=2 # hibernate

lidsuspend is just an alias for lidaction, so if you change one, the
other one will have the same value. The plan is to remove
machdep.lidsuspend eventually when people have upgraded their
/ets/sysctl.conf.

discussed with deraadt, who came up with the new MIB name
no objections mlarkin
ok stsp halex jcs


# 1.62 05-Sep-2016 gsoares

replace obsolete getpass() by readpassphrase()
OK tedu millert


# 1.61 04-Sep-2016 nicm

Use an RB tree instead of BDB to map process->session, ok tedu millert


# 1.60 27-Aug-2016 guenther

Pull in <sys/time.h> for struct timespec

ok deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.59 10-May-2016 bluhm

Do not close the stdio file desciptors in init(8), but dup2(2) them
from /dev/null. The code is taken from daemon(3). Also move this
operation to the beginning.
OK millert@ deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.58 01-Feb-2016 jca

Remove variable unneeded since introduction of crypt_checkpass

ok millert@


# 1.57 23-Dec-2015 mmcc

Use NULL rather than 0 for pointers. No binary change.


# 1.56 10-Dec-2015 mmcc

Remove NULL-checks before free(). ok tb@


# 1.55 18-Nov-2015 tedu

use _shadow getpwnam (and crypt_checkpass)


# 1.54 20-Aug-2015 deraadt

<stdlib.h> is included, so do not need to cast result from
malloc, calloc, realloc*
ok krw millert


Revision tags: OPENBSD_5_8_BASE
# 1.53 14-Jul-2015 millert

Use volatile sig_atomic_t for requested_transition since it is
modified inside signal handlers. Instead of returning a function
pointer, the state functions now return an enum for the next state.
This is used as an index into an array of function pointers to
do the actual state change in transition(). OK deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.52 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.51 06-Dec-2014 bluhm

Do not define the variable pid twice to avoid a compiler warning.
OK millert@


Revision tags: OPENBSD_5_6_BASE
# 1.50 22-Apr-2014 tedu

malloc/memset->calloc. with bonus null check. from peter malone.


Revision tags: OPENBSD_5_5_BASE
# 1.49 03-Jan-2014 millert

Do not raise the securelevel when transitioning from catatonia to
multiuser since we are not actually going multiuser. Fixes a problem
where the securelevel was raised for rc.shutdown even when reboot
was run from single user mode. OK deraadt@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.48 11-Feb-2013 millert

Ignore sysctl failure for CPU_LIDSUSPEND when errno is EOPNOTSUPP.
Just because CPU_LIDSUSPEND is defined in cpu.h does mean it is
actually supported by the hardware. OK halex@


# 1.47 11-Oct-2012 halex

fix "disable lidsuspend on shutdown":
- pull in machine/cpu.h so we can actually see CPU_LIDSUSPEND if it's there
- fix the resulting compilation errors now that the code is actually used

"Just go for it" deraadt@


Revision tags: OPENBSD_5_2_BASE
# 1.46 06-Apr-2012 deraadt

no need to (unsigned) a small constant


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.45 15-Oct-2010 dlg

freebsd uses SIGINT to request a reboot, we may as well be consistent.

pointed out by kettenis@ and deraadt@


# 1.44 14-Oct-2010 dlg

add a SIGQUIT handler that does the same as USR1 and USR2, except it
reboots the machine instead just halting or powering down.

diff from Jonathan Matthew
manpage tweaks from jmc@
ok deraadt@


# 1.43 29-Sep-2010 dcoppa

Add missing err.h include

OK deraadt@


Revision tags: OPENBSD_4_8_BASE
# 1.42 07-Aug-2010 phessler

disable lidsuspend when we are powering down

"I like this" marco@, "Sure" deraadt@


Revision tags: OPENBSD_4_7_BASE
# 1.41 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.40 03-Sep-2007 deraadt

malloc(n * m) -> calloc(n, m); ok espie


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.39 22-Jun-2006 deraadt

accept SIGUSR2. Like SIGUSR1, except it makes RB_POWERDOWN mandatory.
This will be used by kernel components which are trying to really really
power the system down. suggested and tested by jason


# 1.38 19-Mar-2006 otto

Fix mem leaks in error path. From NetBSD's coverity analysis. ok pat@
deraadt@


Revision tags: OPENBSD_3_9_BASE
# 1.37 12-Nov-2005 deraadt

use snprintf; dhill@mindcry.org


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE
# 1.36 13-Mar-2005 markus

turn off accounting when switching to single user;
report bluhm at genua.de; ok henning, krw, deraadt


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE
# 1.35 16-Mar-2004 tedu

errno is not specified to be int, but something from errno.h. ok millert@


# 1.34 30-Oct-2003 deraadt

malloc failures in init? never. but try to be reasonable for one dumb one


Revision tags: OPENBSD_3_4_BASE
# 1.33 29-Jul-2003 deraadt

spaces


# 1.32 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.31 30-Mar-2003 deraadt

snprintf; millert ok


Revision tags: OPENBSD_3_3_BASE
# 1.30 11-Dec-2002 millert

Minor cosmetic nits picked while reading though init.c:
o Use STD{IN,OUT,ERR}_FILENO, not 0-2
o Call exit() from main, not return() (code is never reached anyway)
o Change two cases of '!' into "== NULL"


# 1.29 10-Oct-2002 millert

Style nits. Use STDERR_FILENO, not just 2. Also use parens with
return; David Hill


Revision tags: OPENBSD_3_2_BASE
# 1.28 03-Jul-2002 deraadt

ansi


# 1.27 09-Jun-2002 todd

rm trailing whitespace


# 1.26 22-May-2002 deraadt

strcpy, sprintf death; mpech ok


Revision tags: OPENBSD_3_1_BASE
# 1.25 19-Feb-2002 millert

We live in an ANSI C world. Remove lots of gratuitous #ifdef __STDC__ cruft.


# 1.24 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.23 05-Nov-2001 mpech

kill more registers;

millert@ ok


Revision tags: OPENBSD_3_0_BASE
# 1.22 09-Jul-2001 deraadt

correct type on last arg to execl(); nordin@cse.ogi.edu


Revision tags: OPENBSD_2_9_BASE
# 1.21 19-Jan-2001 deraadt

mark signal races i cannot fix at the moment


Revision tags: OPENBSD_2_8_BASE
# 1.20 20-Aug-2000 millert

Add calls to setusercontext() and login_get*(). We basically call
setusercontext() in most places where previously we did a setlogin().
Add default login.conf file and put root in the "daemon" login class.


# 1.19 06-Aug-2000 millert

Add DEFAULT_STATE macro to allow ramdisk init to set default state to
single_user, not runcom (/etc/rc).


Revision tags: OPENBSD_2_7_BASE
# 1.18 22-Jan-2000 deraadt

remove extra externs not needed because of unistd.h (rest of tree will be done later.. contact me if you want to help)


Revision tags: OPENBSD_2_6_BASE
# 1.17 03-Sep-1999 deraadt

have shutdown code run /etc/rc with arg of "shutdown"; rc.shutdown becomes completely admin-editable


# 1.16 06-Jul-1999 deraadt

if SIGUSR1 is received, kill gettys, run /etc/rc.shutdown, and halt the machine


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.15 03-Jun-1998 deraadt

zero sigaction before use


# 1.14 04-May-1998 deraadt

LETS_GET_BIG


Revision tags: OPENBSD_2_3_BASE
# 1.13 13-Apr-1998 millert

Use _PATH_DEV, not "/dev/"
Make init(8) call login_fbtab() correctly.


# 1.12 03-Mar-1998 deraadt

sigset_t; jraynard


Revision tags: OPENBSD_2_2_BASE
# 1.11 14-Sep-1997 deraadt

some -Wall


# 1.10 25-Jun-1997 kstailey

(foo *)0 -> NULL


Revision tags: OPENBSD_2_1_BASE
# 1.9 25-Mar-1997 deraadt

closelog() more often


# 1.8 22-Feb-1997 millert

Update to lite2 -- man page is the only thing that changed.


Revision tags: OPENBSD_2_0_BASE
# 1.7 31-Jul-1996 deraadt

at session termination, login_fbtab devs back to root


# 1.6 12-Jul-1996 deraadt

precheck getty devices for existance; if not there shut then down


# 1.5 12-Jul-1996 deraadt

do not ask for password if none set; from freebsd


# 1.4 12-Jul-1996 weingart

Fix netbsd pr bin/2620. Fix dangling pointer while I am at it.


# 1.3 23-Jun-1996 deraadt

update rcsid


# 1.2 22-May-1996 deraadt

libutil


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.69 28-Jun-2019 deraadt

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.68 24-Aug-2018 cheloha

Drop special handling of SIGSYS.

Tolerance for up to 25 SIGSYS deliveries was added to init(8) soon after
the addition of sysctl(2) at CSRG, presumably to ease the transition to
the new ABI.

After 25 years of work the ABI transition is finally complete and we can
now safely remove this splint.

In general, we now have better practices and methods for helping userspace
across kernel ABI breaks.

ok deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.67 31-Jan-2018 cheloha

Check GETTY_SPACING against the monotonic clock.

Ensures that we can use the check if the system clock is set backwards.

While here, move time retrieval into the child process in start_getty(),
and only get the time if se_started has been set.

ok millert@ tb@


# 1.66 06-Jan-2018 millert

unifdef LOGIN_CAP, we always want to use login.conf
OK jca@, no objection deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.65 16-Jun-2017 natano

s/CPU_LIDSUSPEND/CPU_LIDACTION/
ok mlarkin


# 1.64 03-May-2017 mestre

Use the safe idiom of cleaning sensitive data from memory with explicit_bzero,
instead of relying on other methods, after readpassphrase. Some programs on
this diff won't benefit that much since it happens near the terminal path, but
someone might copy the unsafe idiom to another program and place it where it
may leak sensitive data.

Discussed aeons ago with tb@, OK deraadt@ and beck@


Revision tags: OPENBSD_6_1_BASE
# 1.63 02-Mar-2017 natano

Add a new sysctl machdep.lidaction. The sysctl works as follows:

machdep.lidaction=0 # do nothing
machdep.lidaction=1 # suspend
machdep.lidaction=2 # hibernate

lidsuspend is just an alias for lidaction, so if you change one, the
other one will have the same value. The plan is to remove
machdep.lidsuspend eventually when people have upgraded their
/ets/sysctl.conf.

discussed with deraadt, who came up with the new MIB name
no objections mlarkin
ok stsp halex jcs


# 1.62 05-Sep-2016 gsoares

replace obsolete getpass() by readpassphrase()
OK tedu millert


# 1.61 04-Sep-2016 nicm

Use an RB tree instead of BDB to map process->session, ok tedu millert


# 1.60 27-Aug-2016 guenther

Pull in <sys/time.h> for struct timespec

ok deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.59 10-May-2016 bluhm

Do not close the stdio file desciptors in init(8), but dup2(2) them
from /dev/null. The code is taken from daemon(3). Also move this
operation to the beginning.
OK millert@ deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.58 01-Feb-2016 jca

Remove variable unneeded since introduction of crypt_checkpass

ok millert@


# 1.57 23-Dec-2015 mmcc

Use NULL rather than 0 for pointers. No binary change.


# 1.56 10-Dec-2015 mmcc

Remove NULL-checks before free(). ok tb@


# 1.55 18-Nov-2015 tedu

use _shadow getpwnam (and crypt_checkpass)


# 1.54 20-Aug-2015 deraadt

<stdlib.h> is included, so do not need to cast result from
malloc, calloc, realloc*
ok krw millert


Revision tags: OPENBSD_5_8_BASE
# 1.53 14-Jul-2015 millert

Use volatile sig_atomic_t for requested_transition since it is
modified inside signal handlers. Instead of returning a function
pointer, the state functions now return an enum for the next state.
This is used as an index into an array of function pointers to
do the actual state change in transition(). OK deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.52 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.51 06-Dec-2014 bluhm

Do not define the variable pid twice to avoid a compiler warning.
OK millert@


Revision tags: OPENBSD_5_6_BASE
# 1.50 22-Apr-2014 tedu

malloc/memset->calloc. with bonus null check. from peter malone.


Revision tags: OPENBSD_5_5_BASE
# 1.49 03-Jan-2014 millert

Do not raise the securelevel when transitioning from catatonia to
multiuser since we are not actually going multiuser. Fixes a problem
where the securelevel was raised for rc.shutdown even when reboot
was run from single user mode. OK deraadt@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.48 11-Feb-2013 millert

Ignore sysctl failure for CPU_LIDSUSPEND when errno is EOPNOTSUPP.
Just because CPU_LIDSUSPEND is defined in cpu.h does mean it is
actually supported by the hardware. OK halex@


# 1.47 11-Oct-2012 halex

fix "disable lidsuspend on shutdown":
- pull in machine/cpu.h so we can actually see CPU_LIDSUSPEND if it's there
- fix the resulting compilation errors now that the code is actually used

"Just go for it" deraadt@


Revision tags: OPENBSD_5_2_BASE
# 1.46 06-Apr-2012 deraadt

no need to (unsigned) a small constant


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.45 15-Oct-2010 dlg

freebsd uses SIGINT to request a reboot, we may as well be consistent.

pointed out by kettenis@ and deraadt@


# 1.44 14-Oct-2010 dlg

add a SIGQUIT handler that does the same as USR1 and USR2, except it
reboots the machine instead just halting or powering down.

diff from Jonathan Matthew
manpage tweaks from jmc@
ok deraadt@


# 1.43 29-Sep-2010 dcoppa

Add missing err.h include

OK deraadt@


Revision tags: OPENBSD_4_8_BASE
# 1.42 07-Aug-2010 phessler

disable lidsuspend when we are powering down

"I like this" marco@, "Sure" deraadt@


Revision tags: OPENBSD_4_7_BASE
# 1.41 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.40 03-Sep-2007 deraadt

malloc(n * m) -> calloc(n, m); ok espie


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.39 22-Jun-2006 deraadt

accept SIGUSR2. Like SIGUSR1, except it makes RB_POWERDOWN mandatory.
This will be used by kernel components which are trying to really really
power the system down. suggested and tested by jason


# 1.38 19-Mar-2006 otto

Fix mem leaks in error path. From NetBSD's coverity analysis. ok pat@
deraadt@


Revision tags: OPENBSD_3_9_BASE
# 1.37 12-Nov-2005 deraadt

use snprintf; dhill@mindcry.org


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE
# 1.36 13-Mar-2005 markus

turn off accounting when switching to single user;
report bluhm at genua.de; ok henning, krw, deraadt


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE
# 1.35 16-Mar-2004 tedu

errno is not specified to be int, but something from errno.h. ok millert@


# 1.34 30-Oct-2003 deraadt

malloc failures in init? never. but try to be reasonable for one dumb one


Revision tags: OPENBSD_3_4_BASE
# 1.33 29-Jul-2003 deraadt

spaces


# 1.32 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.31 30-Mar-2003 deraadt

snprintf; millert ok


Revision tags: OPENBSD_3_3_BASE
# 1.30 11-Dec-2002 millert

Minor cosmetic nits picked while reading though init.c:
o Use STD{IN,OUT,ERR}_FILENO, not 0-2
o Call exit() from main, not return() (code is never reached anyway)
o Change two cases of '!' into "== NULL"


# 1.29 10-Oct-2002 millert

Style nits. Use STDERR_FILENO, not just 2. Also use parens with
return; David Hill


Revision tags: OPENBSD_3_2_BASE
# 1.28 03-Jul-2002 deraadt

ansi


# 1.27 09-Jun-2002 todd

rm trailing whitespace


# 1.26 22-May-2002 deraadt

strcpy, sprintf death; mpech ok


Revision tags: OPENBSD_3_1_BASE
# 1.25 19-Feb-2002 millert

We live in an ANSI C world. Remove lots of gratuitous #ifdef __STDC__ cruft.


# 1.24 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.23 05-Nov-2001 mpech

kill more registers;

millert@ ok


Revision tags: OPENBSD_3_0_BASE
# 1.22 09-Jul-2001 deraadt

correct type on last arg to execl(); nordin@cse.ogi.edu


Revision tags: OPENBSD_2_9_BASE
# 1.21 19-Jan-2001 deraadt

mark signal races i cannot fix at the moment


Revision tags: OPENBSD_2_8_BASE
# 1.20 20-Aug-2000 millert

Add calls to setusercontext() and login_get*(). We basically call
setusercontext() in most places where previously we did a setlogin().
Add default login.conf file and put root in the "daemon" login class.


# 1.19 06-Aug-2000 millert

Add DEFAULT_STATE macro to allow ramdisk init to set default state to
single_user, not runcom (/etc/rc).


Revision tags: OPENBSD_2_7_BASE
# 1.18 22-Jan-2000 deraadt

remove extra externs not needed because of unistd.h (rest of tree will be done later.. contact me if you want to help)


Revision tags: OPENBSD_2_6_BASE
# 1.17 03-Sep-1999 deraadt

have shutdown code run /etc/rc with arg of "shutdown"; rc.shutdown becomes completely admin-editable


# 1.16 06-Jul-1999 deraadt

if SIGUSR1 is received, kill gettys, run /etc/rc.shutdown, and halt the machine


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.15 03-Jun-1998 deraadt

zero sigaction before use


# 1.14 04-May-1998 deraadt

LETS_GET_BIG


Revision tags: OPENBSD_2_3_BASE
# 1.13 13-Apr-1998 millert

Use _PATH_DEV, not "/dev/"
Make init(8) call login_fbtab() correctly.


# 1.12 03-Mar-1998 deraadt

sigset_t; jraynard


Revision tags: OPENBSD_2_2_BASE
# 1.11 14-Sep-1997 deraadt

some -Wall


# 1.10 25-Jun-1997 kstailey

(foo *)0 -> NULL


Revision tags: OPENBSD_2_1_BASE
# 1.9 25-Mar-1997 deraadt

closelog() more often


# 1.8 22-Feb-1997 millert

Update to lite2 -- man page is the only thing that changed.


Revision tags: OPENBSD_2_0_BASE
# 1.7 31-Jul-1996 deraadt

at session termination, login_fbtab devs back to root


# 1.6 12-Jul-1996 deraadt

precheck getty devices for existance; if not there shut then down


# 1.5 12-Jul-1996 deraadt

do not ask for password if none set; from freebsd


# 1.4 12-Jul-1996 weingart

Fix netbsd pr bin/2620. Fix dangling pointer while I am at it.


# 1.3 23-Jun-1996 deraadt

update rcsid


# 1.2 22-May-1996 deraadt

libutil


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.68 24-Aug-2018 cheloha

Drop special handling of SIGSYS.

Tolerance for up to 25 SIGSYS deliveries was added to init(8) soon after
the addition of sysctl(2) at CSRG, presumably to ease the transition to
the new ABI.

After 25 years of work the ABI transition is finally complete and we can
now safely remove this splint.

In general, we now have better practices and methods for helping userspace
across kernel ABI breaks.

ok deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.67 31-Jan-2018 cheloha

Check GETTY_SPACING against the monotonic clock.

Ensures that we can use the check if the system clock is set backwards.

While here, move time retrieval into the child process in start_getty(),
and only get the time if se_started has been set.

ok millert@ tb@


# 1.66 06-Jan-2018 millert

unifdef LOGIN_CAP, we always want to use login.conf
OK jca@, no objection deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.65 16-Jun-2017 natano

s/CPU_LIDSUSPEND/CPU_LIDACTION/
ok mlarkin


# 1.64 03-May-2017 mestre

Use the safe idiom of cleaning sensitive data from memory with explicit_bzero,
instead of relying on other methods, after readpassphrase. Some programs on
this diff won't benefit that much since it happens near the terminal path, but
someone might copy the unsafe idiom to another program and place it where it
may leak sensitive data.

Discussed aeons ago with tb@, OK deraadt@ and beck@


Revision tags: OPENBSD_6_1_BASE
# 1.63 02-Mar-2017 natano

Add a new sysctl machdep.lidaction. The sysctl works as follows:

machdep.lidaction=0 # do nothing
machdep.lidaction=1 # suspend
machdep.lidaction=2 # hibernate

lidsuspend is just an alias for lidaction, so if you change one, the
other one will have the same value. The plan is to remove
machdep.lidsuspend eventually when people have upgraded their
/ets/sysctl.conf.

discussed with deraadt, who came up with the new MIB name
no objections mlarkin
ok stsp halex jcs


# 1.62 05-Sep-2016 gsoares

replace obsolete getpass() by readpassphrase()
OK tedu millert


# 1.61 04-Sep-2016 nicm

Use an RB tree instead of BDB to map process->session, ok tedu millert


# 1.60 27-Aug-2016 guenther

Pull in <sys/time.h> for struct timespec

ok deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.59 10-May-2016 bluhm

Do not close the stdio file desciptors in init(8), but dup2(2) them
from /dev/null. The code is taken from daemon(3). Also move this
operation to the beginning.
OK millert@ deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.58 01-Feb-2016 jca

Remove variable unneeded since introduction of crypt_checkpass

ok millert@


# 1.57 23-Dec-2015 mmcc

Use NULL rather than 0 for pointers. No binary change.


# 1.56 10-Dec-2015 mmcc

Remove NULL-checks before free(). ok tb@


# 1.55 18-Nov-2015 tedu

use _shadow getpwnam (and crypt_checkpass)


# 1.54 20-Aug-2015 deraadt

<stdlib.h> is included, so do not need to cast result from
malloc, calloc, realloc*
ok krw millert


Revision tags: OPENBSD_5_8_BASE
# 1.53 14-Jul-2015 millert

Use volatile sig_atomic_t for requested_transition since it is
modified inside signal handlers. Instead of returning a function
pointer, the state functions now return an enum for the next state.
This is used as an index into an array of function pointers to
do the actual state change in transition(). OK deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.52 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.51 06-Dec-2014 bluhm

Do not define the variable pid twice to avoid a compiler warning.
OK millert@


Revision tags: OPENBSD_5_6_BASE
# 1.50 22-Apr-2014 tedu

malloc/memset->calloc. with bonus null check. from peter malone.


Revision tags: OPENBSD_5_5_BASE
# 1.49 03-Jan-2014 millert

Do not raise the securelevel when transitioning from catatonia to
multiuser since we are not actually going multiuser. Fixes a problem
where the securelevel was raised for rc.shutdown even when reboot
was run from single user mode. OK deraadt@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.48 11-Feb-2013 millert

Ignore sysctl failure for CPU_LIDSUSPEND when errno is EOPNOTSUPP.
Just because CPU_LIDSUSPEND is defined in cpu.h does mean it is
actually supported by the hardware. OK halex@


# 1.47 11-Oct-2012 halex

fix "disable lidsuspend on shutdown":
- pull in machine/cpu.h so we can actually see CPU_LIDSUSPEND if it's there
- fix the resulting compilation errors now that the code is actually used

"Just go for it" deraadt@


Revision tags: OPENBSD_5_2_BASE
# 1.46 06-Apr-2012 deraadt

no need to (unsigned) a small constant


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.45 15-Oct-2010 dlg

freebsd uses SIGINT to request a reboot, we may as well be consistent.

pointed out by kettenis@ and deraadt@


# 1.44 14-Oct-2010 dlg

add a SIGQUIT handler that does the same as USR1 and USR2, except it
reboots the machine instead just halting or powering down.

diff from Jonathan Matthew
manpage tweaks from jmc@
ok deraadt@


# 1.43 29-Sep-2010 dcoppa

Add missing err.h include

OK deraadt@


Revision tags: OPENBSD_4_8_BASE
# 1.42 07-Aug-2010 phessler

disable lidsuspend when we are powering down

"I like this" marco@, "Sure" deraadt@


Revision tags: OPENBSD_4_7_BASE
# 1.41 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.40 03-Sep-2007 deraadt

malloc(n * m) -> calloc(n, m); ok espie


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.39 22-Jun-2006 deraadt

accept SIGUSR2. Like SIGUSR1, except it makes RB_POWERDOWN mandatory.
This will be used by kernel components which are trying to really really
power the system down. suggested and tested by jason


# 1.38 19-Mar-2006 otto

Fix mem leaks in error path. From NetBSD's coverity analysis. ok pat@
deraadt@


Revision tags: OPENBSD_3_9_BASE
# 1.37 12-Nov-2005 deraadt

use snprintf; dhill@mindcry.org


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE
# 1.36 13-Mar-2005 markus

turn off accounting when switching to single user;
report bluhm at genua.de; ok henning, krw, deraadt


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE
# 1.35 16-Mar-2004 tedu

errno is not specified to be int, but something from errno.h. ok millert@


# 1.34 30-Oct-2003 deraadt

malloc failures in init? never. but try to be reasonable for one dumb one


Revision tags: OPENBSD_3_4_BASE
# 1.33 29-Jul-2003 deraadt

spaces


# 1.32 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.31 30-Mar-2003 deraadt

snprintf; millert ok


Revision tags: OPENBSD_3_3_BASE
# 1.30 11-Dec-2002 millert

Minor cosmetic nits picked while reading though init.c:
o Use STD{IN,OUT,ERR}_FILENO, not 0-2
o Call exit() from main, not return() (code is never reached anyway)
o Change two cases of '!' into "== NULL"


# 1.29 10-Oct-2002 millert

Style nits. Use STDERR_FILENO, not just 2. Also use parens with
return; David Hill


Revision tags: OPENBSD_3_2_BASE
# 1.28 03-Jul-2002 deraadt

ansi


# 1.27 09-Jun-2002 todd

rm trailing whitespace


# 1.26 22-May-2002 deraadt

strcpy, sprintf death; mpech ok


Revision tags: OPENBSD_3_1_BASE
# 1.25 19-Feb-2002 millert

We live in an ANSI C world. Remove lots of gratuitous #ifdef __STDC__ cruft.


# 1.24 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.23 05-Nov-2001 mpech

kill more registers;

millert@ ok


Revision tags: OPENBSD_3_0_BASE
# 1.22 09-Jul-2001 deraadt

correct type on last arg to execl(); nordin@cse.ogi.edu


Revision tags: OPENBSD_2_9_BASE
# 1.21 19-Jan-2001 deraadt

mark signal races i cannot fix at the moment


Revision tags: OPENBSD_2_8_BASE
# 1.20 20-Aug-2000 millert

Add calls to setusercontext() and login_get*(). We basically call
setusercontext() in most places where previously we did a setlogin().
Add default login.conf file and put root in the "daemon" login class.


# 1.19 06-Aug-2000 millert

Add DEFAULT_STATE macro to allow ramdisk init to set default state to
single_user, not runcom (/etc/rc).


Revision tags: OPENBSD_2_7_BASE
# 1.18 22-Jan-2000 deraadt

remove extra externs not needed because of unistd.h (rest of tree will be done later.. contact me if you want to help)


Revision tags: OPENBSD_2_6_BASE
# 1.17 03-Sep-1999 deraadt

have shutdown code run /etc/rc with arg of "shutdown"; rc.shutdown becomes completely admin-editable


# 1.16 06-Jul-1999 deraadt

if SIGUSR1 is received, kill gettys, run /etc/rc.shutdown, and halt the machine


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.15 03-Jun-1998 deraadt

zero sigaction before use


# 1.14 04-May-1998 deraadt

LETS_GET_BIG


Revision tags: OPENBSD_2_3_BASE
# 1.13 13-Apr-1998 millert

Use _PATH_DEV, not "/dev/"
Make init(8) call login_fbtab() correctly.


# 1.12 03-Mar-1998 deraadt

sigset_t; jraynard


Revision tags: OPENBSD_2_2_BASE
# 1.11 14-Sep-1997 deraadt

some -Wall


# 1.10 25-Jun-1997 kstailey

(foo *)0 -> NULL


Revision tags: OPENBSD_2_1_BASE
# 1.9 25-Mar-1997 deraadt

closelog() more often


# 1.8 22-Feb-1997 millert

Update to lite2 -- man page is the only thing that changed.


Revision tags: OPENBSD_2_0_BASE
# 1.7 31-Jul-1996 deraadt

at session termination, login_fbtab devs back to root


# 1.6 12-Jul-1996 deraadt

precheck getty devices for existance; if not there shut then down


# 1.5 12-Jul-1996 deraadt

do not ask for password if none set; from freebsd


# 1.4 12-Jul-1996 weingart

Fix netbsd pr bin/2620. Fix dangling pointer while I am at it.


# 1.3 23-Jun-1996 deraadt

update rcsid


# 1.2 22-May-1996 deraadt

libutil


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.67 31-Jan-2018 cheloha

Check GETTY_SPACING against the monotonic clock.

Ensures that we can use the check if the system clock is set backwards.

While here, move time retrieval into the child process in start_getty(),
and only get the time if se_started has been set.

ok millert@ tb@


# 1.66 06-Jan-2018 millert

unifdef LOGIN_CAP, we always want to use login.conf
OK jca@, no objection deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.65 16-Jun-2017 natano

s/CPU_LIDSUSPEND/CPU_LIDACTION/
ok mlarkin


# 1.64 03-May-2017 mestre

Use the safe idiom of cleaning sensitive data from memory with explicit_bzero,
instead of relying on other methods, after readpassphrase. Some programs on
this diff won't benefit that much since it happens near the terminal path, but
someone might copy the unsafe idiom to another program and place it where it
may leak sensitive data.

Discussed aeons ago with tb@, OK deraadt@ and beck@


Revision tags: OPENBSD_6_1_BASE
# 1.63 02-Mar-2017 natano

Add a new sysctl machdep.lidaction. The sysctl works as follows:

machdep.lidaction=0 # do nothing
machdep.lidaction=1 # suspend
machdep.lidaction=2 # hibernate

lidsuspend is just an alias for lidaction, so if you change one, the
other one will have the same value. The plan is to remove
machdep.lidsuspend eventually when people have upgraded their
/ets/sysctl.conf.

discussed with deraadt, who came up with the new MIB name
no objections mlarkin
ok stsp halex jcs


# 1.62 05-Sep-2016 gsoares

replace obsolete getpass() by readpassphrase()
OK tedu millert


# 1.61 04-Sep-2016 nicm

Use an RB tree instead of BDB to map process->session, ok tedu millert


# 1.60 27-Aug-2016 guenther

Pull in <sys/time.h> for struct timespec

ok deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.59 10-May-2016 bluhm

Do not close the stdio file desciptors in init(8), but dup2(2) them
from /dev/null. The code is taken from daemon(3). Also move this
operation to the beginning.
OK millert@ deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.58 01-Feb-2016 jca

Remove variable unneeded since introduction of crypt_checkpass

ok millert@


# 1.57 23-Dec-2015 mmcc

Use NULL rather than 0 for pointers. No binary change.


# 1.56 10-Dec-2015 mmcc

Remove NULL-checks before free(). ok tb@


# 1.55 18-Nov-2015 tedu

use _shadow getpwnam (and crypt_checkpass)


# 1.54 20-Aug-2015 deraadt

<stdlib.h> is included, so do not need to cast result from
malloc, calloc, realloc*
ok krw millert


Revision tags: OPENBSD_5_8_BASE
# 1.53 14-Jul-2015 millert

Use volatile sig_atomic_t for requested_transition since it is
modified inside signal handlers. Instead of returning a function
pointer, the state functions now return an enum for the next state.
This is used as an index into an array of function pointers to
do the actual state change in transition(). OK deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.52 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.51 06-Dec-2014 bluhm

Do not define the variable pid twice to avoid a compiler warning.
OK millert@


Revision tags: OPENBSD_5_6_BASE
# 1.50 22-Apr-2014 tedu

malloc/memset->calloc. with bonus null check. from peter malone.


Revision tags: OPENBSD_5_5_BASE
# 1.49 03-Jan-2014 millert

Do not raise the securelevel when transitioning from catatonia to
multiuser since we are not actually going multiuser. Fixes a problem
where the securelevel was raised for rc.shutdown even when reboot
was run from single user mode. OK deraadt@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.48 11-Feb-2013 millert

Ignore sysctl failure for CPU_LIDSUSPEND when errno is EOPNOTSUPP.
Just because CPU_LIDSUSPEND is defined in cpu.h does mean it is
actually supported by the hardware. OK halex@


# 1.47 11-Oct-2012 halex

fix "disable lidsuspend on shutdown":
- pull in machine/cpu.h so we can actually see CPU_LIDSUSPEND if it's there
- fix the resulting compilation errors now that the code is actually used

"Just go for it" deraadt@


Revision tags: OPENBSD_5_2_BASE
# 1.46 06-Apr-2012 deraadt

no need to (unsigned) a small constant


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.45 15-Oct-2010 dlg

freebsd uses SIGINT to request a reboot, we may as well be consistent.

pointed out by kettenis@ and deraadt@


# 1.44 14-Oct-2010 dlg

add a SIGQUIT handler that does the same as USR1 and USR2, except it
reboots the machine instead just halting or powering down.

diff from Jonathan Matthew
manpage tweaks from jmc@
ok deraadt@


# 1.43 29-Sep-2010 dcoppa

Add missing err.h include

OK deraadt@


Revision tags: OPENBSD_4_8_BASE
# 1.42 07-Aug-2010 phessler

disable lidsuspend when we are powering down

"I like this" marco@, "Sure" deraadt@


Revision tags: OPENBSD_4_7_BASE
# 1.41 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.40 03-Sep-2007 deraadt

malloc(n * m) -> calloc(n, m); ok espie


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.39 22-Jun-2006 deraadt

accept SIGUSR2. Like SIGUSR1, except it makes RB_POWERDOWN mandatory.
This will be used by kernel components which are trying to really really
power the system down. suggested and tested by jason


# 1.38 19-Mar-2006 otto

Fix mem leaks in error path. From NetBSD's coverity analysis. ok pat@
deraadt@


Revision tags: OPENBSD_3_9_BASE
# 1.37 12-Nov-2005 deraadt

use snprintf; dhill@mindcry.org


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE
# 1.36 13-Mar-2005 markus

turn off accounting when switching to single user;
report bluhm at genua.de; ok henning, krw, deraadt


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE
# 1.35 16-Mar-2004 tedu

errno is not specified to be int, but something from errno.h. ok millert@


# 1.34 30-Oct-2003 deraadt

malloc failures in init? never. but try to be reasonable for one dumb one


Revision tags: OPENBSD_3_4_BASE
# 1.33 29-Jul-2003 deraadt

spaces


# 1.32 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.31 30-Mar-2003 deraadt

snprintf; millert ok


Revision tags: OPENBSD_3_3_BASE
# 1.30 11-Dec-2002 millert

Minor cosmetic nits picked while reading though init.c:
o Use STD{IN,OUT,ERR}_FILENO, not 0-2
o Call exit() from main, not return() (code is never reached anyway)
o Change two cases of '!' into "== NULL"


# 1.29 10-Oct-2002 millert

Style nits. Use STDERR_FILENO, not just 2. Also use parens with
return; David Hill


Revision tags: OPENBSD_3_2_BASE
# 1.28 03-Jul-2002 deraadt

ansi


# 1.27 09-Jun-2002 todd

rm trailing whitespace


# 1.26 22-May-2002 deraadt

strcpy, sprintf death; mpech ok


Revision tags: OPENBSD_3_1_BASE
# 1.25 19-Feb-2002 millert

We live in an ANSI C world. Remove lots of gratuitous #ifdef __STDC__ cruft.


# 1.24 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.23 05-Nov-2001 mpech

kill more registers;

millert@ ok


Revision tags: OPENBSD_3_0_BASE
# 1.22 09-Jul-2001 deraadt

correct type on last arg to execl(); nordin@cse.ogi.edu


Revision tags: OPENBSD_2_9_BASE
# 1.21 19-Jan-2001 deraadt

mark signal races i cannot fix at the moment


Revision tags: OPENBSD_2_8_BASE
# 1.20 20-Aug-2000 millert

Add calls to setusercontext() and login_get*(). We basically call
setusercontext() in most places where previously we did a setlogin().
Add default login.conf file and put root in the "daemon" login class.


# 1.19 06-Aug-2000 millert

Add DEFAULT_STATE macro to allow ramdisk init to set default state to
single_user, not runcom (/etc/rc).


Revision tags: OPENBSD_2_7_BASE
# 1.18 22-Jan-2000 deraadt

remove extra externs not needed because of unistd.h (rest of tree will be done later.. contact me if you want to help)


Revision tags: OPENBSD_2_6_BASE
# 1.17 03-Sep-1999 deraadt

have shutdown code run /etc/rc with arg of "shutdown"; rc.shutdown becomes completely admin-editable


# 1.16 06-Jul-1999 deraadt

if SIGUSR1 is received, kill gettys, run /etc/rc.shutdown, and halt the machine


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.15 03-Jun-1998 deraadt

zero sigaction before use


# 1.14 04-May-1998 deraadt

LETS_GET_BIG


Revision tags: OPENBSD_2_3_BASE
# 1.13 13-Apr-1998 millert

Use _PATH_DEV, not "/dev/"
Make init(8) call login_fbtab() correctly.


# 1.12 03-Mar-1998 deraadt

sigset_t; jraynard


Revision tags: OPENBSD_2_2_BASE
# 1.11 14-Sep-1997 deraadt

some -Wall


# 1.10 25-Jun-1997 kstailey

(foo *)0 -> NULL


Revision tags: OPENBSD_2_1_BASE
# 1.9 25-Mar-1997 deraadt

closelog() more often


# 1.8 22-Feb-1997 millert

Update to lite2 -- man page is the only thing that changed.


Revision tags: OPENBSD_2_0_BASE
# 1.7 31-Jul-1996 deraadt

at session termination, login_fbtab devs back to root


# 1.6 12-Jul-1996 deraadt

precheck getty devices for existance; if not there shut then down


# 1.5 12-Jul-1996 deraadt

do not ask for password if none set; from freebsd


# 1.4 12-Jul-1996 weingart

Fix netbsd pr bin/2620. Fix dangling pointer while I am at it.


# 1.3 23-Jun-1996 deraadt

update rcsid


# 1.2 22-May-1996 deraadt

libutil


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.66 06-Jan-2018 millert

unifdef LOGIN_CAP, we always want to use login.conf
OK jca@, no objection deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.65 16-Jun-2017 natano

s/CPU_LIDSUSPEND/CPU_LIDACTION/
ok mlarkin


# 1.64 03-May-2017 mestre

Use the safe idiom of cleaning sensitive data from memory with explicit_bzero,
instead of relying on other methods, after readpassphrase. Some programs on
this diff won't benefit that much since it happens near the terminal path, but
someone might copy the unsafe idiom to another program and place it where it
may leak sensitive data.

Discussed aeons ago with tb@, OK deraadt@ and beck@


Revision tags: OPENBSD_6_1_BASE
# 1.63 02-Mar-2017 natano

Add a new sysctl machdep.lidaction. The sysctl works as follows:

machdep.lidaction=0 # do nothing
machdep.lidaction=1 # suspend
machdep.lidaction=2 # hibernate

lidsuspend is just an alias for lidaction, so if you change one, the
other one will have the same value. The plan is to remove
machdep.lidsuspend eventually when people have upgraded their
/ets/sysctl.conf.

discussed with deraadt, who came up with the new MIB name
no objections mlarkin
ok stsp halex jcs


# 1.62 05-Sep-2016 gsoares

replace obsolete getpass() by readpassphrase()
OK tedu millert


# 1.61 04-Sep-2016 nicm

Use an RB tree instead of BDB to map process->session, ok tedu millert


# 1.60 27-Aug-2016 guenther

Pull in <sys/time.h> for struct timespec

ok deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.59 10-May-2016 bluhm

Do not close the stdio file desciptors in init(8), but dup2(2) them
from /dev/null. The code is taken from daemon(3). Also move this
operation to the beginning.
OK millert@ deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.58 01-Feb-2016 jca

Remove variable unneeded since introduction of crypt_checkpass

ok millert@


# 1.57 23-Dec-2015 mmcc

Use NULL rather than 0 for pointers. No binary change.


# 1.56 10-Dec-2015 mmcc

Remove NULL-checks before free(). ok tb@


# 1.55 18-Nov-2015 tedu

use _shadow getpwnam (and crypt_checkpass)


# 1.54 20-Aug-2015 deraadt

<stdlib.h> is included, so do not need to cast result from
malloc, calloc, realloc*
ok krw millert


Revision tags: OPENBSD_5_8_BASE
# 1.53 14-Jul-2015 millert

Use volatile sig_atomic_t for requested_transition since it is
modified inside signal handlers. Instead of returning a function
pointer, the state functions now return an enum for the next state.
This is used as an index into an array of function pointers to
do the actual state change in transition(). OK deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.52 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.51 06-Dec-2014 bluhm

Do not define the variable pid twice to avoid a compiler warning.
OK millert@


Revision tags: OPENBSD_5_6_BASE
# 1.50 22-Apr-2014 tedu

malloc/memset->calloc. with bonus null check. from peter malone.


Revision tags: OPENBSD_5_5_BASE
# 1.49 03-Jan-2014 millert

Do not raise the securelevel when transitioning from catatonia to
multiuser since we are not actually going multiuser. Fixes a problem
where the securelevel was raised for rc.shutdown even when reboot
was run from single user mode. OK deraadt@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.48 11-Feb-2013 millert

Ignore sysctl failure for CPU_LIDSUSPEND when errno is EOPNOTSUPP.
Just because CPU_LIDSUSPEND is defined in cpu.h does mean it is
actually supported by the hardware. OK halex@


# 1.47 11-Oct-2012 halex

fix "disable lidsuspend on shutdown":
- pull in machine/cpu.h so we can actually see CPU_LIDSUSPEND if it's there
- fix the resulting compilation errors now that the code is actually used

"Just go for it" deraadt@


Revision tags: OPENBSD_5_2_BASE
# 1.46 06-Apr-2012 deraadt

no need to (unsigned) a small constant


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.45 15-Oct-2010 dlg

freebsd uses SIGINT to request a reboot, we may as well be consistent.

pointed out by kettenis@ and deraadt@


# 1.44 14-Oct-2010 dlg

add a SIGQUIT handler that does the same as USR1 and USR2, except it
reboots the machine instead just halting or powering down.

diff from Jonathan Matthew
manpage tweaks from jmc@
ok deraadt@


# 1.43 29-Sep-2010 dcoppa

Add missing err.h include

OK deraadt@


Revision tags: OPENBSD_4_8_BASE
# 1.42 07-Aug-2010 phessler

disable lidsuspend when we are powering down

"I like this" marco@, "Sure" deraadt@


Revision tags: OPENBSD_4_7_BASE
# 1.41 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.40 03-Sep-2007 deraadt

malloc(n * m) -> calloc(n, m); ok espie


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.39 22-Jun-2006 deraadt

accept SIGUSR2. Like SIGUSR1, except it makes RB_POWERDOWN mandatory.
This will be used by kernel components which are trying to really really
power the system down. suggested and tested by jason


# 1.38 19-Mar-2006 otto

Fix mem leaks in error path. From NetBSD's coverity analysis. ok pat@
deraadt@


Revision tags: OPENBSD_3_9_BASE
# 1.37 12-Nov-2005 deraadt

use snprintf; dhill@mindcry.org


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE
# 1.36 13-Mar-2005 markus

turn off accounting when switching to single user;
report bluhm at genua.de; ok henning, krw, deraadt


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE
# 1.35 16-Mar-2004 tedu

errno is not specified to be int, but something from errno.h. ok millert@


# 1.34 30-Oct-2003 deraadt

malloc failures in init? never. but try to be reasonable for one dumb one


Revision tags: OPENBSD_3_4_BASE
# 1.33 29-Jul-2003 deraadt

spaces


# 1.32 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.31 30-Mar-2003 deraadt

snprintf; millert ok


Revision tags: OPENBSD_3_3_BASE
# 1.30 11-Dec-2002 millert

Minor cosmetic nits picked while reading though init.c:
o Use STD{IN,OUT,ERR}_FILENO, not 0-2
o Call exit() from main, not return() (code is never reached anyway)
o Change two cases of '!' into "== NULL"


# 1.29 10-Oct-2002 millert

Style nits. Use STDERR_FILENO, not just 2. Also use parens with
return; David Hill


Revision tags: OPENBSD_3_2_BASE
# 1.28 03-Jul-2002 deraadt

ansi


# 1.27 09-Jun-2002 todd

rm trailing whitespace


# 1.26 22-May-2002 deraadt

strcpy, sprintf death; mpech ok


Revision tags: OPENBSD_3_1_BASE
# 1.25 19-Feb-2002 millert

We live in an ANSI C world. Remove lots of gratuitous #ifdef __STDC__ cruft.


# 1.24 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.23 05-Nov-2001 mpech

kill more registers;

millert@ ok


Revision tags: OPENBSD_3_0_BASE
# 1.22 09-Jul-2001 deraadt

correct type on last arg to execl(); nordin@cse.ogi.edu


Revision tags: OPENBSD_2_9_BASE
# 1.21 19-Jan-2001 deraadt

mark signal races i cannot fix at the moment


Revision tags: OPENBSD_2_8_BASE
# 1.20 20-Aug-2000 millert

Add calls to setusercontext() and login_get*(). We basically call
setusercontext() in most places where previously we did a setlogin().
Add default login.conf file and put root in the "daemon" login class.


# 1.19 06-Aug-2000 millert

Add DEFAULT_STATE macro to allow ramdisk init to set default state to
single_user, not runcom (/etc/rc).


Revision tags: OPENBSD_2_7_BASE
# 1.18 22-Jan-2000 deraadt

remove extra externs not needed because of unistd.h (rest of tree will be done later.. contact me if you want to help)


Revision tags: OPENBSD_2_6_BASE
# 1.17 03-Sep-1999 deraadt

have shutdown code run /etc/rc with arg of "shutdown"; rc.shutdown becomes completely admin-editable


# 1.16 06-Jul-1999 deraadt

if SIGUSR1 is received, kill gettys, run /etc/rc.shutdown, and halt the machine


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.15 03-Jun-1998 deraadt

zero sigaction before use


# 1.14 04-May-1998 deraadt

LETS_GET_BIG


Revision tags: OPENBSD_2_3_BASE
# 1.13 13-Apr-1998 millert

Use _PATH_DEV, not "/dev/"
Make init(8) call login_fbtab() correctly.


# 1.12 03-Mar-1998 deraadt

sigset_t; jraynard


Revision tags: OPENBSD_2_2_BASE
# 1.11 14-Sep-1997 deraadt

some -Wall


# 1.10 25-Jun-1997 kstailey

(foo *)0 -> NULL


Revision tags: OPENBSD_2_1_BASE
# 1.9 25-Mar-1997 deraadt

closelog() more often


# 1.8 22-Feb-1997 millert

Update to lite2 -- man page is the only thing that changed.


Revision tags: OPENBSD_2_0_BASE
# 1.7 31-Jul-1996 deraadt

at session termination, login_fbtab devs back to root


# 1.6 12-Jul-1996 deraadt

precheck getty devices for existance; if not there shut then down


# 1.5 12-Jul-1996 deraadt

do not ask for password if none set; from freebsd


# 1.4 12-Jul-1996 weingart

Fix netbsd pr bin/2620. Fix dangling pointer while I am at it.


# 1.3 23-Jun-1996 deraadt

update rcsid


# 1.2 22-May-1996 deraadt

libutil


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision