@@ -15,11 +15,12 @@ pub unsafe fn setup(build: &mut crate::Build) {
15
15
///
16
16
/// Most of the time when you're running a build system (e.g., make) you expect
17
17
/// Ctrl-C or abnormal termination to actually terminate the entire tree of
18
- /// process in play, not just the one at the top . This currently works "by
18
+ /// processes in play. This currently works "by
19
19
/// default" on Unix platforms because Ctrl-C actually sends a signal to the
20
- /// *process group* rather than the parent process, so everything will get torn
21
- /// down. On Windows, however, this does not happen and Ctrl-C just kills the
22
- /// parent process.
20
+ /// *process group* so everything will get torn
21
+ /// down. On Windows, however, Ctrl-C is only sent to processes in the same console.
22
+ /// If a process is detached or attached to another console, it won't receive the
23
+ /// signal.
23
24
///
24
25
/// To achieve the same semantics on Windows we use Job Objects to ensure that
25
26
/// all processes die at the same time. Job objects have a mode of operation
@@ -87,15 +88,7 @@ mod for_windows {
87
88
) ;
88
89
assert ! ( r. is_ok( ) , "{}" , io:: Error :: last_os_error( ) ) ;
89
90
90
- // Assign our process to this job object. Note that if this fails, one very
91
- // likely reason is that we are ourselves already in a job object! This can
92
- // happen on the build bots that we've got for Windows, or if just anyone
93
- // else is instrumenting the build. In this case we just bail out
94
- // immediately and assume that they take care of it.
95
- //
96
- // Also note that nested jobs (why this might fail) are supported in recent
97
- // versions of Windows, but the version of Windows that our bots are running
98
- // at least don't support nested job objects.
91
+ // Assign our process to this job object.
99
92
let r = AssignProcessToJobObject ( job, GetCurrentProcess ( ) ) ;
100
93
if r. is_err ( ) {
101
94
CloseHandle ( job) . ok ( ) ;
@@ -124,14 +117,19 @@ mod for_windows {
124
117
// (only when wrongly setting the environmental variable),
125
118
// it might be better to improve the experience of the second case
126
119
// when users have interrupted the parent process and we haven't finish
127
- // duplicating the handle yet. We just need close the job object if that occurs.
128
- CloseHandle ( job) . ok ( ) ;
120
+ // duplicating the handle yet.
129
121
return ;
130
122
}
131
123
} ;
132
124
133
125
let mut parent_handle = HANDLE :: default ( ) ;
134
- let r = DuplicateHandle (
126
+ // If this fails, well at least we tried! An example of DuplicateHandle
127
+ // failing in the past has been when the wrong python2 package spawned this
128
+ // build system (e.g., the `python2` package in MSYS instead of
129
+ // `mingw-w64-x86_64-python2`). Not sure why it failed, but the "failure
130
+ // mode" here is that we only clean everything up when the build system
131
+ // dies, not when the python parent does, so not too bad.
132
+ let _ = DuplicateHandle (
135
133
GetCurrentProcess ( ) ,
136
134
job,
137
135
parent,
@@ -140,15 +138,6 @@ mod for_windows {
140
138
false ,
141
139
DUPLICATE_SAME_ACCESS ,
142
140
) ;
143
-
144
- // If this failed, well at least we tried! An example of DuplicateHandle
145
- // failing in the past has been when the wrong python2 package spawned this
146
- // build system (e.g., the `python2` package in MSYS instead of
147
- // `mingw-w64-x86_64-python2`). Not sure why it failed, but the "failure
148
- // mode" here is that we only clean everything up when the build system
149
- // dies, not when the python parent does, so not too bad.
150
- if r. is_err ( ) {
151
- CloseHandle ( job) . ok ( ) ;
152
- }
141
+ CloseHandle ( parent) . ok ( ) ;
153
142
}
154
143
}
0 commit comments