Implemented Util::getMyPath()

This commit is contained in:
Thulinma 2012-10-23 11:12:08 +02:00
parent 255e664e4c
commit 5674f5de8f
3 changed files with 21 additions and 1 deletions

View file

@ -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.\"}")); 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 }//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 /// Sets the current process' running user
void Util::setUser(std::string username){ void Util::setUser(std::string username){
if (username != "root"){ if (username != "root"){

View file

@ -31,6 +31,9 @@ namespace Util{
void addConnectorOptions(int port); void addConnectorOptions(int port);
}; };
/// Gets directory the current executable is stored in.
std::string getMyPath();
/// Will set the active user to the named username. /// Will set the active user to the named username.
void setUser(std::string user); void setUser(std::string user);

View file

@ -10,6 +10,7 @@
#include "json.h" #include "json.h"
#include "stream.h" #include "stream.h"
#include "procs.h" #include "procs.h"
#include "config.h"
#include "socket.h" #include "socket.h"
/// Filters the streamname, removing invalid characters and converting all /// 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. /// Starts a process for a VoD stream.
Socket::Connection Util::Stream::getVod(std::string filename){ Socket::Connection Util::Stream::getVod(std::string filename){
std::string name = "MistPlayer " + 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); int fdin = -1, fdout = -1, fderr = fileno(stderr);
Util::Procs::StartPiped(name, (char **)argv, &fdin, &fdout, &fderr); Util::Procs::StartPiped(name, (char **)argv, &fdin, &fdout, &fderr);
// if StartPiped fails then fdin and fdout will be unmodified (-1) // if StartPiped fails then fdin and fdout will be unmodified (-1)