Correctly exit OpenBTS even if console is not started yet.
This commit is contained in:
parent
7d9fa86569
commit
fc61ebaf53
|
@ -238,15 +238,38 @@ static int startTransceiver()
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void serverCleanup()
|
||||||
|
{
|
||||||
|
if (sgTransceiverPid) {
|
||||||
|
kill(sgTransceiverPid, SIGTERM);
|
||||||
|
if (sgTransceiverPidFileFd >= 0) {
|
||||||
|
close(sgTransceiverPidFileFd);
|
||||||
|
}
|
||||||
|
if (sgTransceiverPidFile.size() > 0) {
|
||||||
|
if (unlink(sgTransceiverPidFile.data()) == 0) {
|
||||||
|
LOG(INFO) << "Deleted lock file " << sgTransceiverPidFile;
|
||||||
|
} else {
|
||||||
|
LOG(INFO) << "Error while deleting lock file " << sgTransceiverPidFile
|
||||||
|
<< " code=" << errno << ": " << strerror(errno);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void exitCLI()
|
static void exitCLI()
|
||||||
{
|
{
|
||||||
if (sgCLIServerSock != NULL) {
|
if (sgCLIServerSock == NULL) {
|
||||||
|
serverCleanup();
|
||||||
|
_exit(EXIT_SUCCESS);
|
||||||
|
} else {
|
||||||
// Closing server sock
|
// Closing server sock
|
||||||
sgCLIServerSock->close();
|
sgCLIServerSock->close();
|
||||||
sgCLIServerSock = NULL;
|
sgCLIServerSock = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Closing server standard input to shutdown local CLI
|
// Closing server standard input to shutdown local CLI
|
||||||
|
// Following functions are not async-signal-safe, but I don't have
|
||||||
|
// better idea how to do this.
|
||||||
cin.setstate(ios::eofbit);
|
cin.setstate(ios::eofbit);
|
||||||
// cin.putback('\n');
|
// cin.putback('\n');
|
||||||
fclose(stdin);
|
fclose(stdin);
|
||||||
|
@ -653,20 +676,7 @@ int main(int argc, char *argv[])
|
||||||
exitBTS(0, cout);
|
exitBTS(0, cout);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sgTransceiverPid) {
|
serverCleanup();
|
||||||
kill(sgTransceiverPid, SIGTERM);
|
|
||||||
if (sgTransceiverPidFileFd >= 0) {
|
|
||||||
close(sgTransceiverPidFileFd);
|
|
||||||
}
|
|
||||||
if (sgTransceiverPidFile.size() > 0) {
|
|
||||||
if (unlink(sgTransceiverPidFile.data()) == 0) {
|
|
||||||
LOG(INFO) << "Deleted lock file " << sgTransceiverPidFile;
|
|
||||||
} else {
|
|
||||||
LOG(INFO) << "Error while deleting lock file " << sgTransceiverPidFile
|
|
||||||
<< " code=" << errno << ": " << strerror(errno);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue