4 |
#include <fcntl.h> |
#include <fcntl.h> |
5 |
#include <stdlib.h> |
#include <stdlib.h> |
6 |
#include <cstring> |
#include <cstring> |
7 |
|
#include <cstdio> |
8 |
|
|
9 |
#include <sys/types.h> |
#include <sys/types.h> |
10 |
#include <pwd.h> |
#include <pwd.h> |
13 |
|
|
14 |
#include "ConfigFile.h" |
#include "ConfigFile.h" |
15 |
#include "daemon.h" |
#include "daemon.h" |
16 |
#include "common.h" |
#include "Common.h" |
17 |
|
#include "Logger.h" |
18 |
|
|
19 |
|
|
20 |
|
|
26 |
switch (sig) |
switch (sig) |
27 |
{ |
{ |
28 |
case SIGHUP: |
case SIGHUP: |
29 |
Common::instance()->logMessage("hangup signal catched"); |
Logger::logMessage("Reload config"); |
30 |
|
Common::instance()->reloadConfig = true; |
31 |
|
|
32 |
break; |
break; |
33 |
|
|
34 |
case SIGTERM: |
case SIGTERM: |
35 |
Common::instance()->logMessage("terminate signal catched...exiting"); |
Logger::logMessage("terminate signal catched...exiting"); |
36 |
Common::instance()->mainContinue = false; |
Common::instance()->mainContinue = false; |
37 |
break; |
break; |
38 |
default: |
default: |
39 |
std::stringstream ss; |
std::stringstream ss; |
40 |
ss << "Received unknown signal: " << sig; |
ss << "Received unknown signal: " << sig; |
41 |
Common::instance()->logMessage(ss.str()); |
Logger::logMessage(ss.str()); |
42 |
break; |
break; |
43 |
} |
} |
44 |
} |
} |
47 |
{ |
{ |
48 |
Common* cmn = Common::instance(); |
Common* cmn = Common::instance(); |
49 |
|
|
50 |
std::string userstr = cmn->GetConfigfile()->GetValue("smsdaemon","user"); |
std::string userstr = cmn->GetConfigfile()->GetValue("smsdaemon","user",""); |
51 |
std::string groupstr = cmn->GetConfigfile()->GetValue("smsdaemon","group"); |
std::string groupstr = cmn->GetConfigfile()->GetValue("smsdaemon","group",""); |
52 |
|
|
53 |
passwd* pass = getpwnam(userstr.c_str()); |
passwd* pass = getpwnam(userstr.c_str()); |
54 |
if (pass != 0) |
if (pass != 0) |
57 |
} |
} |
58 |
else |
else |
59 |
{ |
{ |
60 |
cmn->logMessage( string("could not lookup userid: ") + userstr ); |
Logger::logMessage( string("could not lookup userid: ") + userstr ); |
61 |
exit(1); |
exit(1); |
62 |
} |
} |
63 |
|
|
69 |
} |
} |
70 |
else |
else |
71 |
{ |
{ |
72 |
cmn->logMessage( string("could not lookup groupid: ") + groupstr ); |
Logger::logMessage( string("could not lookup groupid: ") + groupstr ); |
73 |
exit(1); |
exit(1); |
74 |
} |
} |
75 |
} |
} |
77 |
|
|
78 |
void daemonCleanup() |
void daemonCleanup() |
79 |
{ |
{ |
80 |
unlink( Common::instance()->pidfile.c_str() ); |
Common* cmn = Common::instance(); |
81 |
|
Logger::logMessage("Cleaning up daemon"); |
82 |
|
|
83 |
|
seteuid(0); |
84 |
|
setegid(0); |
85 |
|
unlink( cmn->pidfile.c_str() ); |
86 |
|
|
87 |
} |
} |
88 |
|
|
89 |
void daemonize() |
void daemonize() |