* Copyright (c) 1980,1986 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
"@(#) Copyright (c) 1980,1986 Regents of the University of California.\n\
static char sccsid
[] = "@(#)halt.c 5.4 (Berkeley) 5/26/86";
char *ttyn
= (char *)ttyname(2);
struct passwd
*pw
, *getpwuid();
openlog("halt", 0, LOG_AUTH
);
if (!strcmp(*argv
, "-n"))
else if (!strcmp(*argv
, "-y"))
else if (!strcmp(*argv
, "-q"))
else if (!strcmp(*argv
, "-l"))
fprintf(stderr
, "usage: halt [ -n ]\n");
if (ttyn
&& *(ttyn
+strlen("/dev/tty")) == 'd') {
fprintf(stderr
, "halt: dangerous on a dialup; use ``halt -y'' if you are really sure\n");
if (user
== (char *)0 && (pw
= getpwuid(getuid())))
syslog(LOG_CRIT
, "halted by %s", user
);
signal(SIGHUP
, SIG_IGN
); /* for network connections */
if (kill(1, SIGTSTP
) == -1) {
fprintf(stderr
, "reboot: can't idle init\n");
(void) kill(-1, SIGTERM
); /* one chance to catch it */
if (!qflag
) for (i
= 1; ; i
++) {
if (kill(-1, SIGKILL
) == -1) {
"CAUTION: some process(es) wouldn't die\n");
if (!qflag
&& (howto
& RB_NOSYNC
) == 0) {
/* RRRIIINNNGGG RRRIIINNNGGG */
signal(SIGALRM
, dingdong
);
#define SCPYN(a, b) strncpy(a, b, sizeof(a))
char wtmpf
[] = "/usr/adm/wtmp";
register f
= open(wtmpf
, 1);
SCPYN(wtmp
.ut_line
, "~");
SCPYN(wtmp
.ut_name
, "shutdown");
write(f
, (char *)&wtmp
, sizeof(wtmp
));