Skip to content

Commit a4021d7

Browse files
garethgareth
authored andcommitted
---
yaml --- r: 139747 b: refs/heads/try2 c: 995d444 h: refs/heads/master i: 139745: 3835901 139743: a277ae6 v: v3
1 parent 36a716e commit a4021d7

File tree

3 files changed

+45
-13
lines changed

3 files changed

+45
-13
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 483e95a35c9f3ab01666de4808134af26fded68c
8+
refs/heads/try2: 995d44416b203b5b3ba619250ff8effdcf205049
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libcore/libc.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,7 @@ pub mod consts {
864864
pub static F_TLOCK : int = 2;
865865
pub static F_ULOCK : int = 0;
866866
pub static SIGKILL : int = 9;
867+
pub static SIGTERM : int = 15;
867868
}
868869
pub mod posix01 {
869870
}
@@ -932,6 +933,7 @@ pub mod consts {
932933
pub static F_TLOCK : int = 2;
933934
pub static F_ULOCK : int = 0;
934935
pub static SIGKILL : int = 9;
936+
pub static SIGTERM : int = 15;
935937
}
936938
pub mod posix01 {
937939
}
@@ -1001,6 +1003,7 @@ pub mod consts {
10011003
pub static F_TLOCK : int = 2;
10021004
pub static F_ULOCK : int = 0;
10031005
pub static SIGKILL : int = 9;
1006+
pub static SIGTERM : int = 15;
10041007
}
10051008
pub mod posix01 {
10061009
}

branches/try2/src/libcore/run.rs

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,22 @@ pub trait Program {
6363
fn finish(&mut self) -> int;
6464

6565
/**
66-
* Forcibly terminate the program. On Posix OSs SIGKILL will be sent
67-
* to the process. On Win32 TerminateProcess(..) will be called.
66+
* Terminate the program, giving it a chance to clean itself up if
67+
* this is supported by the operating system.
68+
*
69+
* On Posix OSs SIGTERM will be sent to the process. On Win32
70+
* TerminateProcess(..) will be called.
6871
*/
6972
fn destroy(&mut self);
73+
74+
/**
75+
* Terminate the program as soon as possible without giving it a
76+
* chance to clean itself up.
77+
*
78+
* On Posix OSs SIGKILL will be sent to the process. On Win32
79+
* TerminateProcess(..) will be called.
80+
*/
81+
fn force_destroy(&mut self);
7082
}
7183

7284

@@ -266,24 +278,30 @@ pub fn start_program(prog: &str, args: &[~str]) -> @Program {
266278
return waitpid(r.pid);
267279
}
268280

269-
fn destroy_repr(r: &mut ProgRepr) {
270-
killpid(r.pid);
281+
fn destroy_repr(r: &mut ProgRepr, force: bool) {
282+
killpid(r.pid, force);
271283
finish_repr(&mut *r);
272284
close_repr_outputs(&mut *r);
273285

274286
#[cfg(windows)]
275-
fn killpid(pid: pid_t) {
287+
fn killpid(pid: pid_t, _force: bool) {
276288
unsafe {
277289
libc::funcs::extra::kernel32::TerminateProcess(
278290
cast::transmute(pid), 1);
279291
}
280292
}
281293

282294
#[cfg(unix)]
283-
fn killpid(pid: pid_t) {
295+
fn killpid(pid: pid_t, force: bool) {
296+
297+
let signal = if force {
298+
libc::consts::os::posix88::SIGKILL
299+
} else {
300+
libc::consts::os::posix88::SIGTERM
301+
};
302+
284303
unsafe {
285-
libc::funcs::posix88::signal::kill(
286-
pid, libc::consts::os::posix88::SIGKILL as c_int);
304+
libc::funcs::posix88::signal::kill(pid, signal as c_int);
287305
}
288306
}
289307
}
@@ -321,7 +339,8 @@ pub fn start_program(prog: &str, args: &[~str]) -> @Program {
321339
}
322340
fn close_input(&mut self) { close_repr_input(&mut self.r); }
323341
fn finish(&mut self) -> int { finish_repr(&mut self.r) }
324-
fn destroy(&mut self) { destroy_repr(&mut self.r); }
342+
fn destroy(&mut self) { destroy_repr(&mut self.r, false); }
343+
fn force_destroy(&mut self) { destroy_repr(&mut self.r, true); }
325344
}
326345

327346
let mut repr = ProgRepr {
@@ -559,10 +578,9 @@ mod tests {
559578
p.destroy(); // ...and nor should this (and nor should the destructor)
560579
}
561580

562-
#[test]
563581
#[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");
582+
pub fn test_destroy_actually_kills(force: bool) {
583+
let path = Path(fmt!("test/core-run-test-destroy-actually-kills-%?.tmp", force));
566584

567585
os::remove_file(&path);
568586

@@ -580,6 +598,17 @@ mod tests {
580598
assert!(!path.exists());
581599
}
582600

601+
#[test]
602+
#[cfg(unix)]
603+
pub fn test_unforced_destroy_actually_kills() {
604+
test_destroy_actually_kills(false);
605+
}
606+
607+
#[test]
608+
#[cfg(unix)]
609+
pub fn test_forced_destroy_actually_kills() {
610+
test_destroy_actually_kills(true);
611+
}
583612
}
584613

585614
// Local Variables:

0 commit comments

Comments
 (0)