-
Notifications
You must be signed in to change notification settings - Fork 251
/
procmon.cpp
83 lines (64 loc) · 2.16 KB
/
procmon.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
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
77
78
79
80
81
82
83
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#include <iostream>
#include <version.h>
#include "configuration/procmon_configuration.h"
#include "display/screen.h"
#include "display/headless.h"
#include "logging/easylogging++.h"
INITIALIZE_EASYLOGGINGPP
int main(int argc, char *argv[])
{
// Make sure user is running elevated
if(geteuid() != 0)
{
std::cout << "Procmon requires elevated credentials. Please run with sudo.\n";
exit(-1);
}
/*
* Turn off cursor for shell. Note this has to be done before EBPF spins up.
* This is due to a conflict that leads to the consumer thread dieing when the system
* function is executed.
*/
system("setterm -cursor off");
// Configure logging
el::Loggers::addFlag(el::LoggingFlag::HierarchicalLogging);
el::Loggers::addFlag(el::LoggingFlag::AutoSpacing);
el::Loggers::addFlag(el::LoggingFlag::ColoredTerminalOutput);
el::Loggers::addFlag(el::LoggingFlag::HierarchicalLogging);
el::Loggers::setLoggingLevel(el::Level::Error);
// Program initialization: create global config from args
auto config = std::make_shared<ProcmonConfiguration>(argc, argv);
LOG(INFO) << "Tracing " << config->events.size() << " system calls";
// Configure logging
el::Configurations defaultConf;
defaultConf.setToDefault();
if(config->GetHeadlessMode())
{
if(config->GetTraceFilePath().compare("") != 0)
{
std::cerr << "Cannot open trace file in headless mode";
CLIUtils::DisplayUsage(true);
}
Headless headlessDisplay;
// init headless interface
headlessDisplay.initialize(config);
// run in headless mode
headlessDisplay.run();
// cleanup run
headlessDisplay.shutdown();
}
else
{
Screen display;
// initialize curses UI
display.initScreen(config);
// run display
display.run();
// shutdown curses UI
display.shutdownScreen();
}
// re-enable cursor before exiting Procmon
system("setterm -cursor on");
return 0;
}