From 16278a60c1f8ce82521955f5d834393ef23e8a20 Mon Sep 17 00:00:00 2001 From: heck Date: Fri, 8 Oct 2021 20:11:18 +0200 Subject: [PATCH] Fix: cwd is processDir() always --- src/AbstractPityUnit.cc | 6 ++++-- src/AbstractPityUnit.hh | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/AbstractPityUnit.cc b/src/AbstractPityUnit.cc index 413f7de..eea8e73 100644 --- a/src/AbstractPityUnit.cc +++ b/src/AbstractPityUnit.cc @@ -206,7 +206,7 @@ namespace pEp { } - // TODO: hack + // TODO: hack move to _executeOnFork() setenv("HOME", getProcessDir().c_str(), true); // Execute in fork and wait here until process ends @@ -333,11 +333,13 @@ namespace pEp { _waitChildProcesses(); } - void AbstractPityUnit::_executeInFork(std::function func, bool wait_child) const + void AbstractPityUnit::_executeInFork(std::function func, bool wait_child) { pid_t pid; pid = fork(); if (pid == pid_t(0)) { + // Setup process env. + Utils::dir_set_cwd(getProcessDir()); func(); exit(0); } else if (pid < pid_t(0)) { diff --git a/src/AbstractPityUnit.hh b/src/AbstractPityUnit.hh index 9406b4a..03fed3a 100644 --- a/src/AbstractPityUnit.hh +++ b/src/AbstractPityUnit.hh @@ -103,7 +103,7 @@ namespace pEp { void _initDirsRecursive(); void _runRecurse(); virtual void _runSelf() = 0; - void _executeInFork(std::function func, bool wait_child) const; + void _executeInFork(std::function func, bool wait_child); void _waitChildProcesses() const; // Transport