mirror of
https://github.com/norohind/hans.git
synced 2025-04-18 15:27:36 +03:00
Clean exit on signal
This commit is contained in:
parent
363a9d765e
commit
736099944d
17
src/main.cpp
17
src/main.cpp
@ -35,6 +35,16 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
static void sig_term_handler(int)
|
||||||
|
{
|
||||||
|
syslog(LOG_INFO, "SIGTERM received");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void sig_int_handler(int)
|
||||||
|
{
|
||||||
|
syslog(LOG_INFO, "SIGINT received");
|
||||||
|
}
|
||||||
|
|
||||||
void usage()
|
void usage()
|
||||||
{
|
{
|
||||||
printf(
|
printf(
|
||||||
@ -176,10 +186,12 @@ int main(int argc, char *argv[])
|
|||||||
if (!verbose)
|
if (!verbose)
|
||||||
setlogmask(LOG_UPTO(LOG_INFO));
|
setlogmask(LOG_UPTO(LOG_INFO));
|
||||||
|
|
||||||
|
signal(SIGTERM, sig_term_handler);
|
||||||
|
signal(SIGINT, sig_int_handler);
|
||||||
|
|
||||||
|
Worker *worker;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Worker *worker;
|
|
||||||
|
|
||||||
if (isServer)
|
if (isServer)
|
||||||
{
|
{
|
||||||
worker = new Server(mtu, device, password, network, answerPing, uid, gid, 5000);
|
worker = new Server(mtu, device, password, network, answerPing, uid, gid, 5000);
|
||||||
@ -213,6 +225,7 @@ int main(int argc, char *argv[])
|
|||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR, "%s", e.errorMessage());
|
syslog(LOG_ERR, "%s", e.errorMessage());
|
||||||
|
delete worker;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user