Skip to content

Commit b8bd8f3

Browse files
committed
std: Rename Stdio::None to Stdio::Null
This better reflects what it's actually doing as we don't actually have an option for "leave this I/O slot as an empty hole".
1 parent 627515a commit b8bd8f3

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

src/libstd/process.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ fn setup_io(io: &Stdio, readable: bool)
385385
}
386386
StdioImp::Raw(ref owned) => (imp::Stdio::Raw(owned.raw()), None, None),
387387
StdioImp::Inherit => (imp::Stdio::Inherit, None, None),
388-
StdioImp::None => (imp::Stdio::None, None, None),
388+
StdioImp::Null => (imp::Stdio::Null, None, None),
389389
})
390390
}
391391

@@ -439,7 +439,7 @@ enum StdioImp {
439439
MakePipe,
440440
Raw(imp::RawStdio),
441441
Inherit,
442-
None,
442+
Null,
443443
}
444444

445445
impl Stdio {
@@ -454,7 +454,7 @@ impl Stdio {
454454
/// This stream will be ignored. This is the equivalent of attaching the
455455
/// stream to `/dev/null`
456456
#[stable(feature = "process", since = "1.0.0")]
457-
pub fn null() -> Stdio { Stdio(StdioImp::None) }
457+
pub fn null() -> Stdio { Stdio(StdioImp::Null) }
458458
}
459459

460460
impl FromInner<imp::RawStdio> for Stdio {

src/libstd/sys/unix/process.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ pub struct Process {
275275

276276
pub enum Stdio {
277277
Inherit,
278-
None,
278+
Null,
279279
Raw(c_int),
280280
}
281281

@@ -416,7 +416,7 @@ impl Process {
416416
Stdio::Raw(fd.into_raw())
417417
})
418418
}
419-
s @ Stdio::None |
419+
s @ Stdio::Null |
420420
s @ Stdio::Inherit |
421421
s @ Stdio::Raw(_) => Ok(s),
422422
}
@@ -430,12 +430,10 @@ impl Process {
430430
Stdio::Inherit => Ok(()),
431431
Stdio::Raw(fd) => cvt_r(|| libc::dup2(fd, dst)).map(|_| ()),
432432

433-
// If a stdio file descriptor is set to be ignored, we open up
434-
// /dev/null into that file descriptor. Otherwise, the first
435-
// file descriptor opened up in the child would be numbered as
436-
// one of the stdio file descriptors, which is likely to wreak
437-
// havoc.
438-
Stdio::None => {
433+
// Open up a reference to /dev/null with appropriate read/write
434+
// permissions and then move it into the correct location via
435+
// `dup2`.
436+
Stdio::Null => {
439437
let mut opts = OpenOptions::new();
440438
opts.read(dst == libc::STDIN_FILENO);
441439
opts.write(dst != libc::STDIN_FILENO);
@@ -590,7 +588,7 @@ mod tests {
590588

591589
let cat = t!(Process::spawn(&cmd, Stdio::Raw(stdin_read.raw()),
592590
Stdio::Raw(stdout_write.raw()),
593-
Stdio::None));
591+
Stdio::Null));
594592
drop(stdin_read);
595593
drop(stdout_write);
596594

src/libstd/sys/windows/process.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ pub struct Process {
122122

123123
pub enum Stdio {
124124
Inherit,
125-
None,
125+
Null,
126126
Raw(c::HANDLE),
127127
}
128128

@@ -386,11 +386,10 @@ impl Stdio {
386386
RawHandle::new(handle).duplicate(0, true, c::DUPLICATE_SAME_ACCESS)
387387
}
388388

389-
// Similarly to unix, we don't actually leave holes for the
390-
// stdio file descriptors, but rather open up /dev/null
391-
// equivalents. These equivalents are drawn from libuv's
392-
// windows process spawning.
393-
Stdio::None => {
389+
// Open up a reference to NUL with appropriate read/write
390+
// permissions as well as the ability to be inherited to child
391+
// processes (as this is about to be inherited).
392+
Stdio::Null => {
394393
let size = mem::size_of::<c::SECURITY_ATTRIBUTES>();
395394
let mut sa = c::SECURITY_ATTRIBUTES {
396395
nLength: size as c::DWORD,

0 commit comments

Comments
 (0)