@@ -32,9 +32,9 @@ pub struct Test<'a> {
32
32
}
33
33
34
34
static TEST_FUNCTIONS : & [ & ' static Test < ' static > ] = & [
35
- // TODO: When did these tests start failing ?
35
+ // TODO: Why does clone process fail ?
36
36
// &clone_process,
37
- // &forked_pipe,
37
+ & forked_pipe,
38
38
& signal_handler,
39
39
& dup_fds,
40
40
& dup2_redirect_stdout,
@@ -126,49 +126,58 @@ fn dup_fds() -> Result<(), AeroSyscallError> {
126
126
127
127
#[ utest_proc:: test]
128
128
fn signal_handler ( ) -> Result < ( ) , AeroSyscallError > {
129
- let mut pipe = [ 0usize ; 2 ] ;
130
- sys_pipe ( & mut pipe, OpenFlags :: empty ( ) ) ?;
129
+ let child = sys_fork ( ) ?;
131
130
132
- static PIPE_WRITE : AtomicUsize = AtomicUsize :: new ( 0 ) ;
133
- PIPE_WRITE . store ( pipe[ 1 ] , Ordering :: SeqCst ) ;
131
+ // We perform the test in a forked process since then we dont
132
+ // have to worry about restoring the signal handlers.
133
+ if child == 0 {
134
+ let mut pipe = [ 0usize ; 2 ] ;
135
+ sys_pipe ( & mut pipe, OpenFlags :: empty ( ) ) ?;
134
136
135
- fn handle_segmentation_fault ( fault : usize ) {
136
- core :: assert_eq! ( fault , 11 ) ;
137
+ static PIPE_WRITE : AtomicUsize = AtomicUsize :: new ( 0 ) ;
138
+ PIPE_WRITE . store ( pipe [ 1 ] , Ordering :: SeqCst ) ;
137
139
138
- let pfd = PIPE_WRITE . load ( Ordering :: SeqCst ) ;
140
+ fn handle_segmentation_fault ( fault : usize ) {
141
+ core:: assert_eq!( fault, 11 ) ;
139
142
140
- // Dont worry about closing the file descriptors since they will
141
- // be auto closed by the parent.
142
- sys_write ( pfd, b"yes" ) . expect ( "failed to write to the pipe" ) ;
143
- sys_exit ( 0 ) ;
144
- }
143
+ let pfd = PIPE_WRITE . load ( Ordering :: SeqCst ) ;
145
144
146
- // Install the signal handler.
147
- let handler = SignalHandler :: Handle ( handle_segmentation_fault) ;
148
- let sigaction = SigAction :: new ( handler, 0 , SignalFlags :: empty ( ) ) ;
145
+ // Dont worry about closing the file descriptors since they will
146
+ // be auto closed by the parent.
147
+ sys_write ( pfd, b"yes" ) . expect ( "failed to write to the pipe" ) ;
148
+ sys_exit ( 0 ) ;
149
+ }
149
150
150
- sys_sigaction ( SIGSEGV , Some ( & sigaction) , None )
151
- . expect ( "failed to install the segmentation fault handler" ) ;
151
+ // Install the signal handler.
152
+ let handler = SignalHandler :: Handle ( handle_segmentation_fault) ;
153
+ let sigaction = SigAction :: new ( handler, 0 , SignalFlags :: empty ( ) ) ;
152
154
153
- // On fork the signal handler will be copied over to the child process.
154
- let child = sys_fork ( ) ? ;
155
+ sys_sigaction ( SIGSEGV , Some ( & sigaction ) , None )
156
+ . expect ( "failed to install the segmentation fault handler" ) ;
155
157
156
- if child == 0 {
157
- // Create a traditional page fault :^)
158
- unsafe {
159
- * ( 0xcafebabe as * mut usize ) = 69 ;
158
+ // On fork the signal handler will be copied over to the child process.
159
+ let child = sys_fork ( ) ?;
160
+
161
+ if child == 0 {
162
+ // Create a traditional page fault :^)
163
+ unsafe {
164
+ * ( 0xcafebabe as * mut usize ) = 69 ;
165
+ }
166
+ } else {
167
+ let mut buffer = [ 0 ; 3 ] ;
168
+ sys_read ( pipe[ 0 ] , & mut buffer) ?;
169
+
170
+ core:: assert_eq!( & buffer, b"yes" ) ;
160
171
}
161
- } else {
162
- let mut buffer = [ 0 ; 3 ] ;
163
- sys_read ( pipe[ 0 ] , & mut buffer) ?;
164
172
165
- core:: assert_eq!( & buffer, b"yes" ) ;
173
+ // Close the pipe
174
+ sys_close ( pipe[ 0 ] ) ?;
175
+ sys_close ( pipe[ 1 ] ) ?;
176
+ } else {
177
+ let mut status = 0 ;
178
+ sys_waitpid ( child, & mut status, 0 ) ?;
166
179
}
167
180
168
- // Close the pipe/
169
- sys_close ( pipe[ 0 ] ) ?;
170
- sys_close ( pipe[ 1 ] ) ?;
171
-
172
181
Ok ( ( ) )
173
182
}
174
183
0 commit comments