diff options
Diffstat (limited to 'butl')
-rw-r--r-- | butl/process | 11 | ||||
-rw-r--r-- | butl/process.cxx | 12 | ||||
-rw-r--r-- | butl/process.ixx | 11 |
3 files changed, 28 insertions, 6 deletions
diff --git a/butl/process b/butl/process index c810b58..534ad88 100644 --- a/butl/process +++ b/butl/process @@ -67,23 +67,32 @@ namespace butl // Wait for the process to terminate. Return true if the process // terminated normally and with the zero exit status. Throw - // process_error if anything goes wrong. + // process_error if anything goes wrong. This function can be + // called multiple times with subsequent calls simply returning + // the status. // bool wait (); ~process () {if (id != 0) wait ();} + // Move constructible-only type. + // + process (process&&); + process& operator= (process&&) = delete; + process (const process&) = delete; process& operator= (const process&) = delete; #ifndef _WIN32 typedef pid_t id_type; + typedef int status_type; #else typedef void* id_type; // Win32 HANDLE. #endif id_type id; + status_type status; int out_fd; // Write to this fd to send to the new process' stdin. int in_ofd; // Read from this fd to receive from the new process' stdout. diff --git a/butl/process.cxx b/butl/process.cxx index 9025bdb..194ea4e 100644 --- a/butl/process.cxx +++ b/butl/process.cxx @@ -108,12 +108,14 @@ namespace butl bool process:: wait () { - int status; - int r (waitpid (id, &status, 0)); - id = 0; // We have tried. + if (id != 0) + { + int r (waitpid (id, &status, 0)); + id = 0; // We have tried. - if (r == -1) - throw process_error (errno, false); + if (r == -1) + throw process_error (errno, false); + } return WIFEXITED (status) && WEXITSTATUS (status) == 0; } diff --git a/butl/process.ixx b/butl/process.ixx index 0506793..a0948e1 100644 --- a/butl/process.ixx +++ b/butl/process.ixx @@ -11,4 +11,15 @@ namespace butl inline process:: process (char const* args[], process& in, int out, int err) : process (nullptr, args, in, out, err) {} + + inline process:: + process (process&& p) + : id (p.id), + status (p.status), + out_fd (p.out_fd), + in_ofd (p.in_ofd), + in_efd (p.in_efd) + { + p.id = 0; + } } |