From b6f606bf87499be0d005595331cd3f3da80417aa Mon Sep 17 00:00:00 2001 From: Thulinma Date: Wed, 21 Sep 2016 12:37:24 +0200 Subject: [PATCH 1/2] Fixed horrible input parameter bug --- lib/stream.cpp | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/lib/stream.cpp b/lib/stream.cpp index 42722a37..3434d26a 100644 --- a/lib/stream.cpp +++ b/lib/stream.cpp @@ -173,34 +173,36 @@ bool Util::startInput(std::string streamname, std::string filename, bool forkFir DTSC::Scan input; unsigned int input_size = inputs.getSize(); for (unsigned int i = 0; i < input_size; ++i){ - input = inputs.getIndice(i); + DTSC::Scan tmp_input = inputs.getIndice(i); //if match voor current stream && priority is hoger dan wat we al hebben - if (input.getMember("source_match") && curPrio < input.getMember("priority").asInt()){ - if (input.getMember("source_match").getSize()){ - for(unsigned int j = 0; j < input.getMember("source_match").getSize(); ++j){ - std::string source = input.getMember("source_match").getIndice(j).asString(); + if (tmp_input.getMember("source_match") && curPrio < tmp_input.getMember("priority").asInt()){ + if (tmp_input.getMember("source_match").getSize()){ + for(unsigned int j = 0; j < tmp_input.getMember("source_match").getSize(); ++j){ + std::string source = tmp_input.getMember("source_match").getIndice(j).asString(); std::string front = source.substr(0,source.find('*')); std::string back = source.substr(source.find('*')+1); - MEDIUM_MSG("Checking input %s: %s (%s)", inputs.getIndiceName(i).c_str(), input.getMember("name").asString().c_str(), source.c_str()); + MEDIUM_MSG("Checking input %s: %s (%s)", inputs.getIndiceName(i).c_str(), tmp_input.getMember("name").asString().c_str(), source.c_str()); if (filename.substr(0,front.size()) == front && filename.substr(filename.size()-back.size()) == back){ - player_bin = Util::getMyPath() + "MistIn" + input.getMember("name").asString(); - curPrio = input.getMember("priority").asInt(); + player_bin = Util::getMyPath() + "MistIn" + tmp_input.getMember("name").asString(); + curPrio = tmp_input.getMember("priority").asInt(); selected = true; + input = tmp_input; } } }else{ - std::string source = input.getMember("source_match").asString(); - std::string front = source.substr(0,source.find('*')); - std::string back = source.substr(source.find('*')+1); - DEBUG_MSG(DLVL_MEDIUM, "Checking input %s: %s (%s)", inputs.getIndiceName(i).c_str(), input.getMember("name").asString().c_str(), source.c_str()); - - if (filename.substr(0,front.size()) == front && filename.substr(filename.size()-back.size()) == back){ - player_bin = Util::getMyPath() + "MistIn" + input.getMember("name").asString(); - curPrio = input.getMember("priority").asInt(); - selected = true; - } + std::string source = tmp_input.getMember("source_match").asString(); + std::string front = source.substr(0,source.find('*')); + std::string back = source.substr(source.find('*')+1); + MEDIUM_MSG("Checking input %s: %s (%s)", inputs.getIndiceName(i).c_str(), tmp_input.getMember("name").asString().c_str(), source.c_str()); + + if (filename.substr(0,front.size()) == front && filename.substr(filename.size()-back.size()) == back){ + player_bin = Util::getMyPath() + "MistIn" + tmp_input.getMember("name").asString(); + curPrio = tmp_input.getMember("priority").asInt(); + selected = true; + input = tmp_input; + } } } @@ -212,7 +214,7 @@ bool Util::startInput(std::string streamname, std::string filename, bool forkFir return false; } - //copy the neccessary arguments to separate storage so we can unlock the config semaphore safely + //copy the necessary arguments to separate storage so we can unlock the config semaphore safely std::map str_args; //check required parameters DTSC::Scan required = input.getMember("required"); @@ -231,7 +233,7 @@ bool Util::startInput(std::string streamname, std::string filename, bool forkFir unsigned int opt_size = optional.getSize(); for (unsigned int i = 0; i < opt_size; ++i){ std::string opt = optional.getIndiceName(i); - DEBUG_MSG(DLVL_VERYHIGH, "Checking optional %u: %s", i, opt.c_str()); + VERYHIGH_MSG("Checking optional %u: %s", i, opt.c_str()); if (stream_cfg.getMember(opt)){ str_args[optional.getIndice(i).getMember("option").asString()] = stream_cfg.getMember(opt).asString(); } @@ -240,7 +242,7 @@ bool Util::startInput(std::string streamname, std::string filename, bool forkFir //finally, unlock the config semaphore configLock.post(); - DEBUG_MSG(DLVL_MEDIUM, "Starting %s -s %s %s", player_bin.c_str(), streamname.c_str(), filename.c_str()); + INFO_MSG("Starting %s -s %s %s", player_bin.c_str(), streamname.c_str(), filename.c_str()); char * argv[30] = {(char *)player_bin.c_str(), (char *)"-s", (char *)streamname.c_str(), (char *)filename.c_str()}; int argNum = 3; std::string debugLvl; @@ -252,6 +254,7 @@ bool Util::startInput(std::string streamname, std::string filename, bool forkFir for (std::map::iterator it = str_args.begin(); it != str_args.end(); ++it){ argv[++argNum] = (char *)it->first.c_str(); argv[++argNum] = (char *)it->second.c_str(); + INFO_MSG(" Option %s = %s", it->first.c_str(), it->second.c_str()); } argv[++argNum] = (char *)0; From 9e9e5685b499be5660fa465d55175c737eef1dcf Mon Sep 17 00:00:00 2001 From: Thulinma Date: Wed, 21 Sep 2016 12:30:54 +0200 Subject: [PATCH 2/2] Fixed race condition bug in tinythread --- lib/tinythread.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/tinythread.cpp b/lib/tinythread.cpp index fed3b63f..5d17de4a 100644 --- a/lib/tinythread.cpp +++ b/lib/tinythread.cpp @@ -169,8 +169,10 @@ namespace tthread { // The thread is no longer executing if (ti->mThread) { lock_guard guard(ti->mThread->mDataMutex); - ti->mThread->mNotAThread = true; - ti->mThread->ti_copy = 0; + if (ti->mThread){ + ti->mThread->mNotAThread = true; + ti->mThread->ti_copy = 0; + } } // The thread is responsible for freeing the startup information