Skip to content

Commit 2a9a0ef

Browse files
committed
---
yaml --- r: 57309 b: refs/heads/incoming c: eebf29e h: refs/heads/master i: 57307: 62c2dfb v: v3
1 parent 4b89d18 commit 2a9a0ef

File tree

4 files changed

+201
-248
lines changed

4 files changed

+201
-248
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: bf67eb2362b7d0f37012f2d6dac604c3bbacd2c6
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/incoming: 483e95a35c9f3ab01666de4808134af26fded68c
9+
refs/heads/incoming: eebf29ed377189c111afe457be920b645835296c
1010
refs/heads/dist-snap: 00dbbd01c2aee72982b3e0f9511ae1d4428c3ba9
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/src/libcore/libc.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,6 @@ pub mod consts {
863863
pub static F_TEST : int = 3;
864864
pub static F_TLOCK : int = 2;
865865
pub static F_ULOCK : int = 0;
866-
pub static SIGKILL : int = 9;
867866
}
868867
pub mod posix01 {
869868
}
@@ -931,7 +930,6 @@ pub mod consts {
931930
pub static F_TEST : int = 3;
932931
pub static F_TLOCK : int = 2;
933932
pub static F_ULOCK : int = 0;
934-
pub static SIGKILL : int = 9;
935933
}
936934
pub mod posix01 {
937935
}
@@ -1000,7 +998,6 @@ pub mod consts {
1000998
pub static F_TEST : int = 3;
1001999
pub static F_TLOCK : int = 2;
10021000
pub static F_ULOCK : int = 0;
1003-
pub static SIGKILL : int = 9;
10041001
}
10051002
pub mod posix01 {
10061003
}
@@ -1485,17 +1482,6 @@ pub mod funcs {
14851482
-> ssize_t;
14861483
}
14871484
}
1488-
1489-
#[nolink]
1490-
#[abi = "cdecl"]
1491-
pub mod signal {
1492-
use libc::types::os::arch::c95::{c_int};
1493-
use libc::types::os::arch::posix88::{pid_t};
1494-
1495-
pub extern {
1496-
unsafe fn kill(pid: pid_t, sig: c_int) -> c_int;
1497-
}
1498-
}
14991485
}
15001486

15011487
#[cfg(target_os = "linux")]
@@ -1637,7 +1623,6 @@ pub mod funcs {
16371623
pub mod extra {
16381624

16391625
pub mod kernel32 {
1640-
use libc::types::os::arch::c95::{c_uint};
16411626
use libc::types::os::arch::extra::{BOOL, DWORD, HMODULE};
16421627
use libc::types::os::arch::extra::{LPCWSTR, LPWSTR, LPTCH};
16431628
use libc::types::os::arch::extra::{LPSECURITY_ATTRIBUTES};
@@ -1678,7 +1663,6 @@ pub mod funcs {
16781663
findFileData: HANDLE)
16791664
-> BOOL;
16801665
unsafe fn FindClose(findFile: HANDLE) -> BOOL;
1681-
unsafe fn TerminateProcess(hProcess: HANDLE, uExitCode: c_uint) -> BOOL;
16821666
}
16831667
}
16841668

branches/incoming/src/libcore/run.rs

Lines changed: 13 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -44,13 +44,13 @@ pub trait Program {
4444
/// Returns the process id of the program
4545
fn get_id(&mut self) -> pid_t;
4646

47-
/// Returns an io::Writer that can be used to write to stdin
47+
/// Returns an io::writer that can be used to write to stdin
4848
fn input(&mut self) -> @io::Writer;
4949

50-
/// Returns an io::Reader that can be used to read from stdout
50+
/// Returns an io::reader that can be used to read from stdout
5151
fn output(&mut self) -> @io::Reader;
5252

53-
/// Returns an io::Reader that can be used to read from stderr
53+
/// Returns an io::reader that can be used to read from stderr
5454
fn err(&mut self) -> @io::Reader;
5555

5656
/// Closes the handle to the child processes standard input
@@ -62,10 +62,7 @@ pub trait Program {
6262
*/
6363
fn finish(&mut self) -> int;
6464

65-
/**
66-
* Forcibly terminate the program. On Posix OSs SIGKILL will be sent
67-
* to the process. On Win32 TerminateProcess(..) will be called.
68-
*/
65+
/// Closes open handles
6966
fn destroy(&mut self);
7067
}
7168

@@ -175,14 +172,6 @@ fn with_dirp<T>(d: &Option<~str>,
175172
}
176173
}
177174

178-
/// helper function that closes non-NULL files and then makes them NULL
179-
priv unsafe fn fclose_and_null(f: &mut *libc::FILE) {
180-
if *f != 0 as *libc::FILE {
181-
libc::fclose(*f);
182-
*f = 0 as *libc::FILE;
183-
}
184-
}
185-
186175
/**
187176
* Spawns a process and waits for it to terminate
188177
*
@@ -203,9 +192,9 @@ pub fn run_program(prog: &str, args: &[~str]) -> int {
203192
}
204193

205194
/**
206-
* Spawns a process and returns a Program
195+
* Spawns a process and returns a program
207196
*
208-
* The returned value is a boxed class containing a <Program> object that can
197+
* The returned value is a boxed class containing a <program> object that can
209198
* be used for sending and receiving data over the standard file descriptors.
210199
* The class will ensure that file descriptors are closed properly.
211200
*
@@ -251,53 +240,28 @@ pub fn start_program(prog: &str, args: &[~str]) -> @Program {
251240
r.in_fd = invalid_fd;
252241
}
253242
}
254-
255-
fn close_repr_outputs(r: &mut ProgRepr) {
256-
unsafe {
257-
fclose_and_null(&mut r.out_file);
258-
fclose_and_null(&mut r.err_file);
259-
}
260-
}
261-
262243
fn finish_repr(r: &mut ProgRepr) -> int {
263244
if r.finished { return 0; }
264245
r.finished = true;
265246
close_repr_input(&mut *r);
266247
return waitpid(r.pid);
267248
}
268-
269249
fn destroy_repr(r: &mut ProgRepr) {
270-
killpid(r.pid);
271-
finish_repr(&mut *r);
272-
close_repr_outputs(&mut *r);
273-
274-
#[cfg(windows)]
275-
fn killpid(pid: pid_t) {
276-
unsafe {
277-
libc::funcs::extra::kernel32::TerminateProcess(
278-
cast::transmute(pid), 1);
279-
}
280-
}
281-
282-
#[cfg(unix)]
283-
fn killpid(pid: pid_t) {
284-
unsafe {
285-
libc::funcs::posix88::signal::kill(
286-
pid, libc::consts::os::posix88::SIGKILL as c_int);
287-
}
250+
unsafe {
251+
finish_repr(&mut *r);
252+
libc::fclose(r.out_file);
253+
libc::fclose(r.err_file);
288254
}
289255
}
290-
291256
struct ProgRes {
292257
r: ProgRepr,
293258
}
294259

295260
impl Drop for ProgRes {
296261
fn finalize(&self) {
297262
unsafe {
298-
// FIXME #4943: transmute is bad.
299-
finish_repr(cast::transmute(&self.r));
300-
close_repr_outputs(cast::transmute(&self.r));
263+
// FIXME #4943: This is bad.
264+
destroy_repr(cast::transmute(&self.r));
301265
}
302266
}
303267
}
@@ -323,7 +287,6 @@ pub fn start_program(prog: &str, args: &[~str]) -> @Program {
323287
fn finish(&mut self) -> int { finish_repr(&mut self.r) }
324288
fn destroy(&mut self) { destroy_repr(&mut self.r); }
325289
}
326-
327290
let mut repr = ProgRepr {
328291
pid: pid,
329292
in_fd: pipe_input.out,
@@ -495,10 +458,8 @@ pub fn waitpid(pid: pid_t) -> int {
495458

496459
#[cfg(test)]
497460
mod tests {
498-
use libc;
499461
use option::None;
500462
use os;
501-
use path::Path;
502463
use run::{readclose, writeclose};
503464
use run;
504465

@@ -546,40 +507,6 @@ mod tests {
546507
assert!(status == 1);
547508
}
548509

549-
#[test]
550-
pub fn test_destroy_once() {
551-
let mut p = run::start_program("echo", []);
552-
p.destroy(); // this shouldn't crash (and nor should the destructor)
553-
}
554-
555-
#[test]
556-
pub fn test_destroy_twice() {
557-
let mut p = run::start_program("echo", []);
558-
p.destroy(); // this shouldnt crash...
559-
p.destroy(); // ...and nor should this (and nor should the destructor)
560-
}
561-
562-
#[test]
563-
#[cfg(unix)] // there is no way to sleep on windows from inside libcore...
564-
pub fn test_destroy_actually_kills() {
565-
let path = Path("test/core-run-test-destroy-actually-kills.tmp");
566-
567-
os::remove_file(&path);
568-
569-
let cmd = fmt!("sleep 5 && echo MurderDeathKill > %s", path.to_str());
570-
let mut p = run::start_program("sh", [~"-c", cmd]);
571-
572-
p.destroy(); // destroy the program before it has a chance to echo its message
573-
574-
unsafe {
575-
// wait to ensure the program is really destroyed and not just waiting itself
576-
libc::sleep(10);
577-
}
578-
579-
// the program should not have had chance to echo its message
580-
assert!(!path.exists());
581-
}
582-
583510
}
584511

585512
// Local Variables:

0 commit comments

Comments
 (0)