rename process_info to subprocess

master
Daniel Kolesa 2017-05-08 18:42:30 +02:00
parent 4022897195
commit 4966830d33
3 changed files with 17 additions and 17 deletions

View File

@ -111,9 +111,9 @@ static void print_help(ostd::string_range arg0) {
} }
static void exec_command(strvec const &args) { static void exec_command(strvec const &args) {
ostd::process_info pi; ostd::subprocess p;
pi.open_command(ostd::iter(args)); p.open_command(ostd::iter(args));
if (int ret; (ret = pi.close())) { if (int ret; (ret = p.close())) {
auto app = ostd::appender<std::string>(); auto app = ostd::appender<std::string>();
ostd::format(app, "command failed with code %d", ret); ostd::format(app, "command failed with code %d", ret);
throw std::runtime_error{app.get()}; throw std::runtime_error{app.get()};

View File

@ -86,7 +86,7 @@ enum class process_stream {
STDOUT STDOUT
}; };
struct OSTD_EXPORT process_info { struct OSTD_EXPORT subprocess {
process_stream use_in = process_stream::DEFAULT; process_stream use_in = process_stream::DEFAULT;
process_stream use_out = process_stream::DEFAULT; process_stream use_out = process_stream::DEFAULT;
process_stream use_err = process_stream::DEFAULT; process_stream use_err = process_stream::DEFAULT;
@ -94,14 +94,14 @@ struct OSTD_EXPORT process_info {
file_stream out = file_stream{}; file_stream out = file_stream{};
file_stream err = file_stream{}; file_stream err = file_stream{};
process_info() {} subprocess() {}
process_info( subprocess(
process_stream in_use, process_stream out_use, process_stream err_use process_stream in_use, process_stream out_use, process_stream err_use
): ):
use_in(in_use), use_out(out_use), use_err(err_use) use_in(in_use), use_out(out_use), use_err(err_use)
{} {}
process_info(process_info &&i): subprocess(subprocess &&i):
use_in(i.use_in), use_out(i.use_out), use_err(i.use_err), use_in(i.use_in), use_out(i.use_out), use_err(i.use_err),
in(std::move(i.in)), out(std::move(i.out)), err(std::move(i.err)), in(std::move(i.in)), out(std::move(i.out)), err(std::move(i.err)),
pid(i.pid), errno_fd(i.errno_fd) pid(i.pid), errno_fd(i.errno_fd)
@ -110,12 +110,12 @@ struct OSTD_EXPORT process_info {
i.errno_fd = -1; i.errno_fd = -1;
} }
process_info &operator=(process_info &&i) { subprocess &operator=(subprocess &&i) {
swap(i); swap(i);
return *this; return *this;
} }
void swap(process_info &i) { void swap(subprocess &i) {
using std::swap; using std::swap;
swap(use_in, i.use_in); swap(use_in, i.use_in);
swap(use_out, i.use_out); swap(use_out, i.use_out);
@ -127,7 +127,7 @@ struct OSTD_EXPORT process_info {
swap(errno_fd, i.errno_fd); swap(errno_fd, i.errno_fd);
} }
~process_info(); ~subprocess();
int close(); int close();

View File

@ -181,7 +181,7 @@ struct pipe {
} }
}; };
OSTD_EXPORT void process_info::open_impl( OSTD_EXPORT void subprocess::open_impl(
std::string const &cmd, std::vector<std::string> const &args, std::string const &cmd, std::vector<std::string> const &args,
bool use_path bool use_path
) { ) {
@ -266,14 +266,14 @@ OSTD_EXPORT void process_info::open_impl(
} }
} }
OSTD_EXPORT void process_info::reset() { OSTD_EXPORT void subprocess::reset() {
pid = -1; pid = -1;
if (errno_fd >= 0) { if (errno_fd >= 0) {
::close(std::exchange(errno_fd, -1)); ::close(std::exchange(errno_fd, -1));
} }
} }
OSTD_EXPORT int process_info::close() { OSTD_EXPORT int subprocess::close() {
if (pid < 0) { if (pid < 0) {
reset(); reset();
throw process_error{ECHILD, std::generic_category()}; throw process_error{ECHILD, std::generic_category()};
@ -296,7 +296,7 @@ OSTD_EXPORT int process_info::close() {
return retc; return retc;
} }
OSTD_EXPORT process_info::~process_info() { OSTD_EXPORT subprocess::~subprocess() {
try { try {
close(); close();
} catch (process_error const &) {} } catch (process_error const &) {}
@ -305,17 +305,17 @@ OSTD_EXPORT process_info::~process_info() {
#else /* OSTD_PLATFORM_WIN32 */ #else /* OSTD_PLATFORM_WIN32 */
OSTD_EXPORT void process_info::open_impl( OSTD_EXPORT void subprocess::open_impl(
std::string const &, std::vector<std::string> const &, bool std::string const &, std::vector<std::string> const &, bool
) { ) {
return; return;
} }
OSTD_EXPORT int process_info::close() { OSTD_EXPORT int subprocess::close() {
throw process_error{ECHILD, std::generic_category()}; throw process_error{ECHILD, std::generic_category()};
} }
OSTD_EXPORT process_info::~process_info() { OSTD_EXPORT subprocess::~subprocess() {
return; return;
} }