Skip to content

Commit

Permalink
Support for handling SIGTERM and doing an orderly shutdown.
Browse files Browse the repository at this point in the history
  • Loading branch information
PeteDavidson committed May 2, 2016
1 parent e2c49fc commit bab160b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
25 changes: 22 additions & 3 deletions main_process.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class T38Modem : public PProcess
void Main();

protected:
MyManager *manager;
PBoolean Initialise();
};

Expand All @@ -125,6 +126,15 @@ T38Modem::T38Modem()
{
}

PSemaphore TimeToTerminate(0,1);

void SignalHandler(int signo)
{
cout << "T38Modem received signal " << signo << ".\n";
if (signo == SIGTERM)
TimeToTerminate.Signal();
}

void T38Modem::Main()
{
cout << GetName()
Expand All @@ -135,13 +145,22 @@ void T38Modem::Main()
<< " (" << GetOSVersion() << '-' << GetOSHardware() << ")\n"
<< endl;

cout << GetName() << " pid: " << getpid() << " ppid: " << getppid() << endl;

if (signal(SIGTERM, SignalHandler) == SIG_ERR)
cout << GetName() << " can't catch SIGTERM\n";

if (!Initialise()) {
PThread::Sleep(100); // workaround for race condition
return;
}

for (;;)
PThread::Sleep(5000);
TimeToTerminate.Wait();

cout << GetName() << " deleting manager..." << endl;
delete manager;
cout << GetName() << " ending, manager deleted." << endl;
remove("/var/tmp/t38modem_pid");
}

PBoolean T38Modem::Initialise()
Expand Down Expand Up @@ -255,7 +274,7 @@ PBoolean T38Modem::Initialise()
#endif

#ifdef USE_OPAL
MyManager *manager = new MyManager();
manager = new MyManager();

if (!manager->Initialise(args))
return FALSE;
Expand Down
2 changes: 1 addition & 1 deletion opal/sipep.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ void MySIPEndPoint::OnRegistrationStatus(const RegistrationStatus & status)
PTRACE(2, "MySIPEndPoint::OnRegistrationStatus() file " << outFile << " written successfully");
}
else {
PTRACE(2, "MySIPEndPoint::OnRegistrationStatus() open of " << outFile << " failed");
PTRACE(2, "MySIPEndPoint::OnRegistrationStatus() open of " << outFile << " failed: " << strerror(errno));
}
}
else {
Expand Down
2 changes: 1 addition & 1 deletion version.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#define MAJOR_VERSION 3
#define MINOR_VERSION 14
#define BUILD_TYPE ReleaseCode
#define BUILD_NUMBER 0
#define BUILD_NUMBER 1

#endif // _T38M_VERSION_H

0 comments on commit bab160b

Please sign in to comment.