10#undef ZYPP_BASE_LOGGER_LOGGROUP
11#define ZYPP_BASE_LOGGER_LOGGROUP "zypp::exec"
16#if ZYPP_HAS_GLIBSPAWNENGINE
19 enum class SpawnEngine {
24 SpawnEngine initEngineFromEnv () {
26 if ( fBackend.empty() || fBackend ==
"auto" || fBackend ==
"pfork" ) {
27 DBG <<
"Starting processes via posix fork" << std::endl;
28 return SpawnEngine::PFORK;
29 }
else if ( fBackend ==
"gspawn" ) {
30 DBG <<
"Starting processes via glib spawn" << std::endl;
31 return SpawnEngine::GSPAWN;
34 DBG <<
"Falling back to starting process via posix fork" << std::endl;
35 return SpawnEngine::PFORK;
38 std::unique_ptr<zyppng::AbstractSpawnEngine>
engineFromEnv () {
39 static const SpawnEngine eng = initEngineFromEnv();
41 case SpawnEngine::GSPAWN:
42 return std::make_unique<zyppng::GlibSpawnEngine>();
43 case SpawnEngine::PFORK:
45 return std::make_unique<zyppng::ForkSpawnEngine>();
52 return std::make_unique<zyppng::ForkSpawnEngine>();
177 if (WIFEXITED (status))
179 status = WEXITSTATUS (status);
182 WAR <<
"Pid " <<
_pid <<
" exited with status " << status << std::endl;
189 DBG <<
"Pid " <<
_pid <<
" successfully completed" << std::endl;
193 else if (WIFSIGNALED (status))
195 status = WTERMSIG (status);
196 std::string sigdetail { strsignal(status) };
197 if ( WCOREDUMP(status) ) {
198 sigdetail +=
"; Core dumped";
200 if ( status == SIGKILL ) {
201 sigdetail +=
"; Out of memory?";
203 WAR <<
"Pid " <<
_pid <<
" was killed by signal " << status <<
" (" << sigdetail <<
")" << std::endl;
208 ERR <<
"Pid " <<
_pid <<
" exited with unknown error" << std::endl;
209 _execError =
_(
"Command exited with unknown error.");
zypp::Pathname _chroot
Path to chroot into.
bool dieWithParent() const
void setSwitchPgid(bool switchPgid)
const std::string & executedCommand() const
Environment environment() const
const std::vector< int > & fdsToMap() const
zypp::Pathname workingDirectory() const
void setExecError(const std::string &str)
zypp::Pathname _workingDirectory
Working directory.
std::string _execError
Remember execution errors like failed fork/exec.
std::string _executedCommand
Store the command we're executing.
bool _dieWithParent
Should the process die with the parent process.
virtual ~AbstractSpawnEngine()
std::map< std::string, std::string > Environment
For passing additional environment variables to set.
std::vector< int > _mapFds
Additional file descriptors we want to map to the new process.
void setExitStatus(const int state)
void setChroot(const zypp::Pathname &chroot)
virtual void notifyExited(int status)
Environment _environment
Environment variables to set in the new process.
bool useDefaultLocale() const
void setWorkingDirectory(const zypp::Pathname &workingDirectory)
int checkStatus(int status)
zypp::Pathname chroot() const
void setUseDefaultLocale(bool defaultLocale)
static std::unique_ptr< zyppng::AbstractSpawnEngine > createDefaultEngine()
void setEnvironment(const Environment &environment)
const std::string & execError() const
void setDieWithParent(bool dieWithParent)
String related utilities and Regular expression matching.
const std::string & asString(const std::string &t)
Global asString() that works with std::string too.
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
std::unique_ptr< zyppng::AbstractSpawnEngine > engineFromEnv()