39#undef ZYPP_BASE_LOGGER_LOGGROUP
40#define ZYPP_BASE_LOGGER_LOGGROUP "zypp::exec"
126 const char *
const *
argv_1,
132 const char *
argv[
i + 1];
139 const char *
const *
argv_1,
146 const char *
argv[
i + 1];
169 DBG <<
"usePty was set, forcing the ForkSpawnEngine to start external processes" << std::endl;
170 _backend = std::make_unique<zyppng::ForkSpawnEngine>();
179 const char *
chdirTo =
nullptr;
183 if ( root[0] ==
'\0' )
187 else if ( root[0] ==
'/' && root[1] ==
'\0' )
199 switch (
argv[0][0] )
217 if (
argv[0][1] ==
'/' )
242 DBG <<
"Using ttys for communication with " <<
argv[0] << endl;
294 stderrFd = open(
"/dev/null",
O_WRONLY);
298 stderrFd = *stdoutFd;
317 _backend->setEnvironment( environment );
320 if (
_backend->start(
argv, stdinFd, stdoutFd, stderrFd ) ) {
321 bool connected =
true;
338 ERR <<
"Cannot create streams to external program " <<
argv[0] << endl;
347 bool ExternalProgram::waitForExit(std::optional<uint64_t> timeout)
353 return _backend->waitForExit( timeout );
360 ExternalDataSource::close();
394 ERR <<
"select error: " << strerror(
errno) << endl;
423 ExternalDataSource::close();
433 ERR <<
"Failed to kill PID " <<
_backend->pid() <<
" with error: " <<
Errno() << std::endl;
446 ERR <<
"Failed to kill PID " <<
_backend->pid() <<
" with error: " <<
Errno() << std::endl;
470 static std::string empty;
479 static std::string empty;
505 namespace externalprogram
536 if ( pos != std::string::npos )
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
void swap(AutoDispose &rhs) noexcept
Exchange the contents of two AutoDispose objects.
void resetDispose()
Set no dispose function.
Convenience errno wrapper.
bool stderrGetUpTo(std::string &retval_r, const char delim_r, bool returnDelim_r=false)
Read data up to delim_r from stderr (nonblocking).
ExternalProgram()
Start an external program by giving the arguments as an arry of char *pointers.
int close() override
Wait for the progamm to complete.
const std::string & command() const
The command we're executing.
std::ostream & operator>>(std::ostream &out_r)
Redirect all command output to an ostream.
void start_program(const char *const *argv, const Environment &environment, Stderr_Disposition stderr_disp=Normal_Stderr, int stderr_fd=-1, bool default_locale=false, const char *root=NULL, bool switch_pgid=false, bool die_with_parent=false, bool usePty=false)
std::vector< std::string > Arguments
~ExternalProgram() override
static void renumber_fd(int origfd, int newfd)
origfd will be accessible as newfd and closed (unless they were equal)
std::map< std::string, std::string > Environment
For passing additional environment variables to set.
bool kill()
Kill the program.
const std::string & execError() const
Some detail telling why the execution failed, if it failed.
bool running()
Return whether program is running.
Stderr_Disposition
Define symbols for different policies on the handling of stderr.
std::unique_ptr< zyppng::AbstractSpawnEngine > _backend
void setBlocking(bool mode)
Set the blocking mode of the input stream.
FILE * inputFile() const
Return the input stream.
std::string receiveLine()
Read one line from the input stream.
const char * c_str() const
String representation.
static std::unique_ptr< zyppng::AbstractSpawnEngine > createDefaultEngine()
void setUsePty(const bool set=true)
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Easy-to use interface to the ZYPP dependency resolver.
void renumberFd(int origfd, int newfd)
AutoDispose<int> calling ::close
#define for_(IT, BEG, END)
Convenient for-loops using iterator.