libfilezilla
process.hpp
Go to the documentation of this file.
1 #ifndef LIBFILEZILLA_PROCESS_HEADER
2 #define LIBFILEZILLA_PROCESS_HEADER
3 
4 #include "libfilezilla.hpp"
5 
10 #include <vector>
11 
12 #ifdef FZ_WINDOWS
13 #include "glue/windows.hpp"
14 #endif
15 
16 namespace fz {
17 class impersonation_token;
18 
26 class FZ_PUBLIC_SYMBOL process final
27 {
28 public:
29  process();
30  ~process();
31 
32  process(process const&) = delete;
33  process& operator=(process const&) = delete;
34 
46  bool spawn(native_string const& cmd, std::vector<native_string> const& args = std::vector<native_string>(), bool redirect_io = true);
47 
48  bool spawn(std::vector<native_string> const& command_with_args, bool redirect_io = true);
49 
50 #if FZ_WINDOWS || FZ_UNIX
51  bool spawn(impersonation_token const& it, native_string const& cmd, std::vector<native_string> const& args, bool redirect_io = true);
53 #endif
54 
55 #ifndef FZ_WINDOWS
56 
62  bool spawn(native_string const& cmd, std::vector<native_string> const& args, std::vector<int> const& extra_fds, bool redirect_io = true);
63 
64  bool spawn(impersonation_token const& it, native_string const& cmd, std::vector<native_string> const& args, std::vector<int> const& extra_fds, bool redirect_io = true);
65 #endif
66 
73  void kill();
74 
83  int read(char* buffer, unsigned int len);
84 
92  bool write(char const* buffer, unsigned int len);
93 
94  inline bool write(std::string_view const& s) {
95  return write(s.data(), static_cast<unsigned int>(s.size()));
96  }
97 
98 #if FZ_WINDOWS
99 
102  HANDLE handle() const;
103 #endif
104 
105 private:
106  class impl;
107  impl* impl_;
108 };
109 
110 
119 bool FZ_PUBLIC_SYMBOL spawn_detached_process(std::vector<native_string> const& cmd_with_args);
120 
121 #if !FZ_WINDOWS
122 
131 class FZ_PUBLIC_SYMBOL forkblock final
132 {
133 public:
134  forkblock();
135  ~forkblock();
136 
137  forkblock(forkblock const&) = delete;
138  forkblock& operator=(forkblock const&) = delete;
139 };
140 #endif
141 
142 }
143 
144 #endif
bool spawn_detached_process(std::vector< native_string > const &cmd_with_args)
Starts a detached process.
Impersonation tokens for a given user can be used to spawn processes running as that user...
Definition: impersonation.hpp:32
std::wstring native_string
A string in the system's native character type and encoding. Note: This typedef changes depending on...
Definition: string.hpp:33
The namespace used by libfilezilla.
Definition: apply.hpp:17
Sets some global macros and further includes string.hpp.
The buffer class is a simple buffer where data can be appended at the end and consumed at the front...
Definition: buffer.hpp:26
The process class manages an asynchronous process with redirected IO.
Definition: process.hpp:26