-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
66 lines (57 loc) · 1.11 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
#include <signal.h>
#include <stdlib.h>
#include "opts.h"
#include "usage.h"
#include "server.h"
#include "client.h"
#include "pidfile.h"
#include "list_servers.h"
int main(int argc, char **argv)
{
(void)argc;
parse_args(argv);
if (g_help) {
if (g_help > 1)
long_usage(stdout);
else
short_usage(stdout);
exit(0);
}
if (g_getpid) {
int pid = read_pidfile();
if (pid > 0) {
printf("%d\n", pid);
exit(0);
}
exit(EXIT_FAILURE);
}
if (g_list) {
if (list_servers() < 0)
exit(EXIT_FAILURE);
exit(0);
}
if (g_kill) {
int pid = read_pidfile();
if (pid > 0) {
kill(pid, SIGTERM);
exit(0);
}
fprintf(stderr, "error: no server '%s' running\n", g_name);
exit(EXIT_FAILURE);
}
if (g_cancel) {
int pid = read_pidfile();
if (pid > 0) {
/* The server will cancel the running command
* on SIGUSR1. */
kill(pid, SIGUSR1);
exit(0);
}
fprintf(stderr, "error: no server '%s' running\n", g_name);
exit(EXIT_FAILURE);
}
if (g_command)
run_client();
else
run_server();
}