From 5674f5de8f127f8501a9c302533bfec903028102 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Tue, 23 Oct 2012 11:12:08 +0200 Subject: [PATCH] Implemented Util::getMyPath() --- lib/config.cpp | 15 +++++++++++++++ lib/config.h | 3 +++ lib/stream.cpp | 4 +++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/config.cpp b/lib/config.cpp index 7f653a81..cc9c6928 100644 --- a/lib/config.cpp +++ b/lib/config.cpp @@ -311,6 +311,21 @@ void Util::Config::addConnectorOptions(int port){ addOption("daemonize", JSON::fromString("{\"long\":\"daemon\", \"short\":\"d\", \"value\":[1], \"long_off\":\"nodaemon\", \"short_off\":\"n\", \"help\":\"Whether or not to daemonize the process after starting.\"}")); }//addConnectorOptions +/// Gets directory the current executable is stored in. +std::string Util::getMyPath(){ + char mypath[500]; + int ret = readlink("/proc/self/exe", mypath, 500); + if (ret != -1){mypath[ret] = 0;}else{mypath[0] = 0;} + std::string tPath = mypath; + size_t slash = tPath.rfind('/'); + if (slash == std::string::npos){ + slash = tPath.rfind('\\'); + if (slash == std::string::npos){return "";} + } + tPath.resize(slash+1); + return tPath; +} + /// Sets the current process' running user void Util::setUser(std::string username){ if (username != "root"){ diff --git a/lib/config.h b/lib/config.h index 099c9685..7e91a4b6 100644 --- a/lib/config.h +++ b/lib/config.h @@ -31,6 +31,9 @@ namespace Util{ void addConnectorOptions(int port); }; + /// Gets directory the current executable is stored in. + std::string getMyPath(); + /// Will set the active user to the named username. void setUser(std::string user); diff --git a/lib/stream.cpp b/lib/stream.cpp index a091325c..3b681c09 100644 --- a/lib/stream.cpp +++ b/lib/stream.cpp @@ -10,6 +10,7 @@ #include "json.h" #include "stream.h" #include "procs.h" +#include "config.h" #include "socket.h" /// Filters the streamname, removing invalid characters and converting all @@ -34,7 +35,8 @@ Socket::Connection Util::Stream::getLive(std::string streamname){ /// Starts a process for a VoD stream. Socket::Connection Util::Stream::getVod(std::string filename){ std::string name = "MistPlayer " + filename; - const char *argv[] = { "MistPlayer", filename.c_str(), NULL }; + std::string player_bin = Util::getMyPath() + "MistPlayer"; + const char *argv[] = {player_bin.c_str(), filename.c_str(), NULL}; int fdin = -1, fdout = -1, fderr = fileno(stderr); Util::Procs::StartPiped(name, (char **)argv, &fdin, &fdout, &fderr); // if StartPiped fails then fdin and fdout will be unmodified (-1)