-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathmain.cpp
42 lines (29 loc) · 1.12 KB
/
main.cpp
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
#include "inject/injector.h"
#include <zero/log.h>
#include <zero/cmdline.h>
int main(int argc, char ** argv) {
INIT_CONSOLE_LOG(zero::INFO);
zero::Cmdline cmdline;
cmdline.add<int>("pid", "process id");
cmdline.addOptional("daemon", 'd', "daemon mode");
cmdline.addOptional("deaf", '\0', "signal won't be delivered immediately");
cmdline.addOptional<std::vector<std::string>>("environs", 'e', "environment variables");
cmdline.footer("inject argv");
cmdline.parse(argc, argv);
int pid = cmdline.get<int>("pid");
bool daemon = cmdline.getOptional<bool>("daemon");
bool deaf = cmdline.getOptional<bool>("deaf");
auto arguments = cmdline.rest();
auto environs = cmdline.getOptional<std::vector<std::string>>("environs");
if (arguments.empty()) {
LOG_ERROR("inject empty argv");
return -1;
}
LOG_INFO("exec %s", zero::strings::join(arguments, " ").c_str());
Injector injector;
if (!injector.open(pid, deaf)) {
LOG_ERROR("process injector open failed");
return -1;
}
return injector.inject(arguments, environs, daemon);
}