History log of /openbsd-current/sbin/shutdown/shutdown.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.56 28-Apr-2024 florian

gmtime(3) / locatime(3) can fail when timestamps are way off.

Add missing error checks to all calls under sbin/

Input & OK millert


Revision tags: OPENBSD_7_4_BASE OPENBSD_7_5_BASE
# 1.55 19-Apr-2023 jsg

remove duplicate includes


Revision tags: OPENBSD_7_3_BASE
# 1.54 13-Jan-2023 cheloha

shutdown(8): sig_atomic_t variables should be qualified 'volatile'


Revision tags: OPENBSD_7_0_BASE OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.53 12-Jul-2021 beck

Change the error reporting pattern throughout the tree when unveil
fails to report the path that the failure occured on. Suggested by
deraadt@ after some tech discussion.

Work done and verified by Ashton Fagg <ashton@fagg.id.au>

ok deraadt@ semarie@ claudio@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.52 03-Aug-2018 deraadt

Move pledge after getopt when we know whether the operation is reboot,
powerdown, halt, or singleuser. Before pledge, unveil access to
/dev/console, /etc/rc for singleuser entry, execute of /usr/bin/wall
to alert users, and creation of the fastboot and nologin files. Also
conditionally allow execute of halt, reboot, or the shell depending on mode.
Believe all scenarios were tested -- please exercise this one a bit.


# 1.51 07-Apr-2018 cheloha

Display local timezone in all deadline estimates.

Admins don't necessarily reside in the same timezone as the
machine. If an admin mistakenly schedules downtime for a
machine at the wrong time this could be quite bad.

Users, too, don't necessarily reside in the same timezone as the
machine. Saying the box is going down at "15:40" is potentially
ambiguous.

So, display the local timezone in all logs, broadcasts, printouts,
messages, etc. Give the admin a chance to correct the mistake; give
the user a better idea of when the box is actually going down.

This also updates the process' understanding of the present time
before printing estimates. The system's wall clock could have
changed after the shutdown was scheduled, making subsequent
broadcasts potentially misleading for users.

ok deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.50 19-Mar-2018 cheloha

Disallow "++minutes".

strtonum(3) accepts a single leading '+', so if we increment timearg we
allow input with two leading pluses. If we don't increment, we still
have a valid input for strtonum(3).

While here, use errstr to say what was wrong with timearg.

Don't increase the range for offsets yet: it exposes segfaults elsewhere
in the program that need to be addressed.

ok millert@ tb@


# 1.49 02-Mar-2018 cheloha

Refactor the countdown loop() to simplify it.

If we insert our offset into tlist[] and then process tlist[] like an
array we can eliminate many of the special cases and duplicate calls
in loop().

While we're at it, change struct interval and timewarn() to use time_t
to eliminate the need for some of the casting and add explicit long-long
suffixes to the constants in tlist[] to head off overflow if the code
wanders off.

With type-related input from tb@ and a style tweak from anton@.

ok tb@


# 1.48 24-Feb-2018 cheloha

Replace popen/setjmp/pclose with a manual pipe/fork/exec/wait.

We can limit the time we wait on wall(1) without the complexity
inherent to setjmp.

Actually wait (instead of waitpid) to pick up any straggler wall
processes from prior timewarn() calls.

With a tweak from millert@ to ensure we don't accidentally close
stdin before we exec wall.

ok millert@ tb@


# 1.47 04-Feb-2018 cheloha

fprintf(stderr -> warnx

ok jca@ tb@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.46 03-Apr-2017 fcambus

warn format string should be literal.

OK deraadt@, millert@


Revision tags: OPENBSD_6_1_BASE
# 1.45 01-Sep-2016 deraadt

Aggressively use dprintf, rather than crazy unchecked writes. Use
localtime() since it tends to work better than ctime() when some
filesystems are absent.
ok guenther


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.44 16-Nov-2015 deraadt

initially, pledge "stdio rpath wpath cpath getpw tty id proc exec", yes
it sounds like a lot, but this will eventually run the /etc/rc scripts
to shutdown, then run reboot or halt. After looking at getpw*, drop
pledge "getpw". Later drop to just "stdio exec"...

This depends on new pledge semantics for revoke(2).

with help from jca
ok guenther millert semarie tedu jca


Revision tags: OPENBSD_5_8_BASE
# 1.43 23-Apr-2015 deraadt

error in strtonum() conversion; found by Nathanael Rensen


# 1.42 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.41 15-Mar-2015 millert

tzfile.h is an internal header that should never have been installed.
What's worse, the tzfile.h that gets installed is over 20 years old
and doesn't match the real tzfile.h in libc/time. This makes the
tree safe for /usr/include/tzfile.h removal. The TM_YEAR_BASE
define has been moved to time.h temporarily until its usage is
replaced by 1900 in the tree. Actual removal of tzfile.h is pending
a ports build. Based on a diff from deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.40 21-Jan-2015 naddy

Build the argument list for halt/reboot without excessive use of
the conditional operator. Adapted from NetBSD. ok miod@


# 1.39 21-Jan-2015 naddy

Use plain "-p" to specify "halt and power down", for consistency
and compatibility with other BSDs. Adapted from FreeBSD.
Still permit the combination "-hp" as requested by many.
ok sthen@


# 1.38 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)


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.37 22-Nov-2013 deraadt

Whole bunch of (unsigned char) casts carefully added for ctype calls.
Careful second audit by millert


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.36 24-Dec-2009 sobrado

spelling fixes, from Brad Tilley; we will not fix src/sbin/dump/dump.h
as neither arrayified not arrayfied exist -- sanctioned dictionaries
like Merriam-Webster ones suggest a few alternatives (e.g., arrayed),
however these made up words are easy to understand and we are not
certain that current ones are not ok.

ok jmc@


# 1.35 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_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.34 18-Oct-2006 cloder

Replace gcc __attribute with __dead. Recompile yields no binary change.


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.33 02-Dec-2005 deraadt

more sig_atomic_t


Revision tags: OPENBSD_3_8_BASE
# 1.32 19-May-2005 jmc

sort options + sync usage();


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.31 24-Jan-2004 deraadt

minor knf


Revision tags: OPENBSD_3_4_BASE
# 1.30 30-Jul-2003 avsm

NULL -> (char *)NULL in execle; ok millert@


# 1.29 02-Jun-2003 millert

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


# 1.28 16-Apr-2003 mickey

use errx instead of fprintf+exit; millert@ ok


Revision tags: OPENBSD_3_3_BASE
# 1.27 08-Dec-2002 millert

GNU semantics say that if optstring begins with '-' then
each non-option shall be treated as arguments to option '\1'.

BSD getopt match '-' in optstring with a '-' on the command line.
This is used to support deprecated options like "su -" that would
otherwise prevent the use of getopt().

Resolving this simply requires that the leading '-' be moved somewhere
else (I moved it to the end of optstring) since position within
optstring is not meaningful.


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

ansi


# 1.25 26-May-2002 deraadt

pid_t cleanup


Revision tags: OPENBSD_3_1_BASE
# 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


# 1.21 07-Jul-2001 deraadt

major -Wall cleanup, almost complete


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

mark signal races i cannot fix at the moment


# 1.19 15-Jan-2001 deraadt

use _exit() in term handler if real signal


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.18 15-Jan-2000 ericj

add 'd' to usage. mention rc.shutdown in the man page.


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 19-Jul-1999 deraadt

if we run /etc/rc.shutdown ourselves, do it on /dev/console


# 1.15 29-Apr-1999 alex

Y2K fix: allow 'shutdown yymmddhhmm' to work in the next century.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.14 25-Apr-1998 millert

run rc.shutdown even if -r or -h is not specified


Revision tags: OPENBSD_2_2_BASE OPENBSD_2_3_BASE
# 1.13 04-Sep-1997 mickey

use err()/warn()/__progname where appropriate, consolidate string, some -Wall


# 1.12 24-Aug-1997 deraadt

give shutdown daemon own session; dima@tejblum.dnttm.rssi.ru


# 1.11 25-Jul-1997 mickey

do -d for reboot and halt


# 1.10 25-Jul-1997 mickey

-Wall


# 1.9 23-Jun-1997 downsj

Slightly cleaner. (Change nosync to an int, like the rest.)


# 1.8 22-Jun-1997 downsj

Support halt -p.


Revision tags: OPENBSD_2_1_BASE
# 1.7 15-Jan-1997 millert

getopt(3) returns -1 when out of args, not EOF, whee!


# 1.6 22-Dec-1996 deraadt

MAXHOSTNAMELEN, not +1


Revision tags: OPENBSD_2_0_BASE
# 1.5 20-Sep-1996 deraadt

call execle with the correct params; netbsd pr#2737, augustss@cs.chalmers.se


# 1.4 02-Sep-1996 deraadt

whoops


# 1.3 02-Sep-1996 deraadt

bad environ init; from brian@saturn.net


# 1.2 23-Jun-1996 deraadt

update rcsid


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.55 19-Apr-2023 jsg

remove duplicate includes


Revision tags: OPENBSD_7_3_BASE
# 1.54 13-Jan-2023 cheloha

shutdown(8): sig_atomic_t variables should be qualified 'volatile'


Revision tags: OPENBSD_7_0_BASE OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.53 12-Jul-2021 beck

Change the error reporting pattern throughout the tree when unveil
fails to report the path that the failure occured on. Suggested by
deraadt@ after some tech discussion.

Work done and verified by Ashton Fagg <ashton@fagg.id.au>

ok deraadt@ semarie@ claudio@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.52 03-Aug-2018 deraadt

Move pledge after getopt when we know whether the operation is reboot,
powerdown, halt, or singleuser. Before pledge, unveil access to
/dev/console, /etc/rc for singleuser entry, execute of /usr/bin/wall
to alert users, and creation of the fastboot and nologin files. Also
conditionally allow execute of halt, reboot, or the shell depending on mode.
Believe all scenarios were tested -- please exercise this one a bit.


# 1.51 07-Apr-2018 cheloha

Display local timezone in all deadline estimates.

Admins don't necessarily reside in the same timezone as the
machine. If an admin mistakenly schedules downtime for a
machine at the wrong time this could be quite bad.

Users, too, don't necessarily reside in the same timezone as the
machine. Saying the box is going down at "15:40" is potentially
ambiguous.

So, display the local timezone in all logs, broadcasts, printouts,
messages, etc. Give the admin a chance to correct the mistake; give
the user a better idea of when the box is actually going down.

This also updates the process' understanding of the present time
before printing estimates. The system's wall clock could have
changed after the shutdown was scheduled, making subsequent
broadcasts potentially misleading for users.

ok deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.50 19-Mar-2018 cheloha

Disallow "++minutes".

strtonum(3) accepts a single leading '+', so if we increment timearg we
allow input with two leading pluses. If we don't increment, we still
have a valid input for strtonum(3).

While here, use errstr to say what was wrong with timearg.

Don't increase the range for offsets yet: it exposes segfaults elsewhere
in the program that need to be addressed.

ok millert@ tb@


# 1.49 02-Mar-2018 cheloha

Refactor the countdown loop() to simplify it.

If we insert our offset into tlist[] and then process tlist[] like an
array we can eliminate many of the special cases and duplicate calls
in loop().

While we're at it, change struct interval and timewarn() to use time_t
to eliminate the need for some of the casting and add explicit long-long
suffixes to the constants in tlist[] to head off overflow if the code
wanders off.

With type-related input from tb@ and a style tweak from anton@.

ok tb@


# 1.48 24-Feb-2018 cheloha

Replace popen/setjmp/pclose with a manual pipe/fork/exec/wait.

We can limit the time we wait on wall(1) without the complexity
inherent to setjmp.

Actually wait (instead of waitpid) to pick up any straggler wall
processes from prior timewarn() calls.

With a tweak from millert@ to ensure we don't accidentally close
stdin before we exec wall.

ok millert@ tb@


# 1.47 04-Feb-2018 cheloha

fprintf(stderr -> warnx

ok jca@ tb@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.46 03-Apr-2017 fcambus

warn format string should be literal.

OK deraadt@, millert@


Revision tags: OPENBSD_6_1_BASE
# 1.45 01-Sep-2016 deraadt

Aggressively use dprintf, rather than crazy unchecked writes. Use
localtime() since it tends to work better than ctime() when some
filesystems are absent.
ok guenther


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.44 16-Nov-2015 deraadt

initially, pledge "stdio rpath wpath cpath getpw tty id proc exec", yes
it sounds like a lot, but this will eventually run the /etc/rc scripts
to shutdown, then run reboot or halt. After looking at getpw*, drop
pledge "getpw". Later drop to just "stdio exec"...

This depends on new pledge semantics for revoke(2).

with help from jca
ok guenther millert semarie tedu jca


Revision tags: OPENBSD_5_8_BASE
# 1.43 23-Apr-2015 deraadt

error in strtonum() conversion; found by Nathanael Rensen


# 1.42 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.41 15-Mar-2015 millert

tzfile.h is an internal header that should never have been installed.
What's worse, the tzfile.h that gets installed is over 20 years old
and doesn't match the real tzfile.h in libc/time. This makes the
tree safe for /usr/include/tzfile.h removal. The TM_YEAR_BASE
define has been moved to time.h temporarily until its usage is
replaced by 1900 in the tree. Actual removal of tzfile.h is pending
a ports build. Based on a diff from deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.40 21-Jan-2015 naddy

Build the argument list for halt/reboot without excessive use of
the conditional operator. Adapted from NetBSD. ok miod@


# 1.39 21-Jan-2015 naddy

Use plain "-p" to specify "halt and power down", for consistency
and compatibility with other BSDs. Adapted from FreeBSD.
Still permit the combination "-hp" as requested by many.
ok sthen@


# 1.38 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)


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.37 22-Nov-2013 deraadt

Whole bunch of (unsigned char) casts carefully added for ctype calls.
Careful second audit by millert


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.36 24-Dec-2009 sobrado

spelling fixes, from Brad Tilley; we will not fix src/sbin/dump/dump.h
as neither arrayified not arrayfied exist -- sanctioned dictionaries
like Merriam-Webster ones suggest a few alternatives (e.g., arrayed),
however these made up words are easy to understand and we are not
certain that current ones are not ok.

ok jmc@


# 1.35 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_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.34 18-Oct-2006 cloder

Replace gcc __attribute with __dead. Recompile yields no binary change.


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.33 02-Dec-2005 deraadt

more sig_atomic_t


Revision tags: OPENBSD_3_8_BASE
# 1.32 19-May-2005 jmc

sort options + sync usage();


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.31 24-Jan-2004 deraadt

minor knf


Revision tags: OPENBSD_3_4_BASE
# 1.30 30-Jul-2003 avsm

NULL -> (char *)NULL in execle; ok millert@


# 1.29 02-Jun-2003 millert

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


# 1.28 16-Apr-2003 mickey

use errx instead of fprintf+exit; millert@ ok


Revision tags: OPENBSD_3_3_BASE
# 1.27 08-Dec-2002 millert

GNU semantics say that if optstring begins with '-' then
each non-option shall be treated as arguments to option '\1'.

BSD getopt match '-' in optstring with a '-' on the command line.
This is used to support deprecated options like "su -" that would
otherwise prevent the use of getopt().

Resolving this simply requires that the leading '-' be moved somewhere
else (I moved it to the end of optstring) since position within
optstring is not meaningful.


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

ansi


# 1.25 26-May-2002 deraadt

pid_t cleanup


Revision tags: OPENBSD_3_1_BASE
# 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


# 1.21 07-Jul-2001 deraadt

major -Wall cleanup, almost complete


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

mark signal races i cannot fix at the moment


# 1.19 15-Jan-2001 deraadt

use _exit() in term handler if real signal


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.18 15-Jan-2000 ericj

add 'd' to usage. mention rc.shutdown in the man page.


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 19-Jul-1999 deraadt

if we run /etc/rc.shutdown ourselves, do it on /dev/console


# 1.15 29-Apr-1999 alex

Y2K fix: allow 'shutdown yymmddhhmm' to work in the next century.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.14 25-Apr-1998 millert

run rc.shutdown even if -r or -h is not specified


Revision tags: OPENBSD_2_2_BASE OPENBSD_2_3_BASE
# 1.13 04-Sep-1997 mickey

use err()/warn()/__progname where appropriate, consolidate string, some -Wall


# 1.12 24-Aug-1997 deraadt

give shutdown daemon own session; dima@tejblum.dnttm.rssi.ru


# 1.11 25-Jul-1997 mickey

do -d for reboot and halt


# 1.10 25-Jul-1997 mickey

-Wall


# 1.9 23-Jun-1997 downsj

Slightly cleaner. (Change nosync to an int, like the rest.)


# 1.8 22-Jun-1997 downsj

Support halt -p.


Revision tags: OPENBSD_2_1_BASE
# 1.7 15-Jan-1997 millert

getopt(3) returns -1 when out of args, not EOF, whee!


# 1.6 22-Dec-1996 deraadt

MAXHOSTNAMELEN, not +1


Revision tags: OPENBSD_2_0_BASE
# 1.5 20-Sep-1996 deraadt

call execle with the correct params; netbsd pr#2737, augustss@cs.chalmers.se


# 1.4 02-Sep-1996 deraadt

whoops


# 1.3 02-Sep-1996 deraadt

bad environ init; from brian@saturn.net


# 1.2 23-Jun-1996 deraadt

update rcsid


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.54 13-Jan-2023 cheloha

shutdown(8): sig_atomic_t variables should be qualified 'volatile'


Revision tags: OPENBSD_7_0_BASE OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.53 12-Jul-2021 beck

Change the error reporting pattern throughout the tree when unveil
fails to report the path that the failure occured on. Suggested by
deraadt@ after some tech discussion.

Work done and verified by Ashton Fagg <ashton@fagg.id.au>

ok deraadt@ semarie@ claudio@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.52 03-Aug-2018 deraadt

Move pledge after getopt when we know whether the operation is reboot,
powerdown, halt, or singleuser. Before pledge, unveil access to
/dev/console, /etc/rc for singleuser entry, execute of /usr/bin/wall
to alert users, and creation of the fastboot and nologin files. Also
conditionally allow execute of halt, reboot, or the shell depending on mode.
Believe all scenarios were tested -- please exercise this one a bit.


# 1.51 07-Apr-2018 cheloha

Display local timezone in all deadline estimates.

Admins don't necessarily reside in the same timezone as the
machine. If an admin mistakenly schedules downtime for a
machine at the wrong time this could be quite bad.

Users, too, don't necessarily reside in the same timezone as the
machine. Saying the box is going down at "15:40" is potentially
ambiguous.

So, display the local timezone in all logs, broadcasts, printouts,
messages, etc. Give the admin a chance to correct the mistake; give
the user a better idea of when the box is actually going down.

This also updates the process' understanding of the present time
before printing estimates. The system's wall clock could have
changed after the shutdown was scheduled, making subsequent
broadcasts potentially misleading for users.

ok deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.50 19-Mar-2018 cheloha

Disallow "++minutes".

strtonum(3) accepts a single leading '+', so if we increment timearg we
allow input with two leading pluses. If we don't increment, we still
have a valid input for strtonum(3).

While here, use errstr to say what was wrong with timearg.

Don't increase the range for offsets yet: it exposes segfaults elsewhere
in the program that need to be addressed.

ok millert@ tb@


# 1.49 02-Mar-2018 cheloha

Refactor the countdown loop() to simplify it.

If we insert our offset into tlist[] and then process tlist[] like an
array we can eliminate many of the special cases and duplicate calls
in loop().

While we're at it, change struct interval and timewarn() to use time_t
to eliminate the need for some of the casting and add explicit long-long
suffixes to the constants in tlist[] to head off overflow if the code
wanders off.

With type-related input from tb@ and a style tweak from anton@.

ok tb@


# 1.48 24-Feb-2018 cheloha

Replace popen/setjmp/pclose with a manual pipe/fork/exec/wait.

We can limit the time we wait on wall(1) without the complexity
inherent to setjmp.

Actually wait (instead of waitpid) to pick up any straggler wall
processes from prior timewarn() calls.

With a tweak from millert@ to ensure we don't accidentally close
stdin before we exec wall.

ok millert@ tb@


# 1.47 04-Feb-2018 cheloha

fprintf(stderr -> warnx

ok jca@ tb@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.46 03-Apr-2017 fcambus

warn format string should be literal.

OK deraadt@, millert@


Revision tags: OPENBSD_6_1_BASE
# 1.45 01-Sep-2016 deraadt

Aggressively use dprintf, rather than crazy unchecked writes. Use
localtime() since it tends to work better than ctime() when some
filesystems are absent.
ok guenther


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.44 16-Nov-2015 deraadt

initially, pledge "stdio rpath wpath cpath getpw tty id proc exec", yes
it sounds like a lot, but this will eventually run the /etc/rc scripts
to shutdown, then run reboot or halt. After looking at getpw*, drop
pledge "getpw". Later drop to just "stdio exec"...

This depends on new pledge semantics for revoke(2).

with help from jca
ok guenther millert semarie tedu jca


Revision tags: OPENBSD_5_8_BASE
# 1.43 23-Apr-2015 deraadt

error in strtonum() conversion; found by Nathanael Rensen


# 1.42 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.41 15-Mar-2015 millert

tzfile.h is an internal header that should never have been installed.
What's worse, the tzfile.h that gets installed is over 20 years old
and doesn't match the real tzfile.h in libc/time. This makes the
tree safe for /usr/include/tzfile.h removal. The TM_YEAR_BASE
define has been moved to time.h temporarily until its usage is
replaced by 1900 in the tree. Actual removal of tzfile.h is pending
a ports build. Based on a diff from deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.40 21-Jan-2015 naddy

Build the argument list for halt/reboot without excessive use of
the conditional operator. Adapted from NetBSD. ok miod@


# 1.39 21-Jan-2015 naddy

Use plain "-p" to specify "halt and power down", for consistency
and compatibility with other BSDs. Adapted from FreeBSD.
Still permit the combination "-hp" as requested by many.
ok sthen@


# 1.38 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)


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.37 22-Nov-2013 deraadt

Whole bunch of (unsigned char) casts carefully added for ctype calls.
Careful second audit by millert


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.36 24-Dec-2009 sobrado

spelling fixes, from Brad Tilley; we will not fix src/sbin/dump/dump.h
as neither arrayified not arrayfied exist -- sanctioned dictionaries
like Merriam-Webster ones suggest a few alternatives (e.g., arrayed),
however these made up words are easy to understand and we are not
certain that current ones are not ok.

ok jmc@


# 1.35 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_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.34 18-Oct-2006 cloder

Replace gcc __attribute with __dead. Recompile yields no binary change.


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.33 02-Dec-2005 deraadt

more sig_atomic_t


Revision tags: OPENBSD_3_8_BASE
# 1.32 19-May-2005 jmc

sort options + sync usage();


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.31 24-Jan-2004 deraadt

minor knf


Revision tags: OPENBSD_3_4_BASE
# 1.30 30-Jul-2003 avsm

NULL -> (char *)NULL in execle; ok millert@


# 1.29 02-Jun-2003 millert

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


# 1.28 16-Apr-2003 mickey

use errx instead of fprintf+exit; millert@ ok


Revision tags: OPENBSD_3_3_BASE
# 1.27 08-Dec-2002 millert

GNU semantics say that if optstring begins with '-' then
each non-option shall be treated as arguments to option '\1'.

BSD getopt match '-' in optstring with a '-' on the command line.
This is used to support deprecated options like "su -" that would
otherwise prevent the use of getopt().

Resolving this simply requires that the leading '-' be moved somewhere
else (I moved it to the end of optstring) since position within
optstring is not meaningful.


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

ansi


# 1.25 26-May-2002 deraadt

pid_t cleanup


Revision tags: OPENBSD_3_1_BASE
# 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


# 1.21 07-Jul-2001 deraadt

major -Wall cleanup, almost complete


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

mark signal races i cannot fix at the moment


# 1.19 15-Jan-2001 deraadt

use _exit() in term handler if real signal


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.18 15-Jan-2000 ericj

add 'd' to usage. mention rc.shutdown in the man page.


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 19-Jul-1999 deraadt

if we run /etc/rc.shutdown ourselves, do it on /dev/console


# 1.15 29-Apr-1999 alex

Y2K fix: allow 'shutdown yymmddhhmm' to work in the next century.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.14 25-Apr-1998 millert

run rc.shutdown even if -r or -h is not specified


Revision tags: OPENBSD_2_2_BASE OPENBSD_2_3_BASE
# 1.13 04-Sep-1997 mickey

use err()/warn()/__progname where appropriate, consolidate string, some -Wall


# 1.12 24-Aug-1997 deraadt

give shutdown daemon own session; dima@tejblum.dnttm.rssi.ru


# 1.11 25-Jul-1997 mickey

do -d for reboot and halt


# 1.10 25-Jul-1997 mickey

-Wall


# 1.9 23-Jun-1997 downsj

Slightly cleaner. (Change nosync to an int, like the rest.)


# 1.8 22-Jun-1997 downsj

Support halt -p.


Revision tags: OPENBSD_2_1_BASE
# 1.7 15-Jan-1997 millert

getopt(3) returns -1 when out of args, not EOF, whee!


# 1.6 22-Dec-1996 deraadt

MAXHOSTNAMELEN, not +1


Revision tags: OPENBSD_2_0_BASE
# 1.5 20-Sep-1996 deraadt

call execle with the correct params; netbsd pr#2737, augustss@cs.chalmers.se


# 1.4 02-Sep-1996 deraadt

whoops


# 1.3 02-Sep-1996 deraadt

bad environ init; from brian@saturn.net


# 1.2 23-Jun-1996 deraadt

update rcsid


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.53 12-Jul-2021 beck

Change the error reporting pattern throughout the tree when unveil
fails to report the path that the failure occured on. Suggested by
deraadt@ after some tech discussion.

Work done and verified by Ashton Fagg <ashton@fagg.id.au>

ok deraadt@ semarie@ claudio@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.52 03-Aug-2018 deraadt

Move pledge after getopt when we know whether the operation is reboot,
powerdown, halt, or singleuser. Before pledge, unveil access to
/dev/console, /etc/rc for singleuser entry, execute of /usr/bin/wall
to alert users, and creation of the fastboot and nologin files. Also
conditionally allow execute of halt, reboot, or the shell depending on mode.
Believe all scenarios were tested -- please exercise this one a bit.


# 1.51 07-Apr-2018 cheloha

Display local timezone in all deadline estimates.

Admins don't necessarily reside in the same timezone as the
machine. If an admin mistakenly schedules downtime for a
machine at the wrong time this could be quite bad.

Users, too, don't necessarily reside in the same timezone as the
machine. Saying the box is going down at "15:40" is potentially
ambiguous.

So, display the local timezone in all logs, broadcasts, printouts,
messages, etc. Give the admin a chance to correct the mistake; give
the user a better idea of when the box is actually going down.

This also updates the process' understanding of the present time
before printing estimates. The system's wall clock could have
changed after the shutdown was scheduled, making subsequent
broadcasts potentially misleading for users.

ok deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.50 19-Mar-2018 cheloha

Disallow "++minutes".

strtonum(3) accepts a single leading '+', so if we increment timearg we
allow input with two leading pluses. If we don't increment, we still
have a valid input for strtonum(3).

While here, use errstr to say what was wrong with timearg.

Don't increase the range for offsets yet: it exposes segfaults elsewhere
in the program that need to be addressed.

ok millert@ tb@


# 1.49 02-Mar-2018 cheloha

Refactor the countdown loop() to simplify it.

If we insert our offset into tlist[] and then process tlist[] like an
array we can eliminate many of the special cases and duplicate calls
in loop().

While we're at it, change struct interval and timewarn() to use time_t
to eliminate the need for some of the casting and add explicit long-long
suffixes to the constants in tlist[] to head off overflow if the code
wanders off.

With type-related input from tb@ and a style tweak from anton@.

ok tb@


# 1.48 24-Feb-2018 cheloha

Replace popen/setjmp/pclose with a manual pipe/fork/exec/wait.

We can limit the time we wait on wall(1) without the complexity
inherent to setjmp.

Actually wait (instead of waitpid) to pick up any straggler wall
processes from prior timewarn() calls.

With a tweak from millert@ to ensure we don't accidentally close
stdin before we exec wall.

ok millert@ tb@


# 1.47 04-Feb-2018 cheloha

fprintf(stderr -> warnx

ok jca@ tb@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.46 03-Apr-2017 fcambus

warn format string should be literal.

OK deraadt@, millert@


Revision tags: OPENBSD_6_1_BASE
# 1.45 01-Sep-2016 deraadt

Aggressively use dprintf, rather than crazy unchecked writes. Use
localtime() since it tends to work better than ctime() when some
filesystems are absent.
ok guenther


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.44 16-Nov-2015 deraadt

initially, pledge "stdio rpath wpath cpath getpw tty id proc exec", yes
it sounds like a lot, but this will eventually run the /etc/rc scripts
to shutdown, then run reboot or halt. After looking at getpw*, drop
pledge "getpw". Later drop to just "stdio exec"...

This depends on new pledge semantics for revoke(2).

with help from jca
ok guenther millert semarie tedu jca


Revision tags: OPENBSD_5_8_BASE
# 1.43 23-Apr-2015 deraadt

error in strtonum() conversion; found by Nathanael Rensen


# 1.42 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.41 15-Mar-2015 millert

tzfile.h is an internal header that should never have been installed.
What's worse, the tzfile.h that gets installed is over 20 years old
and doesn't match the real tzfile.h in libc/time. This makes the
tree safe for /usr/include/tzfile.h removal. The TM_YEAR_BASE
define has been moved to time.h temporarily until its usage is
replaced by 1900 in the tree. Actual removal of tzfile.h is pending
a ports build. Based on a diff from deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.40 21-Jan-2015 naddy

Build the argument list for halt/reboot without excessive use of
the conditional operator. Adapted from NetBSD. ok miod@


# 1.39 21-Jan-2015 naddy

Use plain "-p" to specify "halt and power down", for consistency
and compatibility with other BSDs. Adapted from FreeBSD.
Still permit the combination "-hp" as requested by many.
ok sthen@


# 1.38 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)


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.37 22-Nov-2013 deraadt

Whole bunch of (unsigned char) casts carefully added for ctype calls.
Careful second audit by millert


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.36 24-Dec-2009 sobrado

spelling fixes, from Brad Tilley; we will not fix src/sbin/dump/dump.h
as neither arrayified not arrayfied exist -- sanctioned dictionaries
like Merriam-Webster ones suggest a few alternatives (e.g., arrayed),
however these made up words are easy to understand and we are not
certain that current ones are not ok.

ok jmc@


# 1.35 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_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.34 18-Oct-2006 cloder

Replace gcc __attribute with __dead. Recompile yields no binary change.


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.33 02-Dec-2005 deraadt

more sig_atomic_t


Revision tags: OPENBSD_3_8_BASE
# 1.32 19-May-2005 jmc

sort options + sync usage();


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.31 24-Jan-2004 deraadt

minor knf


Revision tags: OPENBSD_3_4_BASE
# 1.30 30-Jul-2003 avsm

NULL -> (char *)NULL in execle; ok millert@


# 1.29 02-Jun-2003 millert

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


# 1.28 16-Apr-2003 mickey

use errx instead of fprintf+exit; millert@ ok


Revision tags: OPENBSD_3_3_BASE
# 1.27 08-Dec-2002 millert

GNU semantics say that if optstring begins with '-' then
each non-option shall be treated as arguments to option '\1'.

BSD getopt match '-' in optstring with a '-' on the command line.
This is used to support deprecated options like "su -" that would
otherwise prevent the use of getopt().

Resolving this simply requires that the leading '-' be moved somewhere
else (I moved it to the end of optstring) since position within
optstring is not meaningful.


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

ansi


# 1.25 26-May-2002 deraadt

pid_t cleanup


Revision tags: OPENBSD_3_1_BASE
# 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


# 1.21 07-Jul-2001 deraadt

major -Wall cleanup, almost complete


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

mark signal races i cannot fix at the moment


# 1.19 15-Jan-2001 deraadt

use _exit() in term handler if real signal


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.18 15-Jan-2000 ericj

add 'd' to usage. mention rc.shutdown in the man page.


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 19-Jul-1999 deraadt

if we run /etc/rc.shutdown ourselves, do it on /dev/console


# 1.15 29-Apr-1999 alex

Y2K fix: allow 'shutdown yymmddhhmm' to work in the next century.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.14 25-Apr-1998 millert

run rc.shutdown even if -r or -h is not specified


Revision tags: OPENBSD_2_2_BASE OPENBSD_2_3_BASE
# 1.13 04-Sep-1997 mickey

use err()/warn()/__progname where appropriate, consolidate string, some -Wall


# 1.12 24-Aug-1997 deraadt

give shutdown daemon own session; dima@tejblum.dnttm.rssi.ru


# 1.11 25-Jul-1997 mickey

do -d for reboot and halt


# 1.10 25-Jul-1997 mickey

-Wall


# 1.9 23-Jun-1997 downsj

Slightly cleaner. (Change nosync to an int, like the rest.)


# 1.8 22-Jun-1997 downsj

Support halt -p.


Revision tags: OPENBSD_2_1_BASE
# 1.7 15-Jan-1997 millert

getopt(3) returns -1 when out of args, not EOF, whee!


# 1.6 22-Dec-1996 deraadt

MAXHOSTNAMELEN, not +1


Revision tags: OPENBSD_2_0_BASE
# 1.5 20-Sep-1996 deraadt

call execle with the correct params; netbsd pr#2737, augustss@cs.chalmers.se


# 1.4 02-Sep-1996 deraadt

whoops


# 1.3 02-Sep-1996 deraadt

bad environ init; from brian@saturn.net


# 1.2 23-Jun-1996 deraadt

update rcsid


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.52 03-Aug-2018 deraadt

Move pledge after getopt when we know whether the operation is reboot,
powerdown, halt, or singleuser. Before pledge, unveil access to
/dev/console, /etc/rc for singleuser entry, execute of /usr/bin/wall
to alert users, and creation of the fastboot and nologin files. Also
conditionally allow execute of halt, reboot, or the shell depending on mode.
Believe all scenarios were tested -- please exercise this one a bit.


# 1.51 07-Apr-2018 cheloha

Display local timezone in all deadline estimates.

Admins don't necessarily reside in the same timezone as the
machine. If an admin mistakenly schedules downtime for a
machine at the wrong time this could be quite bad.

Users, too, don't necessarily reside in the same timezone as the
machine. Saying the box is going down at "15:40" is potentially
ambiguous.

So, display the local timezone in all logs, broadcasts, printouts,
messages, etc. Give the admin a chance to correct the mistake; give
the user a better idea of when the box is actually going down.

This also updates the process' understanding of the present time
before printing estimates. The system's wall clock could have
changed after the shutdown was scheduled, making subsequent
broadcasts potentially misleading for users.

ok deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.50 19-Mar-2018 cheloha

Disallow "++minutes".

strtonum(3) accepts a single leading '+', so if we increment timearg we
allow input with two leading pluses. If we don't increment, we still
have a valid input for strtonum(3).

While here, use errstr to say what was wrong with timearg.

Don't increase the range for offsets yet: it exposes segfaults elsewhere
in the program that need to be addressed.

ok millert@ tb@


# 1.49 02-Mar-2018 cheloha

Refactor the countdown loop() to simplify it.

If we insert our offset into tlist[] and then process tlist[] like an
array we can eliminate many of the special cases and duplicate calls
in loop().

While we're at it, change struct interval and timewarn() to use time_t
to eliminate the need for some of the casting and add explicit long-long
suffixes to the constants in tlist[] to head off overflow if the code
wanders off.

With type-related input from tb@ and a style tweak from anton@.

ok tb@


# 1.48 24-Feb-2018 cheloha

Replace popen/setjmp/pclose with a manual pipe/fork/exec/wait.

We can limit the time we wait on wall(1) without the complexity
inherent to setjmp.

Actually wait (instead of waitpid) to pick up any straggler wall
processes from prior timewarn() calls.

With a tweak from millert@ to ensure we don't accidentally close
stdin before we exec wall.

ok millert@ tb@


# 1.47 04-Feb-2018 cheloha

fprintf(stderr -> warnx

ok jca@ tb@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.46 03-Apr-2017 fcambus

warn format string should be literal.

OK deraadt@, millert@


Revision tags: OPENBSD_6_1_BASE
# 1.45 01-Sep-2016 deraadt

Aggressively use dprintf, rather than crazy unchecked writes. Use
localtime() since it tends to work better than ctime() when some
filesystems are absent.
ok guenther


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.44 16-Nov-2015 deraadt

initially, pledge "stdio rpath wpath cpath getpw tty id proc exec", yes
it sounds like a lot, but this will eventually run the /etc/rc scripts
to shutdown, then run reboot or halt. After looking at getpw*, drop
pledge "getpw". Later drop to just "stdio exec"...

This depends on new pledge semantics for revoke(2).

with help from jca
ok guenther millert semarie tedu jca


Revision tags: OPENBSD_5_8_BASE
# 1.43 23-Apr-2015 deraadt

error in strtonum() conversion; found by Nathanael Rensen


# 1.42 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.41 15-Mar-2015 millert

tzfile.h is an internal header that should never have been installed.
What's worse, the tzfile.h that gets installed is over 20 years old
and doesn't match the real tzfile.h in libc/time. This makes the
tree safe for /usr/include/tzfile.h removal. The TM_YEAR_BASE
define has been moved to time.h temporarily until its usage is
replaced by 1900 in the tree. Actual removal of tzfile.h is pending
a ports build. Based on a diff from deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.40 21-Jan-2015 naddy

Build the argument list for halt/reboot without excessive use of
the conditional operator. Adapted from NetBSD. ok miod@


# 1.39 21-Jan-2015 naddy

Use plain "-p" to specify "halt and power down", for consistency
and compatibility with other BSDs. Adapted from FreeBSD.
Still permit the combination "-hp" as requested by many.
ok sthen@


# 1.38 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)


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.37 22-Nov-2013 deraadt

Whole bunch of (unsigned char) casts carefully added for ctype calls.
Careful second audit by millert


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.36 24-Dec-2009 sobrado

spelling fixes, from Brad Tilley; we will not fix src/sbin/dump/dump.h
as neither arrayified not arrayfied exist -- sanctioned dictionaries
like Merriam-Webster ones suggest a few alternatives (e.g., arrayed),
however these made up words are easy to understand and we are not
certain that current ones are not ok.

ok jmc@


# 1.35 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_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.34 18-Oct-2006 cloder

Replace gcc __attribute with __dead. Recompile yields no binary change.


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.33 02-Dec-2005 deraadt

more sig_atomic_t


Revision tags: OPENBSD_3_8_BASE
# 1.32 19-May-2005 jmc

sort options + sync usage();


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.31 24-Jan-2004 deraadt

minor knf


Revision tags: OPENBSD_3_4_BASE
# 1.30 30-Jul-2003 avsm

NULL -> (char *)NULL in execle; ok millert@


# 1.29 02-Jun-2003 millert

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


# 1.28 16-Apr-2003 mickey

use errx instead of fprintf+exit; millert@ ok


Revision tags: OPENBSD_3_3_BASE
# 1.27 08-Dec-2002 millert

GNU semantics say that if optstring begins with '-' then
each non-option shall be treated as arguments to option '\1'.

BSD getopt match '-' in optstring with a '-' on the command line.
This is used to support deprecated options like "su -" that would
otherwise prevent the use of getopt().

Resolving this simply requires that the leading '-' be moved somewhere
else (I moved it to the end of optstring) since position within
optstring is not meaningful.


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

ansi


# 1.25 26-May-2002 deraadt

pid_t cleanup


Revision tags: OPENBSD_3_1_BASE
# 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


# 1.21 07-Jul-2001 deraadt

major -Wall cleanup, almost complete


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

mark signal races i cannot fix at the moment


# 1.19 15-Jan-2001 deraadt

use _exit() in term handler if real signal


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.18 15-Jan-2000 ericj

add 'd' to usage. mention rc.shutdown in the man page.


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 19-Jul-1999 deraadt

if we run /etc/rc.shutdown ourselves, do it on /dev/console


# 1.15 29-Apr-1999 alex

Y2K fix: allow 'shutdown yymmddhhmm' to work in the next century.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.14 25-Apr-1998 millert

run rc.shutdown even if -r or -h is not specified


Revision tags: OPENBSD_2_2_BASE OPENBSD_2_3_BASE
# 1.13 04-Sep-1997 mickey

use err()/warn()/__progname where appropriate, consolidate string, some -Wall


# 1.12 24-Aug-1997 deraadt

give shutdown daemon own session; dima@tejblum.dnttm.rssi.ru


# 1.11 25-Jul-1997 mickey

do -d for reboot and halt


# 1.10 25-Jul-1997 mickey

-Wall


# 1.9 23-Jun-1997 downsj

Slightly cleaner. (Change nosync to an int, like the rest.)


# 1.8 22-Jun-1997 downsj

Support halt -p.


Revision tags: OPENBSD_2_1_BASE
# 1.7 15-Jan-1997 millert

getopt(3) returns -1 when out of args, not EOF, whee!


# 1.6 22-Dec-1996 deraadt

MAXHOSTNAMELEN, not +1


Revision tags: OPENBSD_2_0_BASE
# 1.5 20-Sep-1996 deraadt

call execle with the correct params; netbsd pr#2737, augustss@cs.chalmers.se


# 1.4 02-Sep-1996 deraadt

whoops


# 1.3 02-Sep-1996 deraadt

bad environ init; from brian@saturn.net


# 1.2 23-Jun-1996 deraadt

update rcsid


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.51 07-Apr-2018 cheloha

Display local timezone in all deadline estimates.

Admins don't necessarily reside in the same timezone as the
machine. If an admin mistakenly schedules downtime for a
machine at the wrong time this could be quite bad.

Users, too, don't necessarily reside in the same timezone as the
machine. Saying the box is going down at "15:40" is potentially
ambiguous.

So, display the local timezone in all logs, broadcasts, printouts,
messages, etc. Give the admin a chance to correct the mistake; give
the user a better idea of when the box is actually going down.

This also updates the process' understanding of the present time
before printing estimates. The system's wall clock could have
changed after the shutdown was scheduled, making subsequent
broadcasts potentially misleading for users.

ok deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.50 19-Mar-2018 cheloha

Disallow "++minutes".

strtonum(3) accepts a single leading '+', so if we increment timearg we
allow input with two leading pluses. If we don't increment, we still
have a valid input for strtonum(3).

While here, use errstr to say what was wrong with timearg.

Don't increase the range for offsets yet: it exposes segfaults elsewhere
in the program that need to be addressed.

ok millert@ tb@


# 1.49 02-Mar-2018 cheloha

Refactor the countdown loop() to simplify it.

If we insert our offset into tlist[] and then process tlist[] like an
array we can eliminate many of the special cases and duplicate calls
in loop().

While we're at it, change struct interval and timewarn() to use time_t
to eliminate the need for some of the casting and add explicit long-long
suffixes to the constants in tlist[] to head off overflow if the code
wanders off.

With type-related input from tb@ and a style tweak from anton@.

ok tb@


# 1.48 24-Feb-2018 cheloha

Replace popen/setjmp/pclose with a manual pipe/fork/exec/wait.

We can limit the time we wait on wall(1) without the complexity
inherent to setjmp.

Actually wait (instead of waitpid) to pick up any straggler wall
processes from prior timewarn() calls.

With a tweak from millert@ to ensure we don't accidentally close
stdin before we exec wall.

ok millert@ tb@


# 1.47 04-Feb-2018 cheloha

fprintf(stderr -> warnx

ok jca@ tb@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.46 03-Apr-2017 fcambus

warn format string should be literal.

OK deraadt@, millert@


Revision tags: OPENBSD_6_1_BASE
# 1.45 01-Sep-2016 deraadt

Aggressively use dprintf, rather than crazy unchecked writes. Use
localtime() since it tends to work better than ctime() when some
filesystems are absent.
ok guenther


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.44 16-Nov-2015 deraadt

initially, pledge "stdio rpath wpath cpath getpw tty id proc exec", yes
it sounds like a lot, but this will eventually run the /etc/rc scripts
to shutdown, then run reboot or halt. After looking at getpw*, drop
pledge "getpw". Later drop to just "stdio exec"...

This depends on new pledge semantics for revoke(2).

with help from jca
ok guenther millert semarie tedu jca


Revision tags: OPENBSD_5_8_BASE
# 1.43 23-Apr-2015 deraadt

error in strtonum() conversion; found by Nathanael Rensen


# 1.42 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.41 15-Mar-2015 millert

tzfile.h is an internal header that should never have been installed.
What's worse, the tzfile.h that gets installed is over 20 years old
and doesn't match the real tzfile.h in libc/time. This makes the
tree safe for /usr/include/tzfile.h removal. The TM_YEAR_BASE
define has been moved to time.h temporarily until its usage is
replaced by 1900 in the tree. Actual removal of tzfile.h is pending
a ports build. Based on a diff from deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.40 21-Jan-2015 naddy

Build the argument list for halt/reboot without excessive use of
the conditional operator. Adapted from NetBSD. ok miod@


# 1.39 21-Jan-2015 naddy

Use plain "-p" to specify "halt and power down", for consistency
and compatibility with other BSDs. Adapted from FreeBSD.
Still permit the combination "-hp" as requested by many.
ok sthen@


# 1.38 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)


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.37 22-Nov-2013 deraadt

Whole bunch of (unsigned char) casts carefully added for ctype calls.
Careful second audit by millert


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.36 24-Dec-2009 sobrado

spelling fixes, from Brad Tilley; we will not fix src/sbin/dump/dump.h
as neither arrayified not arrayfied exist -- sanctioned dictionaries
like Merriam-Webster ones suggest a few alternatives (e.g., arrayed),
however these made up words are easy to understand and we are not
certain that current ones are not ok.

ok jmc@


# 1.35 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_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.34 18-Oct-2006 cloder

Replace gcc __attribute with __dead. Recompile yields no binary change.


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.33 02-Dec-2005 deraadt

more sig_atomic_t


Revision tags: OPENBSD_3_8_BASE
# 1.32 19-May-2005 jmc

sort options + sync usage();


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.31 24-Jan-2004 deraadt

minor knf


Revision tags: OPENBSD_3_4_BASE
# 1.30 30-Jul-2003 avsm

NULL -> (char *)NULL in execle; ok millert@


# 1.29 02-Jun-2003 millert

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


# 1.28 16-Apr-2003 mickey

use errx instead of fprintf+exit; millert@ ok


Revision tags: OPENBSD_3_3_BASE
# 1.27 08-Dec-2002 millert

GNU semantics say that if optstring begins with '-' then
each non-option shall be treated as arguments to option '\1'.

BSD getopt match '-' in optstring with a '-' on the command line.
This is used to support deprecated options like "su -" that would
otherwise prevent the use of getopt().

Resolving this simply requires that the leading '-' be moved somewhere
else (I moved it to the end of optstring) since position within
optstring is not meaningful.


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

ansi


# 1.25 26-May-2002 deraadt

pid_t cleanup


Revision tags: OPENBSD_3_1_BASE
# 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


# 1.21 07-Jul-2001 deraadt

major -Wall cleanup, almost complete


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

mark signal races i cannot fix at the moment


# 1.19 15-Jan-2001 deraadt

use _exit() in term handler if real signal


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.18 15-Jan-2000 ericj

add 'd' to usage. mention rc.shutdown in the man page.


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 19-Jul-1999 deraadt

if we run /etc/rc.shutdown ourselves, do it on /dev/console


# 1.15 29-Apr-1999 alex

Y2K fix: allow 'shutdown yymmddhhmm' to work in the next century.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.14 25-Apr-1998 millert

run rc.shutdown even if -r or -h is not specified


Revision tags: OPENBSD_2_2_BASE OPENBSD_2_3_BASE
# 1.13 04-Sep-1997 mickey

use err()/warn()/__progname where appropriate, consolidate string, some -Wall


# 1.12 24-Aug-1997 deraadt

give shutdown daemon own session; dima@tejblum.dnttm.rssi.ru


# 1.11 25-Jul-1997 mickey

do -d for reboot and halt


# 1.10 25-Jul-1997 mickey

-Wall


# 1.9 23-Jun-1997 downsj

Slightly cleaner. (Change nosync to an int, like the rest.)


# 1.8 22-Jun-1997 downsj

Support halt -p.


Revision tags: OPENBSD_2_1_BASE
# 1.7 15-Jan-1997 millert

getopt(3) returns -1 when out of args, not EOF, whee!


# 1.6 22-Dec-1996 deraadt

MAXHOSTNAMELEN, not +1


Revision tags: OPENBSD_2_0_BASE
# 1.5 20-Sep-1996 deraadt

call execle with the correct params; netbsd pr#2737, augustss@cs.chalmers.se


# 1.4 02-Sep-1996 deraadt

whoops


# 1.3 02-Sep-1996 deraadt

bad environ init; from brian@saturn.net


# 1.2 23-Jun-1996 deraadt

update rcsid


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


Revision tags: OPENBSD_6_3_BASE
# 1.50 19-Mar-2018 cheloha

Disallow "++minutes".

strtonum(3) accepts a single leading '+', so if we increment timearg we
allow input with two leading pluses. If we don't increment, we still
have a valid input for strtonum(3).

While here, use errstr to say what was wrong with timearg.

Don't increase the range for offsets yet: it exposes segfaults elsewhere
in the program that need to be addressed.

ok millert@ tb@


# 1.49 02-Mar-2018 cheloha

Refactor the countdown loop() to simplify it.

If we insert our offset into tlist[] and then process tlist[] like an
array we can eliminate many of the special cases and duplicate calls
in loop().

While we're at it, change struct interval and timewarn() to use time_t
to eliminate the need for some of the casting and add explicit long-long
suffixes to the constants in tlist[] to head off overflow if the code
wanders off.

With type-related input from tb@ and a style tweak from anton@.

ok tb@


# 1.48 24-Feb-2018 cheloha

Replace popen/setjmp/pclose with a manual pipe/fork/exec/wait.

We can limit the time we wait on wall(1) without the complexity
inherent to setjmp.

Actually wait (instead of waitpid) to pick up any straggler wall
processes from prior timewarn() calls.

With a tweak from millert@ to ensure we don't accidentally close
stdin before we exec wall.

ok millert@ tb@


# 1.47 04-Feb-2018 cheloha

fprintf(stderr -> warnx

ok jca@ tb@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.46 03-Apr-2017 fcambus

warn format string should be literal.

OK deraadt@, millert@


Revision tags: OPENBSD_6_1_BASE
# 1.45 01-Sep-2016 deraadt

Aggressively use dprintf, rather than crazy unchecked writes. Use
localtime() since it tends to work better than ctime() when some
filesystems are absent.
ok guenther


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.44 16-Nov-2015 deraadt

initially, pledge "stdio rpath wpath cpath getpw tty id proc exec", yes
it sounds like a lot, but this will eventually run the /etc/rc scripts
to shutdown, then run reboot or halt. After looking at getpw*, drop
pledge "getpw". Later drop to just "stdio exec"...

This depends on new pledge semantics for revoke(2).

with help from jca
ok guenther millert semarie tedu jca


Revision tags: OPENBSD_5_8_BASE
# 1.43 23-Apr-2015 deraadt

error in strtonum() conversion; found by Nathanael Rensen


# 1.42 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.41 15-Mar-2015 millert

tzfile.h is an internal header that should never have been installed.
What's worse, the tzfile.h that gets installed is over 20 years old
and doesn't match the real tzfile.h in libc/time. This makes the
tree safe for /usr/include/tzfile.h removal. The TM_YEAR_BASE
define has been moved to time.h temporarily until its usage is
replaced by 1900 in the tree. Actual removal of tzfile.h is pending
a ports build. Based on a diff from deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.40 21-Jan-2015 naddy

Build the argument list for halt/reboot without excessive use of
the conditional operator. Adapted from NetBSD. ok miod@


# 1.39 21-Jan-2015 naddy

Use plain "-p" to specify "halt and power down", for consistency
and compatibility with other BSDs. Adapted from FreeBSD.
Still permit the combination "-hp" as requested by many.
ok sthen@


# 1.38 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)


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.37 22-Nov-2013 deraadt

Whole bunch of (unsigned char) casts carefully added for ctype calls.
Careful second audit by millert


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.36 24-Dec-2009 sobrado

spelling fixes, from Brad Tilley; we will not fix src/sbin/dump/dump.h
as neither arrayified not arrayfied exist -- sanctioned dictionaries
like Merriam-Webster ones suggest a few alternatives (e.g., arrayed),
however these made up words are easy to understand and we are not
certain that current ones are not ok.

ok jmc@


# 1.35 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_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.34 18-Oct-2006 cloder

Replace gcc __attribute with __dead. Recompile yields no binary change.


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.33 02-Dec-2005 deraadt

more sig_atomic_t


Revision tags: OPENBSD_3_8_BASE
# 1.32 19-May-2005 jmc

sort options + sync usage();


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.31 24-Jan-2004 deraadt

minor knf


Revision tags: OPENBSD_3_4_BASE
# 1.30 30-Jul-2003 avsm

NULL -> (char *)NULL in execle; ok millert@


# 1.29 02-Jun-2003 millert

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


# 1.28 16-Apr-2003 mickey

use errx instead of fprintf+exit; millert@ ok


Revision tags: OPENBSD_3_3_BASE
# 1.27 08-Dec-2002 millert

GNU semantics say that if optstring begins with '-' then
each non-option shall be treated as arguments to option '\1'.

BSD getopt match '-' in optstring with a '-' on the command line.
This is used to support deprecated options like "su -" that would
otherwise prevent the use of getopt().

Resolving this simply requires that the leading '-' be moved somewhere
else (I moved it to the end of optstring) since position within
optstring is not meaningful.


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

ansi


# 1.25 26-May-2002 deraadt

pid_t cleanup


Revision tags: OPENBSD_3_1_BASE
# 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


# 1.21 07-Jul-2001 deraadt

major -Wall cleanup, almost complete


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

mark signal races i cannot fix at the moment


# 1.19 15-Jan-2001 deraadt

use _exit() in term handler if real signal


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.18 15-Jan-2000 ericj

add 'd' to usage. mention rc.shutdown in the man page.


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 19-Jul-1999 deraadt

if we run /etc/rc.shutdown ourselves, do it on /dev/console


# 1.15 29-Apr-1999 alex

Y2K fix: allow 'shutdown yymmddhhmm' to work in the next century.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.14 25-Apr-1998 millert

run rc.shutdown even if -r or -h is not specified


Revision tags: OPENBSD_2_2_BASE OPENBSD_2_3_BASE
# 1.13 04-Sep-1997 mickey

use err()/warn()/__progname where appropriate, consolidate string, some -Wall


# 1.12 24-Aug-1997 deraadt

give shutdown daemon own session; dima@tejblum.dnttm.rssi.ru


# 1.11 25-Jul-1997 mickey

do -d for reboot and halt


# 1.10 25-Jul-1997 mickey

-Wall


# 1.9 23-Jun-1997 downsj

Slightly cleaner. (Change nosync to an int, like the rest.)


# 1.8 22-Jun-1997 downsj

Support halt -p.


Revision tags: OPENBSD_2_1_BASE
# 1.7 15-Jan-1997 millert

getopt(3) returns -1 when out of args, not EOF, whee!


# 1.6 22-Dec-1996 deraadt

MAXHOSTNAMELEN, not +1


Revision tags: OPENBSD_2_0_BASE
# 1.5 20-Sep-1996 deraadt

call execle with the correct params; netbsd pr#2737, augustss@cs.chalmers.se


# 1.4 02-Sep-1996 deraadt

whoops


# 1.3 02-Sep-1996 deraadt

bad environ init; from brian@saturn.net


# 1.2 23-Jun-1996 deraadt

update rcsid


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.49 02-Mar-2018 cheloha

Refactor the countdown loop() to simplify it.

If we insert our offset into tlist[] and then process tlist[] like an
array we can eliminate many of the special cases and duplicate calls
in loop().

While we're at it, change struct interval and timewarn() to use time_t
to eliminate the need for some of the casting and add explicit long-long
suffixes to the constants in tlist[] to head off overflow if the code
wanders off.

With type-related input from tb@ and a style tweak from anton@.

ok tb@


# 1.48 24-Feb-2018 cheloha

Replace popen/setjmp/pclose with a manual pipe/fork/exec/wait.

We can limit the time we wait on wall(1) without the complexity
inherent to setjmp.

Actually wait (instead of waitpid) to pick up any straggler wall
processes from prior timewarn() calls.

With a tweak from millert@ to ensure we don't accidentally close
stdin before we exec wall.

ok millert@ tb@


# 1.47 04-Feb-2018 cheloha

fprintf(stderr -> warnx

ok jca@ tb@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.46 03-Apr-2017 fcambus

warn format string should be literal.

OK deraadt@, millert@


Revision tags: OPENBSD_6_1_BASE
# 1.45 01-Sep-2016 deraadt

Aggressively use dprintf, rather than crazy unchecked writes. Use
localtime() since it tends to work better than ctime() when some
filesystems are absent.
ok guenther


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.44 16-Nov-2015 deraadt

initially, pledge "stdio rpath wpath cpath getpw tty id proc exec", yes
it sounds like a lot, but this will eventually run the /etc/rc scripts
to shutdown, then run reboot or halt. After looking at getpw*, drop
pledge "getpw". Later drop to just "stdio exec"...

This depends on new pledge semantics for revoke(2).

with help from jca
ok guenther millert semarie tedu jca


Revision tags: OPENBSD_5_8_BASE
# 1.43 23-Apr-2015 deraadt

error in strtonum() conversion; found by Nathanael Rensen


# 1.42 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.41 15-Mar-2015 millert

tzfile.h is an internal header that should never have been installed.
What's worse, the tzfile.h that gets installed is over 20 years old
and doesn't match the real tzfile.h in libc/time. This makes the
tree safe for /usr/include/tzfile.h removal. The TM_YEAR_BASE
define has been moved to time.h temporarily until its usage is
replaced by 1900 in the tree. Actual removal of tzfile.h is pending
a ports build. Based on a diff from deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.40 21-Jan-2015 naddy

Build the argument list for halt/reboot without excessive use of
the conditional operator. Adapted from NetBSD. ok miod@


# 1.39 21-Jan-2015 naddy

Use plain "-p" to specify "halt and power down", for consistency
and compatibility with other BSDs. Adapted from FreeBSD.
Still permit the combination "-hp" as requested by many.
ok sthen@


# 1.38 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)


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.37 22-Nov-2013 deraadt

Whole bunch of (unsigned char) casts carefully added for ctype calls.
Careful second audit by millert


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.36 24-Dec-2009 sobrado

spelling fixes, from Brad Tilley; we will not fix src/sbin/dump/dump.h
as neither arrayified not arrayfied exist -- sanctioned dictionaries
like Merriam-Webster ones suggest a few alternatives (e.g., arrayed),
however these made up words are easy to understand and we are not
certain that current ones are not ok.

ok jmc@


# 1.35 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_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.34 18-Oct-2006 cloder

Replace gcc __attribute with __dead. Recompile yields no binary change.


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.33 02-Dec-2005 deraadt

more sig_atomic_t


Revision tags: OPENBSD_3_8_BASE
# 1.32 19-May-2005 jmc

sort options + sync usage();


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.31 24-Jan-2004 deraadt

minor knf


Revision tags: OPENBSD_3_4_BASE
# 1.30 30-Jul-2003 avsm

NULL -> (char *)NULL in execle; ok millert@


# 1.29 02-Jun-2003 millert

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


# 1.28 16-Apr-2003 mickey

use errx instead of fprintf+exit; millert@ ok


Revision tags: OPENBSD_3_3_BASE
# 1.27 08-Dec-2002 millert

GNU semantics say that if optstring begins with '-' then
each non-option shall be treated as arguments to option '\1'.

BSD getopt match '-' in optstring with a '-' on the command line.
This is used to support deprecated options like "su -" that would
otherwise prevent the use of getopt().

Resolving this simply requires that the leading '-' be moved somewhere
else (I moved it to the end of optstring) since position within
optstring is not meaningful.


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

ansi


# 1.25 26-May-2002 deraadt

pid_t cleanup


Revision tags: OPENBSD_3_1_BASE
# 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


# 1.21 07-Jul-2001 deraadt

major -Wall cleanup, almost complete


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

mark signal races i cannot fix at the moment


# 1.19 15-Jan-2001 deraadt

use _exit() in term handler if real signal


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.18 15-Jan-2000 ericj

add 'd' to usage. mention rc.shutdown in the man page.


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 19-Jul-1999 deraadt

if we run /etc/rc.shutdown ourselves, do it on /dev/console


# 1.15 29-Apr-1999 alex

Y2K fix: allow 'shutdown yymmddhhmm' to work in the next century.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.14 25-Apr-1998 millert

run rc.shutdown even if -r or -h is not specified


Revision tags: OPENBSD_2_2_BASE OPENBSD_2_3_BASE
# 1.13 04-Sep-1997 mickey

use err()/warn()/__progname where appropriate, consolidate string, some -Wall


# 1.12 24-Aug-1997 deraadt

give shutdown daemon own session; dima@tejblum.dnttm.rssi.ru


# 1.11 25-Jul-1997 mickey

do -d for reboot and halt


# 1.10 25-Jul-1997 mickey

-Wall


# 1.9 23-Jun-1997 downsj

Slightly cleaner. (Change nosync to an int, like the rest.)


# 1.8 22-Jun-1997 downsj

Support halt -p.


Revision tags: OPENBSD_2_1_BASE
# 1.7 15-Jan-1997 millert

getopt(3) returns -1 when out of args, not EOF, whee!


# 1.6 22-Dec-1996 deraadt

MAXHOSTNAMELEN, not +1


Revision tags: OPENBSD_2_0_BASE
# 1.5 20-Sep-1996 deraadt

call execle with the correct params; netbsd pr#2737, augustss@cs.chalmers.se


# 1.4 02-Sep-1996 deraadt

whoops


# 1.3 02-Sep-1996 deraadt

bad environ init; from brian@saturn.net


# 1.2 23-Jun-1996 deraadt

update rcsid


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.48 24-Feb-2018 cheloha

Replace popen/setjmp/pclose with a manual pipe/fork/exec/wait.

We can limit the time we wait on wall(1) without the complexity
inherent to setjmp.

Actually wait (instead of waitpid) to pick up any straggler wall
processes from prior timewarn() calls.

With a tweak from millert@ to ensure we don't accidentally close
stdin before we exec wall.

ok millert@ tb@


# 1.47 04-Feb-2018 cheloha

fprintf(stderr -> warnx

ok jca@ tb@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.46 03-Apr-2017 fcambus

warn format string should be literal.

OK deraadt@, millert@


Revision tags: OPENBSD_6_1_BASE
# 1.45 01-Sep-2016 deraadt

Aggressively use dprintf, rather than crazy unchecked writes. Use
localtime() since it tends to work better than ctime() when some
filesystems are absent.
ok guenther


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.44 16-Nov-2015 deraadt

initially, pledge "stdio rpath wpath cpath getpw tty id proc exec", yes
it sounds like a lot, but this will eventually run the /etc/rc scripts
to shutdown, then run reboot or halt. After looking at getpw*, drop
pledge "getpw". Later drop to just "stdio exec"...

This depends on new pledge semantics for revoke(2).

with help from jca
ok guenther millert semarie tedu jca


Revision tags: OPENBSD_5_8_BASE
# 1.43 23-Apr-2015 deraadt

error in strtonum() conversion; found by Nathanael Rensen


# 1.42 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.41 15-Mar-2015 millert

tzfile.h is an internal header that should never have been installed.
What's worse, the tzfile.h that gets installed is over 20 years old
and doesn't match the real tzfile.h in libc/time. This makes the
tree safe for /usr/include/tzfile.h removal. The TM_YEAR_BASE
define has been moved to time.h temporarily until its usage is
replaced by 1900 in the tree. Actual removal of tzfile.h is pending
a ports build. Based on a diff from deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.40 21-Jan-2015 naddy

Build the argument list for halt/reboot without excessive use of
the conditional operator. Adapted from NetBSD. ok miod@


# 1.39 21-Jan-2015 naddy

Use plain "-p" to specify "halt and power down", for consistency
and compatibility with other BSDs. Adapted from FreeBSD.
Still permit the combination "-hp" as requested by many.
ok sthen@


# 1.38 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)


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.37 22-Nov-2013 deraadt

Whole bunch of (unsigned char) casts carefully added for ctype calls.
Careful second audit by millert


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.36 24-Dec-2009 sobrado

spelling fixes, from Brad Tilley; we will not fix src/sbin/dump/dump.h
as neither arrayified not arrayfied exist -- sanctioned dictionaries
like Merriam-Webster ones suggest a few alternatives (e.g., arrayed),
however these made up words are easy to understand and we are not
certain that current ones are not ok.

ok jmc@


# 1.35 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_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.34 18-Oct-2006 cloder

Replace gcc __attribute with __dead. Recompile yields no binary change.


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.33 02-Dec-2005 deraadt

more sig_atomic_t


Revision tags: OPENBSD_3_8_BASE
# 1.32 19-May-2005 jmc

sort options + sync usage();


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.31 24-Jan-2004 deraadt

minor knf


Revision tags: OPENBSD_3_4_BASE
# 1.30 30-Jul-2003 avsm

NULL -> (char *)NULL in execle; ok millert@


# 1.29 02-Jun-2003 millert

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


# 1.28 16-Apr-2003 mickey

use errx instead of fprintf+exit; millert@ ok


Revision tags: OPENBSD_3_3_BASE
# 1.27 08-Dec-2002 millert

GNU semantics say that if optstring begins with '-' then
each non-option shall be treated as arguments to option '\1'.

BSD getopt match '-' in optstring with a '-' on the command line.
This is used to support deprecated options like "su -" that would
otherwise prevent the use of getopt().

Resolving this simply requires that the leading '-' be moved somewhere
else (I moved it to the end of optstring) since position within
optstring is not meaningful.


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

ansi


# 1.25 26-May-2002 deraadt

pid_t cleanup


Revision tags: OPENBSD_3_1_BASE
# 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


# 1.21 07-Jul-2001 deraadt

major -Wall cleanup, almost complete


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

mark signal races i cannot fix at the moment


# 1.19 15-Jan-2001 deraadt

use _exit() in term handler if real signal


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.18 15-Jan-2000 ericj

add 'd' to usage. mention rc.shutdown in the man page.


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 19-Jul-1999 deraadt

if we run /etc/rc.shutdown ourselves, do it on /dev/console


# 1.15 29-Apr-1999 alex

Y2K fix: allow 'shutdown yymmddhhmm' to work in the next century.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.14 25-Apr-1998 millert

run rc.shutdown even if -r or -h is not specified


Revision tags: OPENBSD_2_2_BASE OPENBSD_2_3_BASE
# 1.13 04-Sep-1997 mickey

use err()/warn()/__progname where appropriate, consolidate string, some -Wall


# 1.12 24-Aug-1997 deraadt

give shutdown daemon own session; dima@tejblum.dnttm.rssi.ru


# 1.11 25-Jul-1997 mickey

do -d for reboot and halt


# 1.10 25-Jul-1997 mickey

-Wall


# 1.9 23-Jun-1997 downsj

Slightly cleaner. (Change nosync to an int, like the rest.)


# 1.8 22-Jun-1997 downsj

Support halt -p.


Revision tags: OPENBSD_2_1_BASE
# 1.7 15-Jan-1997 millert

getopt(3) returns -1 when out of args, not EOF, whee!


# 1.6 22-Dec-1996 deraadt

MAXHOSTNAMELEN, not +1


Revision tags: OPENBSD_2_0_BASE
# 1.5 20-Sep-1996 deraadt

call execle with the correct params; netbsd pr#2737, augustss@cs.chalmers.se


# 1.4 02-Sep-1996 deraadt

whoops


# 1.3 02-Sep-1996 deraadt

bad environ init; from brian@saturn.net


# 1.2 23-Jun-1996 deraadt

update rcsid


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.47 04-Feb-2018 cheloha

fprintf(stderr -> warnx

ok jca@ tb@


Revision tags: OPENBSD_6_2_BASE
# 1.46 03-Apr-2017 fcambus

warn format string should be literal.

OK deraadt@, millert@


Revision tags: OPENBSD_6_1_BASE
# 1.45 01-Sep-2016 deraadt

Aggressively use dprintf, rather than crazy unchecked writes. Use
localtime() since it tends to work better than ctime() when some
filesystems are absent.
ok guenther


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.44 16-Nov-2015 deraadt

initially, pledge "stdio rpath wpath cpath getpw tty id proc exec", yes
it sounds like a lot, but this will eventually run the /etc/rc scripts
to shutdown, then run reboot or halt. After looking at getpw*, drop
pledge "getpw". Later drop to just "stdio exec"...

This depends on new pledge semantics for revoke(2).

with help from jca
ok guenther millert semarie tedu jca


Revision tags: OPENBSD_5_8_BASE
# 1.43 23-Apr-2015 deraadt

error in strtonum() conversion; found by Nathanael Rensen


# 1.42 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.41 15-Mar-2015 millert

tzfile.h is an internal header that should never have been installed.
What's worse, the tzfile.h that gets installed is over 20 years old
and doesn't match the real tzfile.h in libc/time. This makes the
tree safe for /usr/include/tzfile.h removal. The TM_YEAR_BASE
define has been moved to time.h temporarily until its usage is
replaced by 1900 in the tree. Actual removal of tzfile.h is pending
a ports build. Based on a diff from deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.40 21-Jan-2015 naddy

Build the argument list for halt/reboot without excessive use of
the conditional operator. Adapted from NetBSD. ok miod@


# 1.39 21-Jan-2015 naddy

Use plain "-p" to specify "halt and power down", for consistency
and compatibility with other BSDs. Adapted from FreeBSD.
Still permit the combination "-hp" as requested by many.
ok sthen@


# 1.38 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)


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.37 22-Nov-2013 deraadt

Whole bunch of (unsigned char) casts carefully added for ctype calls.
Careful second audit by millert


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.36 24-Dec-2009 sobrado

spelling fixes, from Brad Tilley; we will not fix src/sbin/dump/dump.h
as neither arrayified not arrayfied exist -- sanctioned dictionaries
like Merriam-Webster ones suggest a few alternatives (e.g., arrayed),
however these made up words are easy to understand and we are not
certain that current ones are not ok.

ok jmc@


# 1.35 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_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.34 18-Oct-2006 cloder

Replace gcc __attribute with __dead. Recompile yields no binary change.


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.33 02-Dec-2005 deraadt

more sig_atomic_t


Revision tags: OPENBSD_3_8_BASE
# 1.32 19-May-2005 jmc

sort options + sync usage();


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.31 24-Jan-2004 deraadt

minor knf


Revision tags: OPENBSD_3_4_BASE
# 1.30 30-Jul-2003 avsm

NULL -> (char *)NULL in execle; ok millert@


# 1.29 02-Jun-2003 millert

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


# 1.28 16-Apr-2003 mickey

use errx instead of fprintf+exit; millert@ ok


Revision tags: OPENBSD_3_3_BASE
# 1.27 08-Dec-2002 millert

GNU semantics say that if optstring begins with '-' then
each non-option shall be treated as arguments to option '\1'.

BSD getopt match '-' in optstring with a '-' on the command line.
This is used to support deprecated options like "su -" that would
otherwise prevent the use of getopt().

Resolving this simply requires that the leading '-' be moved somewhere
else (I moved it to the end of optstring) since position within
optstring is not meaningful.


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

ansi


# 1.25 26-May-2002 deraadt

pid_t cleanup


Revision tags: OPENBSD_3_1_BASE
# 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


# 1.21 07-Jul-2001 deraadt

major -Wall cleanup, almost complete


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

mark signal races i cannot fix at the moment


# 1.19 15-Jan-2001 deraadt

use _exit() in term handler if real signal


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.18 15-Jan-2000 ericj

add 'd' to usage. mention rc.shutdown in the man page.


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 19-Jul-1999 deraadt

if we run /etc/rc.shutdown ourselves, do it on /dev/console


# 1.15 29-Apr-1999 alex

Y2K fix: allow 'shutdown yymmddhhmm' to work in the next century.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.14 25-Apr-1998 millert

run rc.shutdown even if -r or -h is not specified


Revision tags: OPENBSD_2_2_BASE OPENBSD_2_3_BASE
# 1.13 04-Sep-1997 mickey

use err()/warn()/__progname where appropriate, consolidate string, some -Wall


# 1.12 24-Aug-1997 deraadt

give shutdown daemon own session; dima@tejblum.dnttm.rssi.ru


# 1.11 25-Jul-1997 mickey

do -d for reboot and halt


# 1.10 25-Jul-1997 mickey

-Wall


# 1.9 23-Jun-1997 downsj

Slightly cleaner. (Change nosync to an int, like the rest.)


# 1.8 22-Jun-1997 downsj

Support halt -p.


Revision tags: OPENBSD_2_1_BASE
# 1.7 15-Jan-1997 millert

getopt(3) returns -1 when out of args, not EOF, whee!


# 1.6 22-Dec-1996 deraadt

MAXHOSTNAMELEN, not +1


Revision tags: OPENBSD_2_0_BASE
# 1.5 20-Sep-1996 deraadt

call execle with the correct params; netbsd pr#2737, augustss@cs.chalmers.se


# 1.4 02-Sep-1996 deraadt

whoops


# 1.3 02-Sep-1996 deraadt

bad environ init; from brian@saturn.net


# 1.2 23-Jun-1996 deraadt

update rcsid


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


Revision tags: OPENBSD_6_2_BASE
# 1.46 03-Apr-2017 fcambus

warn format string should be literal.

OK deraadt@, millert@


Revision tags: OPENBSD_6_1_BASE
# 1.45 01-Sep-2016 deraadt

Aggressively use dprintf, rather than crazy unchecked writes. Use
localtime() since it tends to work better than ctime() when some
filesystems are absent.
ok guenther


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.44 16-Nov-2015 deraadt

initially, pledge "stdio rpath wpath cpath getpw tty id proc exec", yes
it sounds like a lot, but this will eventually run the /etc/rc scripts
to shutdown, then run reboot or halt. After looking at getpw*, drop
pledge "getpw". Later drop to just "stdio exec"...

This depends on new pledge semantics for revoke(2).

with help from jca
ok guenther millert semarie tedu jca


Revision tags: OPENBSD_5_8_BASE
# 1.43 23-Apr-2015 deraadt

error in strtonum() conversion; found by Nathanael Rensen


# 1.42 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.41 15-Mar-2015 millert

tzfile.h is an internal header that should never have been installed.
What's worse, the tzfile.h that gets installed is over 20 years old
and doesn't match the real tzfile.h in libc/time. This makes the
tree safe for /usr/include/tzfile.h removal. The TM_YEAR_BASE
define has been moved to time.h temporarily until its usage is
replaced by 1900 in the tree. Actual removal of tzfile.h is pending
a ports build. Based on a diff from deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.40 21-Jan-2015 naddy

Build the argument list for halt/reboot without excessive use of
the conditional operator. Adapted from NetBSD. ok miod@


# 1.39 21-Jan-2015 naddy

Use plain "-p" to specify "halt and power down", for consistency
and compatibility with other BSDs. Adapted from FreeBSD.
Still permit the combination "-hp" as requested by many.
ok sthen@


# 1.38 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)


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.37 22-Nov-2013 deraadt

Whole bunch of (unsigned char) casts carefully added for ctype calls.
Careful second audit by millert


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.36 24-Dec-2009 sobrado

spelling fixes, from Brad Tilley; we will not fix src/sbin/dump/dump.h
as neither arrayified not arrayfied exist -- sanctioned dictionaries
like Merriam-Webster ones suggest a few alternatives (e.g., arrayed),
however these made up words are easy to understand and we are not
certain that current ones are not ok.

ok jmc@


# 1.35 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_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.34 18-Oct-2006 cloder

Replace gcc __attribute with __dead. Recompile yields no binary change.


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.33 02-Dec-2005 deraadt

more sig_atomic_t


Revision tags: OPENBSD_3_8_BASE
# 1.32 19-May-2005 jmc

sort options + sync usage();


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.31 24-Jan-2004 deraadt

minor knf


Revision tags: OPENBSD_3_4_BASE
# 1.30 30-Jul-2003 avsm

NULL -> (char *)NULL in execle; ok millert@


# 1.29 02-Jun-2003 millert

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


# 1.28 16-Apr-2003 mickey

use errx instead of fprintf+exit; millert@ ok


Revision tags: OPENBSD_3_3_BASE
# 1.27 08-Dec-2002 millert

GNU semantics say that if optstring begins with '-' then
each non-option shall be treated as arguments to option '\1'.

BSD getopt match '-' in optstring with a '-' on the command line.
This is used to support deprecated options like "su -" that would
otherwise prevent the use of getopt().

Resolving this simply requires that the leading '-' be moved somewhere
else (I moved it to the end of optstring) since position within
optstring is not meaningful.


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

ansi


# 1.25 26-May-2002 deraadt

pid_t cleanup


Revision tags: OPENBSD_3_1_BASE
# 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


# 1.21 07-Jul-2001 deraadt

major -Wall cleanup, almost complete


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

mark signal races i cannot fix at the moment


# 1.19 15-Jan-2001 deraadt

use _exit() in term handler if real signal


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.18 15-Jan-2000 ericj

add 'd' to usage. mention rc.shutdown in the man page.


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 19-Jul-1999 deraadt

if we run /etc/rc.shutdown ourselves, do it on /dev/console


# 1.15 29-Apr-1999 alex

Y2K fix: allow 'shutdown yymmddhhmm' to work in the next century.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.14 25-Apr-1998 millert

run rc.shutdown even if -r or -h is not specified


Revision tags: OPENBSD_2_2_BASE OPENBSD_2_3_BASE
# 1.13 04-Sep-1997 mickey

use err()/warn()/__progname where appropriate, consolidate string, some -Wall


# 1.12 24-Aug-1997 deraadt

give shutdown daemon own session; dima@tejblum.dnttm.rssi.ru


# 1.11 25-Jul-1997 mickey

do -d for reboot and halt


# 1.10 25-Jul-1997 mickey

-Wall


# 1.9 23-Jun-1997 downsj

Slightly cleaner. (Change nosync to an int, like the rest.)


# 1.8 22-Jun-1997 downsj

Support halt -p.


Revision tags: OPENBSD_2_1_BASE
# 1.7 15-Jan-1997 millert

getopt(3) returns -1 when out of args, not EOF, whee!


# 1.6 22-Dec-1996 deraadt

MAXHOSTNAMELEN, not +1


Revision tags: OPENBSD_2_0_BASE
# 1.5 20-Sep-1996 deraadt

call execle with the correct params; netbsd pr#2737, augustss@cs.chalmers.se


# 1.4 02-Sep-1996 deraadt

whoops


# 1.3 02-Sep-1996 deraadt

bad environ init; from brian@saturn.net


# 1.2 23-Jun-1996 deraadt

update rcsid


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision