-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.cpp
More file actions
48 lines (37 loc) · 884 Bytes
/
Main.cpp
File metadata and controls
48 lines (37 loc) · 884 Bytes
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
#include <getopt.h>
#include <unistd.h>
#if defined SUPPORT_CAP
#include <cap-ng.h>
#endif
#include "IpLink.hpp"
#include "format_si.hpp"
/*** Program ***/
int main(int argc, char *argv[])
{
IpLink::Config config;
config.parse_args(argc, argv, std::cout);
if (config.shown_help) {
return 0;
}
if (config.daemon) {
pid_t p = fork();
if (p == -1) {
throw std::runtime_error(std::string("fork() failed: ") + strerror(errno));
} else if (p > 0) {
usleep(100000);
int status;
if (waitpid(p, &status, WNOHANG) == p && (WIFEXITED(status) || WIFSIGNALED(status))) {
return status;
}
return 0;
}
}
#if defined SUPPORT_CAP
if (getuid() != 0 && !capng_have_capability(CAPNG_EFFECTIVE, CAP_NET_ADMIN)) {
throw std::runtime_error("Requires root or CAP_NET_ADMIN privilege");
}
#endif
IpLink::IpLink iplink(config);
iplink.run();
return 0;
}