Fixed all semaphore instances not being cleaned up properly.
This commit is contained in:
parent
dda9ed54b4
commit
f4b296164e
14 changed files with 77 additions and 63 deletions
|
@ -81,7 +81,10 @@ static const char * DBG_LVL_LIST[] = {"NONE", "FAIL", "ERROR", "WARN", "INFO", "
|
|||
#define SHM_STATISTICS "MstSTAT"
|
||||
#define SHM_USERS "MstUSER%s" //%s stream name
|
||||
#define SHM_TRIGGER "MstTRIG%s" //%s trigger name
|
||||
#define SEM_LIVE "MstLIVE%s" //%s stream name
|
||||
#define SEM_LIVE "/MstLIVE%s" //%s stream name
|
||||
#define SEM_INPUT "/MstInpt%s" //%s stream name
|
||||
#define SEM_CONF "/MstConfLock"
|
||||
#define SHM_CONF "MstConf"
|
||||
#define NAME_BUFFER_SIZE 200 //char buffer size for snprintf'ing shm filenames
|
||||
|
||||
#define SHM_STREAM_ENCRYPT "MstCRYP%s" //%s stream name
|
||||
|
|
|
@ -132,7 +132,7 @@ namespace IPC {
|
|||
while (!(*this) && timer++ < 10) {
|
||||
#if defined(__CYGWIN__) || defined(_WIN32)
|
||||
std::string semaName = "Global\\";
|
||||
semaName += name;
|
||||
semaName += (name+1);
|
||||
if (oflag & O_CREAT) {
|
||||
if (oflag & O_EXCL) {
|
||||
//attempt opening, if succes, close handle and return false;
|
||||
|
|
|
@ -86,8 +86,8 @@ JSON::Value Util::getStreamConfig(std::string streamname){
|
|||
FAIL_MSG("Stream opening denied: %s is longer than 100 characters (%lu).", streamname.c_str(), streamname.size());
|
||||
return result;
|
||||
}
|
||||
IPC::sharedPage mistConfOut("!mistConfig", DEFAULT_CONF_PAGE_SIZE);
|
||||
IPC::semaphore configLock("!mistConfLock", O_CREAT | O_RDWR, ACCESSPERMS, 1);
|
||||
IPC::sharedPage mistConfOut(SHM_CONF, DEFAULT_CONF_PAGE_SIZE);
|
||||
IPC::semaphore configLock(SEM_CONF, O_CREAT | O_RDWR, ACCESSPERMS, 1);
|
||||
configLock.wait();
|
||||
DTSC::Scan config = DTSC::Scan(mistConfOut.mapped, mistConfOut.len);
|
||||
|
||||
|
@ -107,7 +107,10 @@ JSON::Value Util::getStreamConfig(std::string streamname){
|
|||
/// Checks if the given streamname has an active input serving it. Returns true if this is the case.
|
||||
/// Assumes the streamname has already been through sanitizeName()!
|
||||
bool Util::streamAlive(std::string & streamname){
|
||||
IPC::semaphore playerLock(std::string("/lock_" + streamname).c_str(), O_CREAT | O_RDWR, ACCESSPERMS, 1);
|
||||
char semName[NAME_BUFFER_SIZE];
|
||||
snprintf(semName, NAME_BUFFER_SIZE, SEM_INPUT, streamname.c_str());
|
||||
IPC::semaphore playerLock(semName, O_RDWR, ACCESSPERMS, 1);
|
||||
if (!playerLock){return false;}
|
||||
if (!playerLock.tryWait()) {
|
||||
playerLock.close();
|
||||
return true;
|
||||
|
@ -151,8 +154,8 @@ bool Util::startInput(std::string streamname, std::string filename, bool forkFir
|
|||
}
|
||||
|
||||
//Attempt to load up configuration and find this stream
|
||||
IPC::sharedPage mistConfOut("!mistConfig", DEFAULT_CONF_PAGE_SIZE);
|
||||
IPC::semaphore configLock("!mistConfLock", O_CREAT | O_RDWR, ACCESSPERMS, 1);
|
||||
IPC::sharedPage mistConfOut(SHM_CONF, DEFAULT_CONF_PAGE_SIZE);
|
||||
IPC::semaphore configLock(SEM_CONF, O_CREAT | O_RDWR, ACCESSPERMS, 1);
|
||||
//Lock the config to prevent race conditions and corruption issues while reading
|
||||
configLock.wait();
|
||||
DTSC::Scan config = DTSC::Scan(mistConfOut.mapped, mistConfOut.len);
|
||||
|
@ -304,8 +307,8 @@ int Util::startRecording(std::string streamname) {
|
|||
}
|
||||
|
||||
// Attempt to load up configuration and find this stream
|
||||
IPC::sharedPage mistConfOut("!mistConfig", DEFAULT_CONF_PAGE_SIZE);
|
||||
IPC::semaphore configLock("!mistConfLock", O_CREAT | O_RDWR, ACCESSPERMS, 1);
|
||||
IPC::sharedPage mistConfOut(SHM_CONF, DEFAULT_CONF_PAGE_SIZE);
|
||||
IPC::semaphore configLock(SEM_CONF, O_CREAT | O_RDWR, ACCESSPERMS, 1);
|
||||
|
||||
//Lock the config to prevent race conditions and corruption issues while reading
|
||||
configLock.wait();
|
||||
|
|
|
@ -10,10 +10,7 @@ namespace TS {
|
|||
Stream::Stream(bool _threaded){
|
||||
threaded = _threaded;
|
||||
if (threaded){
|
||||
globalSem.open("MstTSInputLock", O_CREAT | O_EXCL | O_RDWR, ACCESSPERMS, 1);
|
||||
if (!globalSem) {
|
||||
globalSem.open("MstTSInputLock", O_CREAT | O_RDWR, ACCESSPERMS, 1);
|
||||
}
|
||||
globalSem.open("MstTSInputLock", O_CREAT | O_RDWR, ACCESSPERMS, 1);
|
||||
if (!globalSem) {
|
||||
FAIL_MSG("Creating semaphore failed: %s", strerror(errno));
|
||||
threaded = false;
|
||||
|
@ -23,6 +20,12 @@ namespace TS {
|
|||
}
|
||||
}
|
||||
|
||||
Stream::~Stream(){
|
||||
if (threaded){
|
||||
globalSem.unlink();
|
||||
}
|
||||
}
|
||||
|
||||
void Stream::parse(char * newPack, unsigned long long bytePos) {
|
||||
Packet newPacket;
|
||||
newPacket.FromPointer(newPack);
|
||||
|
|
|
@ -21,6 +21,7 @@ namespace TS {
|
|||
class Stream{
|
||||
public:
|
||||
Stream(bool _threaded = false);
|
||||
~Stream();
|
||||
void add(char * newPack, unsigned long long bytePos = 0);
|
||||
void add(Packet & newPack, unsigned long long bytePos = 0);
|
||||
void parse(Packet & newPack, unsigned long long bytePos);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue