aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--butl/process10
-rw-r--r--butl/process.ixx30
2 files changed, 38 insertions, 2 deletions
diff --git a/butl/process b/butl/process
index 6077ad3..e96f7ce 100644
--- a/butl/process
+++ b/butl/process
@@ -83,14 +83,20 @@ namespace butl
~process () {if (id != 0) wait ();}
- // Move constructible-only type.
+ // Moveable-only type.
//
process (process&&);
- process& operator= (process&&) = delete;
+ process& operator= (process&&);
process (const process&) = delete;
process& operator= (const process&) = delete;
+ // Create an empty or "already terminated" process. That is, id is 0
+ // and exit status is 0.
+ //
+ process ();
+
+ public:
#ifndef _WIN32
typedef pid_t id_type;
typedef int status_type;
diff --git a/butl/process.ixx b/butl/process.ixx
index a049764..baf55f8 100644
--- a/butl/process.ixx
+++ b/butl/process.ixx
@@ -5,6 +5,16 @@
namespace butl
{
inline process::
+ process ()
+ : id (0),
+ status (0), // This is a bit of an assumption.
+ out_fd (-1),
+ in_ofd (-1),
+ in_efd (-1)
+ {
+ }
+
+ inline process::
process (char const* const args[], int in, int out, int err)
: process (nullptr, args, in, out, err) {}
@@ -22,4 +32,24 @@ namespace butl
{
p.id = 0;
}
+
+ inline process& process::
+ operator= (process&& p)
+ {
+ if (this != &p)
+ {
+ if (id != 0)
+ wait ();
+
+ id = p.id;
+ status = p.status;
+ out_fd = p.out_fd;
+ in_ofd = p.in_ofd;
+ in_efd = p.in_efd;
+
+ p.id = 0;
+ }
+
+ return *this;
+ }
}