Robustify accesses to server config
This commit is contained in:
parent
d36faa340a
commit
ac92e09262
14 changed files with 238 additions and 192 deletions
|
@ -126,6 +126,7 @@ static inline void show_stackframe(){}
|
|||
|
||||
#define SHM_STREAM_INDEX "MstSTRM%s" //%s stream name
|
||||
#define SHM_STREAM_STATE "MstSTATE%s" //%s stream name
|
||||
#define SHM_STREAM_CONF "MstSCnf%s" //%s stream name
|
||||
#define STRMSTAT_OFF 0
|
||||
#define STRMSTAT_INIT 1
|
||||
#define STRMSTAT_BOOT 2
|
||||
|
@ -139,11 +140,10 @@ static inline void show_stackframe(){}
|
|||
#define SHM_TRACK_DATA "MstDATA%s@%lu_%lu" //%s stream name, %lu track ID, %lu page #
|
||||
#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_INPUT "/MstInpt%s" //%s stream name
|
||||
#define SEM_CONF "/MstConfLock"
|
||||
#define SHM_CONF "MstConf"
|
||||
#define SHM_CAPA "MstCapa"
|
||||
#define SHM_PROTO "MstProt"
|
||||
#define SHM_STATE_LOGS "MstStateLogs"
|
||||
#define SHM_STATE_ACCS "MstStateAccs"
|
||||
#define SHM_STATE_STREAMS "MstStateStreams"
|
||||
|
|
|
@ -79,20 +79,17 @@ JSON::Value Util::getStreamConfig(const 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(SHM_CONF, DEFAULT_CONF_PAGE_SIZE, false, false);
|
||||
IPC::semaphore configLock(SEM_CONF, O_CREAT | O_RDWR, ACCESSPERMS, 1);
|
||||
configLock.wait();
|
||||
DTSC::Scan config = DTSC::Scan(mistConfOut.mapped, mistConfOut.len);
|
||||
std::string smp = streamname.substr(0, streamname.find_first_of("+ "));
|
||||
//check if smp (everything before + or space) exists
|
||||
DTSC::Scan stream_cfg = config.getMember("streams").getMember(smp);
|
||||
|
||||
char tmpBuf[NAME_BUFFER_SIZE];
|
||||
snprintf(tmpBuf, NAME_BUFFER_SIZE, SHM_STREAM_CONF, smp.c_str());
|
||||
Util::DTSCShmReader rStrmConf(tmpBuf);
|
||||
DTSC::Scan stream_cfg = rStrmConf.getScan();
|
||||
if (!stream_cfg){
|
||||
DEBUG_MSG(DLVL_MEDIUM, "Stream %s not configured", streamname.c_str());
|
||||
}else{
|
||||
result = stream_cfg.asJSON();
|
||||
WARN_MSG("Could not get stream '%s' config!", smp.c_str());
|
||||
return result;
|
||||
}
|
||||
configLock.post();//unlock the config semaphore
|
||||
return result;
|
||||
return stream_cfg.asJSON();
|
||||
}
|
||||
|
||||
DTSC::Meta Util::getStreamMeta(const std::string & streamname){
|
||||
|
@ -281,22 +278,17 @@ JSON::Value Util::getInputBySource(const std::string &filename, bool isProvider)
|
|||
JSON::Value ret;
|
||||
|
||||
//Attempt to load up configuration and find this stream
|
||||
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);
|
||||
//Abort if no config available
|
||||
if (!config){
|
||||
FAIL_MSG("Configuration not available, aborting! Is MistController running?");
|
||||
configLock.post();//unlock the config semaphore
|
||||
Util::DTSCShmReader rCapa(SHM_CAPA);
|
||||
DTSC::Scan inputs = rCapa.getMember("inputs");
|
||||
//Abort if not available
|
||||
if (!inputs){
|
||||
FAIL_MSG("Capabilities not available, aborting! Is MistController running?");
|
||||
return false;
|
||||
}
|
||||
|
||||
//check in curConf for capabilities-inputs-<naam>-priority/source_match
|
||||
//check in curConf for <naam>-priority/source_match
|
||||
bool selected = false;
|
||||
long long int curPrio = -1;
|
||||
DTSC::Scan inputs = config.getMember("capabilities").getMember("inputs");
|
||||
DTSC::Scan input;
|
||||
unsigned int input_size = inputs.getSize();
|
||||
bool noProviderNoPick = false;
|
||||
|
@ -350,7 +342,6 @@ JSON::Value Util::getInputBySource(const std::string &filename, bool isProvider)
|
|||
}else{
|
||||
ret = input.asJSON();
|
||||
}
|
||||
configLock.post();//unlock the config semaphore
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -362,3 +353,18 @@ uint8_t Util::getStreamStatus(const std::string & streamname){
|
|||
return streamStatus.mapped[0];
|
||||
}
|
||||
|
||||
Util::DTSCShmReader::DTSCShmReader(const std::string &pageName){
|
||||
rPage.init(pageName, 0);
|
||||
if (rPage){
|
||||
rAcc = Util::RelAccX(rPage.mapped);
|
||||
}
|
||||
}
|
||||
|
||||
DTSC::Scan Util::DTSCShmReader::getMember(const std::string &indice){
|
||||
return DTSC::Scan(rAcc.getPointer("dtsc_data"), rAcc.getSize("dtsc_data")).getMember(indice.c_str());
|
||||
}
|
||||
|
||||
DTSC::Scan Util::DTSCShmReader::getScan(){
|
||||
return DTSC::Scan(rAcc.getPointer("dtsc_data"), rAcc.getSize("dtsc_data"));
|
||||
}
|
||||
|
||||
|
|
13
lib/stream.h
13
lib/stream.h
|
@ -6,6 +6,8 @@
|
|||
#include "socket.h"
|
||||
#include "json.h"
|
||||
#include "dtsc.h"
|
||||
#include "shared_memory.h"
|
||||
#include "util.h"
|
||||
|
||||
namespace Util {
|
||||
std::string getTmpFolder();
|
||||
|
@ -16,5 +18,16 @@ namespace Util {
|
|||
JSON::Value getInputBySource(const std::string & filename, bool isProvider = false);
|
||||
DTSC::Meta getStreamMeta(const std::string & streamname);
|
||||
uint8_t getStreamStatus(const std::string & streamname);
|
||||
|
||||
class DTSCShmReader{
|
||||
public:
|
||||
DTSCShmReader(const std::string &pageName);
|
||||
DTSC::Scan getMember(const std::string &indice);
|
||||
DTSC::Scan getScan();
|
||||
private:
|
||||
IPC::sharedPage rPage;
|
||||
Util::RelAccX rAcc;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "defines.h"
|
||||
#include "timing.h"
|
||||
#include "procs.h"
|
||||
#include "dtsc.h"
|
||||
#include <errno.h> // errno, ENOENT, EEXIST
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
@ -564,6 +565,13 @@ namespace Util{
|
|||
r << std::endl;
|
||||
break;
|
||||
}
|
||||
case RAX_DTSC:{
|
||||
char * ptr = getPointer(it->first, i);
|
||||
size_t sz = getSize(it->first, i);
|
||||
r << std::endl;
|
||||
r << DTSC::Scan(ptr, sz).toPrettyString(indent+6) << std::endl;
|
||||
break;
|
||||
}
|
||||
default: r << "[UNIMPLEMENTED]" << std::endl; break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,6 +74,7 @@ namespace Util{
|
|||
#define RAX_RAW 0x40
|
||||
#define RAX_256RAW 0x44
|
||||
#define RAX_512RAW 0x45
|
||||
#define RAX_DTSC 0x50
|
||||
|
||||
/// Reliable Access class.
|
||||
/// Provides reliable access to memory data structures, using dynamic static offsets and a status
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue