ForkExec: allow passing arguments to helper

The optional args array will be used when executing the helper
executable.
This commit is contained in:
Patrick Ohly 2013-07-11 11:40:51 +02:00
parent a69018e6da
commit f2378b7909
2 changed files with 12 additions and 5 deletions

View File

@ -88,8 +88,9 @@ ForkExec::ForkExec()
static Mutex ForkExecMutex;
static unsigned int ForkExecCount;
ForkExecParent::ForkExecParent(const std::string &helper) :
ForkExecParent::ForkExecParent(const std::string &helper, const std::vector<std::string> &args) :
m_helper(helper),
m_args(args),
m_childPid(0),
m_hasConnected(false),
m_hasQuit(false),
@ -108,9 +109,10 @@ ForkExecParent::ForkExecParent(const std::string &helper) :
m_instance = StringPrintf("forkexec%u", ForkExecCount);
}
boost::shared_ptr<ForkExecParent> ForkExecParent::create(const std::string &helper)
boost::shared_ptr<ForkExecParent> ForkExecParent::create(const std::string &helper,
const std::vector<std::string> &args)
{
boost::shared_ptr<ForkExecParent> forkexec(new ForkExecParent(helper));
boost::shared_ptr<ForkExecParent> forkexec(new ForkExecParent(helper, args));
return forkexec;
}
@ -212,6 +214,9 @@ void ForkExecParent::start()
}
m_argvStrings.push_back(helper);
m_argvStrings.insert(m_argvStrings.end(),
m_args.begin(),
m_args.end());
m_argv.reset(AllocStringArray(m_argvStrings));
for (char **env = environ;
*env;

View File

@ -126,7 +126,8 @@ class ForkExecParent : public ForkExec
* will not start the helper yet: first connect your slots, then
* call start().
*/
static boost::shared_ptr<ForkExecParent> create(const std::string &helper);
static boost::shared_ptr<ForkExecParent> create(const std::string &helper,
const std::vector<std::string> &args = std::vector<std::string>());
/**
* the helper string passed to create()
@ -203,9 +204,10 @@ class ForkExecParent : public ForkExec
void addEnvVar(const std::string &name, const std::string &value);
private:
ForkExecParent(const std::string &helper);
ForkExecParent(const std::string &helper, const std::vector<std::string> &args);
std::string m_helper;
std::vector<std::string> m_args;
boost::shared_ptr<GDBusCXX::DBusServerCXX> m_server;
boost::scoped_array<char *> m_argv;
std::list<std::string> m_argvStrings;