-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProxyApp.cpp
More file actions
79 lines (59 loc) · 1.66 KB
/
Copy pathProxyApp.cpp
File metadata and controls
79 lines (59 loc) · 1.66 KB
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
#include "ProxyApp.h"
#include <libutils/Logger.h>
#include <libutils/FileUtils.h>
#include <functional>
#include <syslog.h>
#include <unistd.h>
using namespace Utils;
using namespace std::placeholders;
ProxyApp::ProxyApp(): DaemonApplication("opi-authproxy","/run","root","root")
{
}
void ProxyApp::SigTerm(int signo)
{
logg << Logger::Debug << "Got signal "<<signo<<lend;
this->proxy->ShutDown();
}
void ProxyApp::SigHup(int signo)
{
(void) signo;
// TODO: Perhaps reload any config
}
void ProxyApp::Startup()
{
// Divert logger to syslog
openlog( "opi-authproxy", LOG_PERROR, LOG_DAEMON);
logg.SetOutputter( [](const string& msg){ syslog(LOG_INFO, "%s",msg.c_str());});
logg.SetLogName("");
logg << Logger::Info << "Starting" << lend;
Utils::SigHandler::Instance().AddHandler(SIGTERM, std::bind(&ProxyApp::SigTerm, this, _1) );
Utils::SigHandler::Instance().AddHandler(SIGINT, std::bind(&ProxyApp::SigTerm, this, _1) );
Utils::SigHandler::Instance().AddHandler(SIGHUP, std::bind(&ProxyApp::SigHup, this, _1) );
this->options.AddOption( Option('D', "debug", Option::ArgNone,"0","Debug logging") );
try
{
// Remove possible old socket
unlink(SOCKPATH);
if( ! File::DirExists( File::GetPath( SOCKPATH ) ) )
{
File::MkPath( File::GetPath( SOCKPATH ), 0755 );
}
}
catch( std::runtime_error& err)
{
logg << Logger::Notice << "Failed to setup directory: " << err.what() << lend;
}
proxy = AuthProxyPtr(new AuthProxy(SOCKPATH) );
}
void ProxyApp::Main()
{
if( this->options["debug"] == "1" )
{
logg << Logger::Info << "Increase logging to debug level "<<lend;
logg.SetLevel(Logger::Debug);
}
proxy->Run();
}
void ProxyApp::ShutDown()
{
}