libzypp  17.35.12
abstractspawnengine_p.h
Go to the documentation of this file.
1 #ifndef ZYPPNG_IO_PRIVATE_ABSTRACTPROCESSBACKEND_H
2 #define ZYPPNG_IO_PRIVATE_ABSTRACTPROCESSBACKEND_H
3 
4 #include <cstdint>
5 #include <string>
6 #include <vector>
7 #include <map>
8 #include <memory>
9 #include <optional>
10 
11 #include <zypp/Pathname.h>
12 
13 namespace zyppng {
14 
22  {
23  public:
24 
28  using Environment = std::map<std::string,std::string>;
29 
31  virtual ~AbstractSpawnEngine();
32 
33  static std::unique_ptr<zyppng::AbstractSpawnEngine> createDefaultEngine ();
34 
35  int exitStatus () const;
36  void setExitStatus ( const int state );
37 
38  const std::string &executedCommand () const;
39  const std::string &execError() const;
40  void setExecError ( const std::string & str );
41 
42  zypp::Pathname chroot() const;
43  void setChroot( const zypp::Pathname &chroot );
44 
45  bool useDefaultLocale() const;
46  void setUseDefaultLocale( bool defaultLocale );
47 
48  Environment environment() const;
49  void setEnvironment( const Environment &environment );
50 
55  pid_t pid ( );
56 
60  virtual bool start ( const char *const *argv, int stdin_fd, int stdout_fd, int stderr_fd ) = 0;
61 
62  virtual bool waitForExit ( const std::optional<uint64_t> &timeout = {} ) = 0;
63  virtual bool isRunning ( bool wait = false ) = 0;
64 
70  virtual void notifyExited ( int status );
71 
72  bool dieWithParent() const;
73  void setDieWithParent( bool dieWithParent );
74 
75  bool switchPgid() const;
76  void setSwitchPgid(bool switchPgid);
77 
80 
81  const std::vector<int> &fdsToMap () const;
82  void addFd ( int fd );
83 
84  int checkStatus(int status);
85 
86  protected:
87  bool _useDefaultLocale = false;
89  bool _dieWithParent = false;
90 
91  bool _switchPgid = false;
92 
93  pid_t _pid = -1;
94  int _exitStatus = 0;
96  std::string _execError;
98  std::string _executedCommand;
100  std::vector<std::string> _args;
108  std::vector<int> _mapFds;
109 
110  };
111 
112 } // namespace zyppng
113 
114 #endif // ZYPPNG_IO_PRIVATE_ABSTRACTPROCESSBACKEND_H
zypp::Pathname workingDirectory() const
zypp::Pathname _workingDirectory
Working directory.
virtual void notifyExited(int status)
static std::unique_ptr< zyppng::AbstractSpawnEngine > createDefaultEngine()
std::string _execError
Remember execution errors like failed fork/exec.
const std::string & execError() const
String related utilities and Regular expression matching.
void setUseDefaultLocale(bool defaultLocale)
bool _dieWithParent
Should the process die with the parent process.
virtual bool start(const char *const *argv, int stdin_fd, int stdout_fd, int stderr_fd)=0
void setWorkingDirectory(const zypp::Pathname &workingDirectory)
std::vector< std::string > _args
The arguments we want to pass to the program.
void setExecError(const std::string &str)
void setEnvironment(const Environment &environment)
void setChroot(const zypp::Pathname &chroot)
zypp::Pathname _chroot
Path to chroot into.
void setDieWithParent(bool dieWithParent)
std::string _executedCommand
Store the command we&#39;re executing.
virtual bool waitForExit(const std::optional< uint64_t > &timeout={})=0
zypp::Pathname chroot() const
void setExitStatus(const int state)
const std::string & executedCommand() const
virtual bool isRunning(bool wait=false)=0
void setSwitchPgid(bool switchPgid)
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.
const std::vector< int > & fdsToMap() const
Environment _environment
Environment variables to set in the new process.