diff --git a/lib/defines.h b/lib/defines.h index 6e88b639..29c2353f 100644 --- a/lib/defines.h +++ b/lib/defines.h @@ -12,7 +12,8 @@ #define DLVL_DONTEVEN 10 // All messages enabled, even pointless ones. #if DEBUG > 0 #include -#define DEBUG_MSG(lvl, msg, ...) if (DEBUG >= lvl){fprintf(stderr, "[%s:%d] " msg "\n", __FILE__, __LINE__, ##__VA_ARGS__);} +#include +#define DEBUG_MSG(lvl, msg, ...) if (DEBUG >= lvl){fprintf(stderr, "[%d][%s:%d] " msg "\n", getpid(), __FILE__, __LINE__, ##__VA_ARGS__);} #else #define DEBUG_MSG(lvl, msg, ...) // Debugging disabled. #endif diff --git a/lib/shared_memory.cpp b/lib/shared_memory.cpp index 831c3961..e694e5dd 100644 --- a/lib/shared_memory.cpp +++ b/lib/shared_memory.cpp @@ -93,16 +93,16 @@ namespace IPC { } } if (handle == -1) { - perror(std::string("shm_open for page " + name + " failed").c_str()); + DEBUG_MSG(DLVL_FAIL, "shm_open for page %s failed: %s", name.c_str(), strerror(errno)); return; } if (master){ if (ftruncate(handle, 0) < 0) { - perror(std::string("ftruncate to zero for page " + name + " failed").c_str()); + DEBUG_MSG(DLVL_FAIL, "truncate to zero for page %s failed: %s", name.c_str(), strerror(errno)); return; } if (ftruncate(handle, len) < 0) { - perror(std::string("ftruncate to len for page " + name + " failed").c_str()); + DEBUG_MSG(DLVL_FAIL, "truncate to %lld for page %s failed: %s", len, name.c_str(), strerror(errno)); return; } }else{ @@ -391,7 +391,7 @@ namespace IPC { sharedPage tmp(std::string(baseName + (char)(myPages.size() + (int)'A')), (4096 << myPages.size()), true); myPages.insert(tmp); tmp.master = false; - DEBUG_MSG(DLVL_WARN, "Added a new page: %s", tmp.name.c_str()); + DEBUG_MSG(DLVL_MEDIUM, "Added a new page: %s", tmp.name.c_str()); } void sharedServer::deletePage() { @@ -452,7 +452,7 @@ namespace IPC { //increase the count if needed if (id >= amount){ amount = id+1; - DEBUG_MSG(DLVL_DEVEL, "Shared memory %s is now at count %u", baseName.c_str(), amount); + DEBUG_MSG(DLVL_VERYHIGH, "Shared memory %s is now at count %u", baseName.c_str(), amount); } callback(it->mapped + offset + 1, payLen, id); switch (counter) { @@ -483,7 +483,7 @@ namespace IPC { //bring the counter down if this was the last element if (id == amount - 1){ amount = id; - DEBUG_MSG(DLVL_DEVEL, "Shared memory %s is now at count %u", baseName.c_str(), amount); + DEBUG_MSG(DLVL_VERYHIGH, "Shared memory %s is now at count %u", baseName.c_str(), amount); } //stop, we're guaranteed no more pages are full at this point return; @@ -494,7 +494,7 @@ namespace IPC { //increase the count if needed if (id >= amount){ amount = id+1; - DEBUG_MSG(DLVL_DEVEL, "Shared memory %s is now at count %u", baseName.c_str(), amount); + DEBUG_MSG(DLVL_VERYHIGH, "Shared memory %s is now at count %u", baseName.c_str(), amount); } callback(it->mapped + offset, payLen, id); }else{ @@ -503,7 +503,7 @@ namespace IPC { //bring the counter down if this was the last element if (id == amount - 1){ amount = id; - DEBUG_MSG(DLVL_DEVEL, "Shared memory %s is now at count %u", baseName.c_str(), amount); + DEBUG_MSG(DLVL_VERYHIGH, "Shared memory %s is now at count %u", baseName.c_str(), amount); } //stop, we're guaranteed no more pages are full at this point if (empty){ diff --git a/lib/stream.cpp b/lib/stream.cpp index 3573bd0c..77dd6933 100644 --- a/lib/stream.cpp +++ b/lib/stream.cpp @@ -122,13 +122,16 @@ bool Util::Stream::getStream(std::string streamname){ sem_t * playerLock = sem_open(std::string("/lock_" + streamname).c_str(), O_CREAT | O_RDWR, ACCESSPERMS, 1); if (sem_trywait(playerLock) == -1){ sem_close(playerLock); + DEBUG_MSG(DLVL_MEDIUM, "Playerlock for %s already active - not re-activating stream", streamname.c_str()); return true; } sem_post(playerLock); sem_close(playerLock); if (ServConf["streams"][streamname]["source"].asString()[0] == '/'){ + DEBUG_MSG(DLVL_MEDIUM, "Activating VoD stream %s", streamname.c_str()); return getVod(ServConf["streams"][streamname]["source"].asString(), streamname); }else{ + DEBUG_MSG(DLVL_MEDIUM, "Activating live stream %s", streamname.c_str()); return getLive(streamname); } }