summaryrefslogtreecommitdiff
path: root/package/sash/src/shutdown.c
blob: cc5ee87637eff3949c0e06987d3adba4be72177e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* shutdown.c:
 *
 * Copyright (C) 1998  Kenneth Albanowski <kjahds@kjahds.com>,
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 */

#include "sash.h"

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <sys/types.h>

#include <sys/stat.h>
#include <dirent.h>
#include <pwd.h>
#include <grp.h>
#include <time.h>
#include <signal.h>
#include <unistd.h>
#include <sys/reboot.h>

int
main(argc, argv)
	int argc;
	char	**argv;
{
	char *progname = argv[0];

	if (argc > 2 && strcmp(argv[1], "-d") == 0) {
		sleep(atoi(argv[2]));
		argc -= 2;
	}
	if ((argc != 3) || (strcmp(argv[1], "-h") && strcmp(argv[1], "-r")) || strcmp(argv[2], "now")) {
		printf("Usage: %s [-d delay] -h|-r now\n", progname);
		exit(0);
	}
	
	kill(1, SIGTSTP);
	sync();
	signal(SIGTERM,SIG_IGN);
	setpgrp();
	kill(-1, SIGTERM);
	sleep(1);
	kill(-1, SIGHUP); /* Force PPPD's down, too */
	sleep(1);
	kill(-1, SIGKILL);
	sync();
	sleep(1);
	
	if (strcmp(argv[1], "-h")==0) {
		reboot(0xCDEF0123);
	} else {
		reboot(0x01234567);
	}
	
	exit(0); /* Shrug */
}