]> git.proxmox.com Git - rustc.git/blob - src/libstd/sys/unix/ext/process.rs
Imported Upstream version 1.1.0+dfsg1
[rustc.git] / src / libstd / sys / unix / ext / process.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! Unix-specific extensions to primitives in the `std::process` module.
12
13 #![stable(feature = "rust1", since = "1.0.0")]
14
15 use os::unix::raw::{uid_t, gid_t};
16 use prelude::v1::*;
17 use process;
18 use sys;
19 use sys_common::{AsInnerMut, AsInner};
20
21 /// Unix-specific extensions to the `std::process::Command` builder
22 #[stable(feature = "rust1", since = "1.0.0")]
23 pub trait CommandExt {
24 /// Sets the child process's user id. This translates to a
25 /// `setuid` call in the child process. Failure in the `setuid`
26 /// call will cause the spawn to fail.
27 #[stable(feature = "rust1", since = "1.0.0")]
28 fn uid(&mut self, id: uid_t) -> &mut process::Command;
29
30 /// Similar to `uid`, but sets the group id of the child process. This has
31 /// the same semantics as the `uid` field.
32 #[stable(feature = "rust1", since = "1.0.0")]
33 fn gid(&mut self, id: gid_t) -> &mut process::Command;
34 }
35
36 #[stable(feature = "rust1", since = "1.0.0")]
37 impl CommandExt for process::Command {
38 fn uid(&mut self, id: uid_t) -> &mut process::Command {
39 self.as_inner_mut().uid = Some(id);
40 self
41 }
42
43 fn gid(&mut self, id: gid_t) -> &mut process::Command {
44 self.as_inner_mut().gid = Some(id);
45 self
46 }
47 }
48
49 /// Unix-specific extensions to `std::process::ExitStatus`
50 #[stable(feature = "rust1", since = "1.0.0")]
51 pub trait ExitStatusExt {
52 /// If the process was terminated by a signal, returns that signal.
53 #[stable(feature = "rust1", since = "1.0.0")]
54 fn signal(&self) -> Option<i32>;
55 }
56
57 #[stable(feature = "rust1", since = "1.0.0")]
58 impl ExitStatusExt for process::ExitStatus {
59 fn signal(&self) -> Option<i32> {
60 match *self.as_inner() {
61 sys::process::ExitStatus::Signal(s) => Some(s),
62 _ => None
63 }
64 }
65 }