Remove Transceiver PID file on OpenBTS exit.
This commit is contained in:
parent
7b3c0d3090
commit
a0f3b96688
|
@ -109,8 +109,10 @@ TransceiverManager gTRX(1, gConfig.getStr("TRX.IP"), gConfig.getNum("TRX.Port"))
|
||||||
/// Pointer to the server socket if we run remote CLI.
|
/// Pointer to the server socket if we run remote CLI.
|
||||||
static ConnectionServerSocket *sgCLIServerSock = NULL;
|
static ConnectionServerSocket *sgCLIServerSock = NULL;
|
||||||
|
|
||||||
/// We store Transceiver PID if we started it.
|
/// We store Transceiver PID if we start it.
|
||||||
static pid_t sgTransceiverPid = 0;
|
static pid_t sgTransceiverPid = 0;
|
||||||
|
static int sgTransceiverPidFileFd = -1;
|
||||||
|
static std::string sgTransceiverPidFile;
|
||||||
|
|
||||||
/** Function to shutdown the process when something wrong happens. */
|
/** Function to shutdown the process when something wrong happens. */
|
||||||
void shutdownOpenbts()
|
void shutdownOpenbts()
|
||||||
|
@ -189,15 +191,15 @@ static int startTransceiver()
|
||||||
if (gConfig.defines("TRX.Path")) {
|
if (gConfig.defines("TRX.Path")) {
|
||||||
|
|
||||||
// Open and lock PID file, taking care of old transceiver instance.
|
// Open and lock PID file, taking care of old transceiver instance.
|
||||||
std::string lockfile = gConfig.getStr("TRX.WritePID");
|
sgTransceiverPidFile = gConfig.getStr("TRX.WritePID");
|
||||||
int lfp = openPidFile(lockfile);
|
sgTransceiverPidFileFd = openPidFile(sgTransceiverPidFile);
|
||||||
if (lfp < 0) return EXIT_SUCCESS;
|
if (sgTransceiverPidFileFd < 0) return EXIT_SUCCESS;
|
||||||
int pid;
|
int pid;
|
||||||
if (lockPidFile(lockfile, lfp, false) != EXIT_SUCCESS) {
|
if (lockPidFile(sgTransceiverPidFile, sgTransceiverPidFileFd, false) != EXIT_SUCCESS) {
|
||||||
// Another OpenBTS instance is running and blocking PID file.
|
// Another OpenBTS instance is running and blocking PID file.
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
if (readPidFile(lockfile, lfp, pid) == EXIT_SUCCESS) {
|
if (readPidFile(sgTransceiverPidFile, sgTransceiverPidFileFd, pid) == EXIT_SUCCESS) {
|
||||||
// There is no harm in this. Transceiver's owner is not
|
// There is no harm in this. Transceiver's owner is not
|
||||||
// running and could safely kill it.
|
// running and could safely kill it.
|
||||||
kill(pid, SIGTERM);
|
kill(pid, SIGTERM);
|
||||||
|
@ -217,7 +219,7 @@ static int startTransceiver()
|
||||||
_exit(0);
|
_exit(0);
|
||||||
}
|
}
|
||||||
// Now we can finally write transceiver PID to the file.
|
// Now we can finally write transceiver PID to the file.
|
||||||
if (writePidFile(lockfile, lfp, sgTransceiverPid) != EXIT_SUCCESS) return EXIT_FAILURE;
|
if (writePidFile(sgTransceiverPidFile, sgTransceiverPidFileFd, sgTransceiverPid) != EXIT_SUCCESS) return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -573,7 +575,20 @@ int main(int argc, char *argv[])
|
||||||
exitBTS(0, cout);
|
exitBTS(0, cout);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sgTransceiverPid) kill(sgTransceiverPid, SIGKILL);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue