File: shutdown.c

package info (click to toggle)
wmshutdown 0.2-9
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 176 kB
  • sloc: ansic: 408; makefile: 64
file content (48 lines) | stat: -rw-r--r-- 876 bytes parent folder | download | duplicates (2)
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
/*
 * shutdown.c
 *
 * (C) 2001 Rafael V. Aroca <rafael@linuxqos.cjb.net> 
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char **argv) {

	if (argv[1] != NULL) {

		if (strcmp((char*)argv[1], "-r") == 0) {
			int ch;
			FILE *output;

			printf("Rebooting...\n");
			output = popen("/sbin/shutdown now -r", "r");
			ch = fgetc(output);
			while (ch != EOF) {
				printf("%c", ch);
				ch = fgetc(output);
			}
			pclose(output);
		} 
		
		if (strcmp(argv[1], "-h") == 0) {
			int ch;
			FILE *output;

			printf("Halting...\n");
			output = popen("/sbin/shutdown now -h", "r");
			ch = fgetc(output);
			while (ch != EOF) {
				printf("%c", ch);
				ch = fgetc(output);
			}
			pclose(output);
		} 

		if (!strcmp(argv[1], "-h") == 0 && !strcmp(argv[1], "-r") == 0) 
			printf("Nothing done.\n");
	} else printf("Nothing done.\n"); 
}