moved sigaction to std::signal

pull/14/head
Tom Early 6 years ago
parent e40153a53e
commit f6643f30eb

@ -1,7 +1,7 @@
/* /*
* Copyright (C) 2010, 2011 by Scott Lawson KI4LKF * Copyright (C) 2010,2011 by Scott Lawson KI4LKF
* *
* Copyright (C) 2015 by Thomas A. Early N7TAE * Copyright (C) 2015,2020 by Thomas A. Early N7TAE
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -31,7 +31,6 @@
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <signal.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
@ -43,6 +42,7 @@
#include <exception> #include <exception>
#include <thread> #include <thread>
#include <string> #include <string>
#include <csignal>
#include "DVAPDongle.h" #include "DVAPDongle.h"
#include "QnetTypeDefs.h" #include "QnetTypeDefs.h"
@ -150,11 +150,9 @@ static void calcPFCS(unsigned char *packet, unsigned char *pfcs)
return; return;
} }
static void sig_catch(int signum) static void sig_catch(int)
{ {
if ((signum == SIGTERM) || (signum == SIGINT) || (signum == SIGHUP)) keep_running = false;
keep_running = false;
exit(0);
} }
/* process configuration file */ /* process configuration file */
@ -524,23 +522,11 @@ static void RptrAckThread(SDVAP_ACK_ARG *parg)
sprintf(RADIO_ID, "%20.2f", ber); sprintf(RADIO_ID, "%20.2f", ber);
memcpy(RADIO_ID, "BER%", 4); memcpy(RADIO_ID, "BER%", 4);
struct sigaction act;
unsigned char silence[12] = { 0x9e,0x8d,0x32,0x88,0x26,0x1a,0x3f,0x61,0xe8,0x70,0x4f,0x93 }; unsigned char silence[12] = { 0x9e,0x8d,0x32,0x88,0x26,0x1a,0x3f,0x61,0xe8,0x70,0x4f,0x93 };
act.sa_handler = sig_catch; std::signal(SIGTERM, sig_catch);
sigemptyset(&act.sa_mask); std::signal(SIGINT, sig_catch);
if (sigaction(SIGTERM, &act, 0) != 0) { std::signal(SIGHUP, sig_catch);
printf("sigaction-TERM failed, error=%d\n", errno);
return;
}
if (sigaction(SIGHUP, &act, 0) != 0) {
printf("sigaction-HUP failed, error=%d\n", errno);
return;
}
if (sigaction(SIGINT, &act, 0) != 0) {
printf("sigaction-INT failed, error=%d\n", errno);
return;
}
sleep(TIMING_PLAY_WAIT); sleep(TIMING_PLAY_WAIT);
@ -642,7 +628,6 @@ static void ReadDVAPThread()
SDSVT dsvt; SDSVT dsvt;
SDVAP_REGISTER dr; SDVAP_REGISTER dr;
CTimer last_RF_time; CTimer last_RF_time;
struct sigaction act;
bool dvap_busy = false; bool dvap_busy = false;
// bool ptt = false; // bool ptt = false;
bool the_end = true; bool the_end = true;
@ -656,23 +641,9 @@ static void ReadDVAPThread()
int num_dv_frames = 0; int num_dv_frames = 0;
int num_bit_errors = 0; int num_bit_errors = 0;
act.sa_handler = sig_catch; std::signal(SIGTERM, sig_catch);
sigemptyset(&act.sa_mask); std::signal(SIGINT, sig_catch);
if (sigaction(SIGTERM, &act, 0) != 0) { std::signal(SIGHUP, sig_catch);
printf("sigaction-TERM failed, error=%d\n", errno);
keep_running = false;
return;
}
if (sigaction(SIGHUP, &act, 0) != 0) {
printf("sigaction-HUP failed, error=%d\n", errno);
keep_running = false;
return;
}
if (sigaction(SIGINT, &act, 0) != 0) {
printf("sigaction-INT failed, error=%d\n", errno);
keep_running = false;
return;
}
while (keep_running) { while (keep_running) {
@ -891,7 +862,6 @@ static void ReadDVAPThread()
int main(int argc, const char **argv) int main(int argc, const char **argv)
{ {
struct sigaction act;
int rc = -1; int rc = -1;
short cnt = 0; short cnt = 0;
@ -964,20 +934,9 @@ int main(int argc, const char **argv)
CTimer ackpoint; CTimer ackpoint;
act.sa_handler = sig_catch; std::signal(SIGTERM, sig_catch);
sigemptyset(&act.sa_mask); std::signal(SIGINT, sig_catch);
if (sigaction(SIGTERM, &act, 0) != 0) { std::signal(SIGHUP, sig_catch);
printf("sigaction-TERM failed, error=%d\n", errno);
return 1;
}
if (sigaction(SIGHUP, &act, 0) != 0) {
printf("sigaction-HUP failed, error=%d\n", errno);
return 1;
}
if (sigaction(SIGINT, &act, 0) != 0) {
printf("sigaction-INT failed, error=%d\n", errno);
return 1;
}
/* open dvp */ /* open dvp */
if (!dongle.Initialize(MODULE_SERIAL_NUMBER.c_str(), MODULE_FREQUENCY, MODULE_OFFSET, MODULE_POWER, MODULE_SQUELCH)) if (!dongle.Initialize(MODULE_SERIAL_NUMBER.c_str(), MODULE_FREQUENCY, MODULE_OFFSET, MODULE_POWER, MODULE_SQUELCH))

@ -24,7 +24,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
#include <unistd.h> #include <unistd.h>
#include <signal.h>
#include <errno.h> #include <errno.h>
#include <math.h> #include <math.h>
#include <sys/time.h> #include <sys/time.h>
@ -43,6 +42,7 @@
#include <string> #include <string>
#include <thread> #include <thread>
#include <chrono> #include <chrono>
#include <csignal>
#include "IRCDDB.h" #include "IRCDDB.h"
#include "IRCutils.h" #include "IRCutils.h"
@ -54,7 +54,7 @@
#define CFG_DIR "/usr/local/etc" #define CFG_DIR "/usr/local/etc"
#endif #endif
const std::string GW_VERSION("QnetGateway-9.3"); const std::string GW_VERSION("QnetGateway-9.4");
extern void dstar_dv_init(); extern void dstar_dv_init();
extern int dstar_dv_decode(const unsigned char *d, int data[3]); extern int dstar_dv_decode(const unsigned char *d, int data[3]);
@ -62,13 +62,9 @@ extern int dstar_dv_decode(const unsigned char *d, int data[3]);
static std::atomic<bool> keep_running(true); static std::atomic<bool> keep_running(true);
/* signal catching function */ /* signal catching function */
static void sigCatch(int signum) static void sigCatch(int)
{ {
/* do NOT do any serious work here */ keep_running = false;
if ((signum == SIGTERM) || (signum == SIGINT))
keep_running = false;
return;
} }
int CQnetGateway::FindIndex(const int i) const int CQnetGateway::FindIndex(const int i) const
@ -388,30 +384,14 @@ int CQnetGateway::open_port(const SPORTIP *pip, int family)
/* receive data from the irc server and save it */ /* receive data from the irc server and save it */
void CQnetGateway::GetIRCDataThread(const int i) void CQnetGateway::GetIRCDataThread(const int i)
{ {
std::string user, rptr, gateway, ipaddr; std::string user, rptr, gateway, ipaddr, utime;
DSTAR_PROTOCOL proto; DSTAR_PROTOCOL proto;
IRCDDB_RESPONSE_TYPE type; IRCDDB_RESPONSE_TYPE type;
struct sigaction act;
short last_status = 0; short last_status = 0;
act.sa_handler = sigCatch; std::signal(SIGTERM, sigCatch);
sigemptyset(&act.sa_mask); std::signal(SIGINT, sigCatch);
act.sa_flags = SA_RESTART; std::signal(SIGHUP, sigCatch);
if (sigaction(SIGTERM, &act, 0) != 0) {
printf("GetIRCDataThread: sigaction-TERM failed, error=%d\n", errno);
keep_running = false;
return;
}
if (sigaction(SIGINT, &act, 0) != 0) {
printf("GetIRCDataThread: sigaction-INT failed, error=%d\n", errno);
keep_running = false;
return;
}
if (sigaction(SIGPIPE, &act, 0) != 0) {
printf("GetIRCDataThread: sigaction-PIPE failed, error=%d\n", errno);
keep_running = false;
return;
}
short threshold = 0; short threshold = 0;
bool not_announced[3]; bool not_announced[3];
@ -477,9 +457,9 @@ void CQnetGateway::GetIRCDataThread(const int i)
while (((type = ii[i]->getMessageType()) != IDRT_NONE) && keep_running) { while (((type = ii[i]->getMessageType()) != IDRT_NONE) && keep_running) {
switch (type) { switch (type) {
case IDRT_USER: case IDRT_USER:
ii[i]->receiveUser(user, rptr, gateway, ipaddr); ii[i]->receiveUser(user, rptr, gateway, ipaddr, utime);
if (LOG_IRC) if (LOG_IRC)
printf("U%d u[%s] r[%s] g[%s] a[%s]\n", i, user.c_str(), rptr.c_str(), gateway.c_str(), ipaddr.c_str()); printf("U%d u[%s] r[%s] g[%s] a[%s] t[%s]\n", i, user.c_str(), rptr.c_str(), gateway.c_str(), ipaddr.c_str(), utime.c_str());
if (!user.empty()) { if (!user.empty()) {
if (!rptr.empty() && !gateway.empty() && !ipaddr.empty()) { if (!rptr.empty() && !gateway.empty() && !ipaddr.empty()) {
@ -2081,8 +2061,6 @@ void CQnetGateway::APRSBeaconThread()
char rcv_buf[512]; char rcv_buf[512];
time_t tnow = 0; time_t tnow = 0;
struct sigaction act;
/* /*
Every 20 seconds, the remote APRS host sends a KEEPALIVE packet-comment Every 20 seconds, the remote APRS host sends a KEEPALIVE packet-comment
on the TCP/APRS port. on the TCP/APRS port.
@ -2094,21 +2072,9 @@ void CQnetGateway::APRSBeaconThread()
*/ */
short THRESHOLD_COUNTDOWN = 15; short THRESHOLD_COUNTDOWN = 15;
act.sa_handler = sigCatch; std::signal(SIGTERM, sigCatch);
sigemptyset(&act.sa_mask); std::signal(SIGINT, sigCatch);
act.sa_flags = SA_RESTART; std::signal(SIGHUP, sigCatch);
if (sigaction(SIGTERM, &act, 0) != 0) {
printf("APRSBeaconThread: sigaction-TERM failed, error=%d\n", errno);
return;
}
if (sigaction(SIGINT, &act, 0) != 0) {
printf("APRSBeaconThread: sigaction-INT failed, error=%d\n", errno);
return;
}
if (sigaction(SIGPIPE, &act, 0) != 0) {
printf("APRSBeaconThread: sigaction-PIPE failed, error=%d\n", errno);
return;
}
time_t last_keepalive_time; time_t last_keepalive_time;
time(&last_keepalive_time); time(&last_keepalive_time);
@ -2266,22 +2232,9 @@ void CQnetGateway::PlayFileThread(SECHO &edata)
const unsigned char sdsilence[3] = { 0x16U, 0x29U, 0xF5U }; const unsigned char sdsilence[3] = { 0x16U, 0x29U, 0xF5U };
const unsigned char sdsync[3] = { 0x55U, 0x2DU, 0x16U }; const unsigned char sdsync[3] = { 0x55U, 0x2DU, 0x16U };
struct sigaction act; std::signal(SIGTERM, sigCatch);
act.sa_handler = sigCatch; std::signal(SIGINT, sigCatch);
sigemptyset(&act.sa_mask); std::signal(SIGHUP, sigCatch);
act.sa_flags = SA_RESTART;
if (sigaction(SIGTERM, &act, 0) != 0) {
printf("sigaction-TERM failed, error=%d\n", errno);
return;
}
if (sigaction(SIGINT, &act, 0) != 0) {
printf("sigaction-INT failed, error=%d\n", errno);
return;
}
if (sigaction(SIGPIPE, &act, 0) != 0) {
printf("sigaction-PIPE failed, error=%d\n", errno);
return;
}
printf("File to playback:[%s]\n", edata.file); printf("File to playback:[%s]\n", edata.file);
@ -2421,7 +2374,6 @@ void CQnetGateway::qrgs_and_maps()
bool CQnetGateway::Init(char *cfgfile) bool CQnetGateway::Init(char *cfgfile)
{ {
short int i; short int i;
struct sigaction act;
setvbuf(stdout, (char *)NULL, _IOLBF, 0); setvbuf(stdout, (char *)NULL, _IOLBF, 0);
@ -2434,21 +2386,9 @@ bool CQnetGateway::Init(char *cfgfile)
return true; return true;
} }
act.sa_handler = sigCatch; std::signal(SIGTERM, sigCatch);
sigemptyset(&act.sa_mask); std::signal(SIGINT, sigCatch);
act.sa_flags = SA_RESTART; std::signal(SIGHUP, sigCatch);
if (sigaction(SIGTERM, &act, 0) != 0) {
printf("sigaction-TERM failed, error=%d\n", errno);
return true;
}
if (sigaction(SIGINT, &act, 0) != 0) {
printf("sigaction-INT failed, error=%d\n", errno);
return true;
}
if (sigaction(SIGPIPE, &act, 0) != 0) {
printf("sigaction-PIPE failed, error=%d\n", errno);
return true;
}
for (i = 0; i < 3; i++) for (i = 0; i < 3; i++)
memset(&band_txt[0], 0, sizeof(SBANDTXT)); memset(&band_txt[0], 0, sizeof(SBANDTXT));

@ -2,7 +2,7 @@
* Copyright (C) 2018-2019 by Thomas A. Early N7TAE * Copyright (C) 2018-2019 by Thomas A. Early N7TAE
* *
* CQnetITAP::GetITAPData() is based on some code that is... * CQnetITAP::GetITAPData() is based on some code that is...
* Copyright (C) 2011-2015,2018 by Jonathan Naylor G4KLX * Copyright (C) 2011-2015,2018,2020 by Jonathan Naylor G4KLX
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -45,7 +45,7 @@
#include "QnetConfigure.h" #include "QnetConfigure.h"
#include "Timer.h" #include "Timer.h"
#define ITAP_VERSION "QnetITAP-2.1.5" #define ITAP_VERSION "QnetITAP-2.1.6"
std::atomic<bool> CQnetITAP::keep_running(true); std::atomic<bool> CQnetITAP::keep_running(true);
@ -63,21 +63,9 @@ bool CQnetITAP::Initialize(const char *cfgfile)
if (ReadConfig(cfgfile)) if (ReadConfig(cfgfile))
return true; return true;
struct sigaction act; std::signal(SIGTERM, CQnetITAP::SignalCatch);
act.sa_handler = &CQnetITAP::SignalCatch; std::signal(SIGHUP, CQnetITAP::SignalCatch);
sigemptyset(&act.sa_mask); std::signal(SIGINT, CQnetITAP::SignalCatch);
if (sigaction(SIGTERM, &act, 0) != 0) {
printf("sigaction-TERM failed, error=%d\n", errno);
return true;
}
if (sigaction(SIGHUP, &act, 0) != 0) {
printf("sigaction-HUP failed, error=%d\n", errno);
return true;
}
if (sigaction(SIGINT, &act, 0) != 0) {
printf("sigaction-INT failed, error=%d\n", errno);
return true;
}
Modem2Gate.SetUp(modem2gate.c_str()); Modem2Gate.SetUp(modem2gate.c_str());
if (Gate2Modem.Open(gate2modem.c_str())) if (Gate2Modem.Open(gate2modem.c_str()))
@ -631,7 +619,6 @@ void CQnetITAP::SignalCatch(const int signum)
{ {
if ((signum == SIGTERM) || (signum == SIGINT) || (signum == SIGHUP)) if ((signum == SIGTERM) || (signum == SIGINT) || (signum == SIGHUP))
keep_running = false; keep_running = false;
exit(0);
} }
void CQnetITAP::calcPFCS(const unsigned char *packet, unsigned char *pfcs) void CQnetITAP::calcPFCS(const unsigned char *packet, unsigned char *pfcs)

@ -106,12 +106,12 @@ public:
void Run(const char *cfgfile); void Run(const char *cfgfile);
// data // data
static std::atomic<bool> keep_running;
private: private:
int assigned_module; int assigned_module;
// functions // functions
bool Initialize(const char *cfgfile); bool Initialize(const char *cfgfile);
static std::atomic<bool> keep_running;
static void SignalCatch(const int signum); static void SignalCatch(const int signum);
bool ProcessGateway(const int len, const unsigned char *raw); bool ProcessGateway(const int len, const unsigned char *raw);
bool ProcessITAP(const unsigned char *raw); bool ProcessITAP(const unsigned char *raw);

@ -1,7 +1,7 @@
/* /*
* Copyright (C) 2010 by Scott Lawson KI4LKF * Copyright (C) 2010 by Scott Lawson KI4LKF
* Copyright (C) 2015,2018,2019 by Thomas A. Early N7TAE * Copyright (C) 2015,2008-2020 by Thomas A. Early N7TAE
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -28,7 +28,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
#include <unistd.h> #include <unistd.h>
#include <signal.h>
#include <errno.h> #include <errno.h>
#include <regex.h> #include <regex.h>
@ -47,12 +46,13 @@
#include <utility> #include <utility>
#include <thread> #include <thread>
#include <chrono> #include <chrono>
#include <csignal>
#include "DPlusAuthenticator.h" #include "DPlusAuthenticator.h"
#include "QnetConfigure.h" #include "QnetConfigure.h"
#include "QnetLink.h" #include "QnetLink.h"
#define LINK_VERSION "QnetLink-7.2" #define LINK_VERSION "QnetLink-7.3"
#ifndef BIN_DIR #ifndef BIN_DIR
#define BIN_DIR "/usr/local/bin" #define BIN_DIR "/usr/local/bin"
#endif #endif
@ -182,19 +182,10 @@ void CQnetLink::RptrAckThread(char *arg)
char RADIO_ID[21]; char RADIO_ID[21];
memcpy(RADIO_ID, arg + 1, 21); memcpy(RADIO_ID, arg + 1, 21);
unsigned char silence[12] = { 0x9E, 0x8D, 0x32, 0x88, 0x26, 0x1A, 0x3F, 0x61, 0xE8, 0x16, 0x29, 0xf5 }; unsigned char silence[12] = { 0x9E, 0x8D, 0x32, 0x88, 0x26, 0x1A, 0x3F, 0x61, 0xE8, 0x16, 0x29, 0xf5 };
struct sigaction act;
act.sa_handler = sigCatch; std::signal(SIGTERM, sigCatch);
sigemptyset(&act.sa_mask); std::signal(SIGINT, sigCatch);
act.sa_flags = SA_RESTART; std::signal(SIGHUP, sigCatch);
if (sigaction(SIGTERM, &act, 0) != 0) {
printf("sigaction-TERM failed, error=%d\n", errno);
return;
}
if (sigaction(SIGINT, &act, 0) != 0) {
printf("sigaction-INT failed, error=%d\n", errno);
return;
}
short int streamid_raw = Random.NewStreamID(); short int streamid_raw = Random.NewStreamID();
@ -926,12 +917,9 @@ void CQnetLink::g2link(const char from_mod, const char *call, const char to_mod)
} }
/* signal catching function */ /* signal catching function */
void CQnetLink::sigCatch(int signum) void CQnetLink::sigCatch(int)
{ {
/* do NOT do any serious work here */ keep_running = false;
if ((signum == SIGTERM) || (signum == SIGINT))
keep_running = false;
return;
} }
void CQnetLink::Process() void CQnetLink::Process()
@ -3242,18 +3230,9 @@ void CQnetLink::PlayAudioNotifyThread(char *msg)
void CQnetLink::AudioNotifyThread(SECHO &edata) void CQnetLink::AudioNotifyThread(SECHO &edata)
{ {
struct sigaction act; std::signal(SIGTERM, sigCatch);
act.sa_handler = sigCatch; std::signal(SIGINT, sigCatch);
sigemptyset(&act.sa_mask); std::signal(SIGHUP, sigCatch);
act.sa_flags = SA_RESTART;
if (sigaction(SIGTERM, &act, 0) != 0) {
fprintf(stderr, "sigaction-TERM failed, error=%d\n", errno);
return;
}
if (sigaction(SIGINT, &act, 0) != 0) {
fprintf(stderr, "sigaction-INT failed, error=%d\n", errno);
return;
}
char mod = edata.header.hdr.rpt1[7]; char mod = edata.header.hdr.rpt1[7];
@ -3409,8 +3388,6 @@ void CQnetLink::AudioNotifyThread(SECHO &edata)
bool CQnetLink::Init(const char *cfgfile) bool CQnetLink::Init(const char *cfgfile)
{ {
struct sigaction act;
tzset(); tzset();
setvbuf(stdout, (char *)NULL, _IOLBF, 0); setvbuf(stdout, (char *)NULL, _IOLBF, 0);
@ -3421,17 +3398,9 @@ bool CQnetLink::Init(const char *cfgfile)
return true; return true;
} }
act.sa_handler = sigCatch; std::signal(SIGTERM, sigCatch);
sigemptyset(&act.sa_mask); std::signal(SIGINT, sigCatch);
act.sa_flags = SA_RESTART; std::signal(SIGHUP, sigCatch);
if (sigaction(SIGTERM, &act, 0) != 0) {
printf("sigaction-TERM failed, error=%d\n", errno);
return true;
}
if (sigaction(SIGINT, &act, 0) != 0) {
printf("sigaction-INT failed, error=%d\n", errno);
return true;
}
for (int i=0; i<3; i++) { for (int i=0; i<3; i++) {
notify_msg[i][0] = '\0'; notify_msg[i][0] = '\0';

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2019 by Thomas A. Early N7TAE * Copyright (C) 2019,2020 by Thomas A. Early N7TAE
* *
* CQnetModem is inspired by {Modem,MMDVMHost}.cpp in * CQnetModem is inspired by {Modem,MMDVMHost}.cpp in
* Jonathan Naylor's brilliant MMDVMHost that is... * Jonathan Naylor's brilliant MMDVMHost that is...
@ -44,7 +44,7 @@
#include "QnetModem.h" #include "QnetModem.h"
#include "QnetConfigure.h" #include "QnetConfigure.h"
#define MODEM_VERSION "QnetModem-0.1.3" #define MODEM_VERSION "QnetModem-1.0.0"
#define MAX_RESPONSES 30 #define MAX_RESPONSES 30
std::atomic<bool> CQnetModem::keep_running(true); std::atomic<bool> CQnetModem::keep_running(true);
@ -218,21 +218,9 @@ bool CQnetModem::Initialize(const char *cfgfile)
if (ReadConfig(cfgfile)) if (ReadConfig(cfgfile))
return true; return true;
struct sigaction act; std::signal(SIGTERM, SignalCatch);
act.sa_handler = &CQnetModem::SignalCatch; std::signal(SIGINT, SignalCatch);
sigemptyset(&act.sa_mask); std::signal(SIGHUP, SignalCatch);
if (sigaction(SIGTERM, &act, 0) != 0) {
printf("sigaction-TERM failed, error=%d\n", errno);
return true;
}
if (sigaction(SIGHUP, &act, 0) != 0) {
printf("sigaction-HUP failed, error=%d\n", errno);
return true;
}
if (sigaction(SIGINT, &act, 0) != 0) {
printf("sigaction-INT failed, error=%d\n", errno);
return true;
}
Modem2Gate.SetUp(modem2gate.c_str()); Modem2Gate.SetUp(modem2gate.c_str());
if (Gate2Modem.Open(gate2modem.c_str())) if (Gate2Modem.Open(gate2modem.c_str()))
@ -850,11 +838,9 @@ bool CQnetModem::ReadConfig(const char *cfgFile)
return false; return false;
} }
void CQnetModem::SignalCatch(const int signum) void CQnetModem::SignalCatch(const int)
{ {
if ((signum == SIGTERM) || (signum == SIGINT) || (signum == SIGHUP)) keep_running = false;
keep_running = false;
exit(0);
} }
int main(int argc, const char **argv) int main(int argc, const char **argv)

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2018 by Thomas A. Early N7TAE * Copyright (C) 2018,2020 by Thomas A. Early N7TAE
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -36,7 +36,7 @@
#include "QnetTypeDefs.h" #include "QnetTypeDefs.h"
#include "QnetConfigure.h" #include "QnetConfigure.h"
#define RELAY_VERSION "QnetRelay-1.1.0" #define RELAY_VERSION "QnetRelay-1.1.1"
std::atomic<bool> CQnetRelay::keep_running(true); std::atomic<bool> CQnetRelay::keep_running(true);
@ -56,21 +56,9 @@ bool CQnetRelay::Initialize(const char *cfgfile)
if (ReadConfig(cfgfile)) if (ReadConfig(cfgfile))
return true; return true;
struct sigaction act; std::signal(SIGTERM, SignalCatch);
act.sa_handler = &CQnetRelay::SignalCatch; std::signal(SIGINT, SignalCatch);
sigemptyset(&act.sa_mask); std::signal(SIGHUP, SignalCatch);
if (sigaction(SIGTERM, &act, 0) != 0) {
printf("sigaction-TERM failed, error=%d\n", errno);
return true;
}
if (sigaction(SIGHUP, &act, 0) != 0) {
printf("sigaction-HUP failed, error=%d\n", errno);
return true;
}
if (sigaction(SIGINT, &act, 0) != 0) {
printf("sigaction-INT failed, error=%d\n", errno);
return true;
}
return false; return false;
} }
@ -403,11 +391,9 @@ bool CQnetRelay::ReadConfig(const char *cfgFile)
return false; return false;
} }
void CQnetRelay::SignalCatch(const int signum) void CQnetRelay::SignalCatch(const int)
{ {
if ((signum == SIGTERM) || (signum == SIGINT) || (signum == SIGHUP)) keep_running = false;
keep_running = false;
exit(0);
} }
int main(int argc, const char **argv) int main(int argc, const char **argv)

Loading…
Cancel
Save

Powered by TurnKey Linux.