summaryrefslogtreecommitdiff
path: root/cli/ops/process.rs
diff options
context:
space:
mode:
authorLuca Casonato <luca.casonato@antipy.com>2020-06-25 18:38:19 +0200
committerGitHub <noreply@github.com>2020-06-25 12:38:19 -0400
commit4102a195851033a21c4a23daac4c78ed2329f61f (patch)
tree2d33701fdec4cf065bdfd7f9324dc9316929c1e9 /cli/ops/process.rs
parent1fcb71b3556ed6d3a9c6bfa8fbf1ad8b700f8578 (diff)
fix: panic when process stdio rid is 0 or invalid (#6405)
Diffstat (limited to 'cli/ops/process.rs')
-rw-r--r--cli/ops/process.rs37
1 files changed, 17 insertions, 20 deletions
diff --git a/cli/ops/process.rs b/cli/ops/process.rs
index 78d9313c0..384068e6a 100644
--- a/cli/ops/process.rs
+++ b/cli/ops/process.rs
@@ -33,12 +33,12 @@ fn clone_file(
})
}
-fn subprocess_stdio_map(s: &str) -> std::process::Stdio {
+fn subprocess_stdio_map(s: &str) -> Result<std::process::Stdio, OpError> {
match s {
- "inherit" => std::process::Stdio::inherit(),
- "piped" => std::process::Stdio::piped(),
- "null" => std::process::Stdio::null(),
- _ => unreachable!(),
+ "inherit" => Ok(std::process::Stdio::inherit()),
+ "piped" => Ok(std::process::Stdio::piped()),
+ "null" => Ok(std::process::Stdio::null()),
+ _ => Err(OpError::other("Invalid resource for stdio".to_string())),
}
}
@@ -86,28 +86,25 @@ fn op_run(
}
// TODO: make this work with other resources, eg. sockets
- let stdin_rid = run_args.stdin_rid;
- if stdin_rid > 0 {
- let file = clone_file(stdin_rid, &mut resource_table)?;
- c.stdin(file);
+ if run_args.stdin != "" {
+ c.stdin(subprocess_stdio_map(run_args.stdin.as_ref())?);
} else {
- c.stdin(subprocess_stdio_map(run_args.stdin.as_ref()));
+ let file = clone_file(run_args.stdin_rid, &mut resource_table)?;
+ c.stdin(file);
}
- let stdout_rid = run_args.stdout_rid;
- if stdout_rid > 0 {
- let file = clone_file(stdout_rid, &mut resource_table)?;
- c.stdout(file);
+ if run_args.stdout != "" {
+ c.stdout(subprocess_stdio_map(run_args.stdout.as_ref())?);
} else {
- c.stdout(subprocess_stdio_map(run_args.stdout.as_ref()));
+ let file = clone_file(run_args.stdout_rid, &mut resource_table)?;
+ c.stdout(file);
}
- let stderr_rid = run_args.stderr_rid;
- if stderr_rid > 0 {
- let file = clone_file(stderr_rid, &mut resource_table)?;
- c.stderr(file);
+ if run_args.stderr != "" {
+ c.stderr(subprocess_stdio_map(run_args.stderr.as_ref())?);
} else {
- c.stderr(subprocess_stdio_map(run_args.stderr.as_ref()));
+ let file = clone_file(run_args.stderr_rid, &mut resource_table)?;
+ c.stderr(file);
}
// We want to kill child when it's closed