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.
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.
11 //! Unix-specific extensions to primitives in the `std::process` module.
13 #![stable(feature = "rust1", since = "1.0.0")]
15 use os
::unix
::raw
::{uid_t, gid_t}
;
16 use os
::unix
::io
::{FromRawFd, RawFd, AsRawFd, IntoRawFd}
;
20 use sys_common
::{AsInnerMut, AsInner, FromInner, IntoInner}
;
22 /// Unix-specific extensions to the `std::process::Command` builder
23 #[stable(feature = "rust1", since = "1.0.0")]
24 pub trait CommandExt
{
25 /// Sets the child process's user id. This translates to a
26 /// `setuid` call in the child process. Failure in the `setuid`
27 /// call will cause the spawn to fail.
28 #[stable(feature = "rust1", since = "1.0.0")]
29 fn uid(&mut self, id
: uid_t
) -> &mut process
::Command
;
31 /// Similar to `uid`, but sets the group id of the child process. This has
32 /// the same semantics as the `uid` field.
33 #[stable(feature = "rust1", since = "1.0.0")]
34 fn gid(&mut self, id
: gid_t
) -> &mut process
::Command
;
37 #[stable(feature = "rust1", since = "1.0.0")]
38 impl CommandExt
for process
::Command
{
39 fn uid(&mut self, id
: uid_t
) -> &mut process
::Command
{
40 self.as_inner_mut().uid
= Some(id
);
44 fn gid(&mut self, id
: gid_t
) -> &mut process
::Command
{
45 self.as_inner_mut().gid
= Some(id
);
50 /// Unix-specific extensions to `std::process::ExitStatus`
51 #[stable(feature = "rust1", since = "1.0.0")]
52 pub trait ExitStatusExt
{
53 /// If the process was terminated by a signal, returns that signal.
54 #[stable(feature = "rust1", since = "1.0.0")]
55 fn signal(&self) -> Option
<i32>;
58 #[stable(feature = "rust1", since = "1.0.0")]
59 impl ExitStatusExt
for process
::ExitStatus
{
60 fn signal(&self) -> Option
<i32> {
61 match *self.as_inner() {
62 sys
::process
::ExitStatus
::Signal(s
) => Some(s
),
68 #[stable(feature = "process_extensions", since = "1.2.0")]
69 impl FromRawFd
for process
::Stdio
{
70 unsafe fn from_raw_fd(fd
: RawFd
) -> process
::Stdio
{
71 process
::Stdio
::from_inner(sys
::fd
::FileDesc
::new(fd
))
75 #[stable(feature = "process_extensions", since = "1.2.0")]
76 impl AsRawFd
for process
::ChildStdin
{
77 fn as_raw_fd(&self) -> RawFd
{
78 self.as_inner().fd().raw()
82 #[stable(feature = "process_extensions", since = "1.2.0")]
83 impl AsRawFd
for process
::ChildStdout
{
84 fn as_raw_fd(&self) -> RawFd
{
85 self.as_inner().fd().raw()
89 #[stable(feature = "process_extensions", since = "1.2.0")]
90 impl AsRawFd
for process
::ChildStderr
{
91 fn as_raw_fd(&self) -> RawFd
{
92 self.as_inner().fd().raw()
96 impl IntoRawFd
for process
::ChildStdin
{
97 fn into_raw_fd(self) -> RawFd
{
98 self.into_inner().into_fd().into_raw()
102 impl IntoRawFd
for process
::ChildStdout
{
103 fn into_raw_fd(self) -> RawFd
{
104 self.into_inner().into_fd().into_raw()
108 impl IntoRawFd
for process
::ChildStderr
{
109 fn into_raw_fd(self) -> RawFd
{
110 self.into_inner().into_fd().into_raw()