forked from bobrippling/utop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
76 lines (59 loc) · 1.39 KB
/
main.c
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
66
67
68
69
70
71
72
73
74
75
76
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <signal.h>
#include "proc.h"
#include "gui.h"
#include "util.h"
#define MS_TO_US(n) ((n) * 1000)
uid_t global_uid = 0;
int global_force = 0;
int global_debug = 0;
int max_unam_len, max_gnam_len;
static struct myproc **proclist;
void extra_init()
{
global_uid = getuid();
/* for layout - username length */
max_unam_len = longest_passwd_line("/etc/passwd");
max_gnam_len = longest_passwd_line("/etc/group");
}
void signal_handler(int sig) {
if (sig == SIGABRT || sig == SIGTERM) {
gui_term();
fprintf(stderr, "\nCaught signal %d. Bye!\n", sig);
proc_cleanup(proclist);
exit(EXIT_FAILURE);
}
}
int main(int argc, char **argv)
{
struct sigaction action;
int i;
action.sa_handler = signal_handler;
sigaction(SIGABRT, &action, NULL);
sigaction(SIGTERM, &action, NULL);
for(i = 1; i < argc; i++){
if(!strcmp(argv[i], "-f")){
global_force = 1;
}else if(!strcmp(argv[i], "-d")){
global_debug = 1;
}else{
fprintf(stderr,
"Usage: %s [-f] [-d]\n"
" -f: Don't prompt for lsof and strace\n"
" -d: Debug mode\n"
, *argv);
return 1;
}
}
extra_init();
gui_init();
proclist = proc_init();
gui_run(proclist);
gui_term();
proc_cleanup(proclist);
return 0;
}