@@ -23,6 +23,7 @@ void obtain_lock (char* ctxt) {
23
23
exit (-1 );
24
24
}
25
25
locked = 1 ;
26
+ printf ("Obtained lock (%s).\n" , ctxt );
26
27
}
27
28
28
29
void release_lock (char * ctxt ) {
@@ -31,6 +32,7 @@ void release_lock (char* ctxt) {
31
32
exit (-1 );
32
33
}
33
34
locked = 0 ;
35
+ printf ("Released lock (%s).\n" , ctxt );
34
36
}
35
37
36
38
//============================================================
@@ -256,8 +258,8 @@ void install_autoreaping_sigchld_handler () {
256
258
257
259
//Blocks the SIGCHILD signal by updating the signal mask.
258
260
//Returns the previous signal mask.
259
- static sigset_t block_sigchild () {
260
- obtain_lock ("block_sigchild" );
261
+ static sigset_t block_sigchild (char * ctxt ) {
262
+ obtain_lock (ctxt );
261
263
262
264
//Create signal mask containing only SIGCHLD.
263
265
sigset_t sigchld_mask ;
@@ -291,10 +293,10 @@ static void suspend_until_sigchild () {
291
293
292
294
//Restore the signal mask to the given mask.
293
295
//Exits program with error if unsuccessful.
294
- static void restore_signal_mask (sigset_t * old_mask ) {
296
+ static void restore_signal_mask (sigset_t * old_mask , char * ctxt ) {
295
297
if (sigprocmask (SIG_SETMASK , old_mask , NULL ))
296
298
exit_with_error ();
297
- release_lock ("restore_signal_mask" );
299
+ release_lock (ctxt );
298
300
}
299
301
300
302
//============================================================
@@ -323,7 +325,7 @@ stz_int retrieve_process_state (Process* process,
323
325
stz_int wait_for_termination ){
324
326
325
327
//Block SIGCHLD while we're reading the process state.
326
- sigset_t old_signal_mask = block_sigchild ();
328
+ sigset_t old_signal_mask = block_sigchild ("retrieve_process_state" );
327
329
328
330
//Read the current status code of the process.
329
331
stz_int status = process -> status -> status_code ;
@@ -342,7 +344,7 @@ stz_int retrieve_process_state (Process* process,
342
344
* s = make_process_state (status );
343
345
344
346
//End Block SIGCHLD.
345
- restore_signal_mask (& old_signal_mask );
347
+ restore_signal_mask (& old_signal_mask , "retrieve_process_state" );
346
348
347
349
//Return 0 to indicate success.
348
350
//TODO: In this implementation failures halt the program
@@ -369,7 +371,7 @@ stz_int launch_process(stz_byte* file, stz_byte** argvs,
369
371
stz_int input , stz_int output , stz_int error ,
370
372
stz_byte * working_dir , stz_byte * * env_vars , Process * process ) {
371
373
//block sigchld
372
- sigset_t old_signal_mask = block_sigchild ();
374
+ sigset_t old_signal_mask = block_sigchild ("launch_process" );
373
375
374
376
//Compute which pipes to create for the process.
375
377
//has_pipes[PROCESS_IN] = 1, indicates that a process input pipe
@@ -481,14 +483,14 @@ stz_int launch_process(stz_byte* file, stz_byte** argvs,
481
483
// Perform cleanup and return -1 to indicate error.
482
484
return_error : {
483
485
posix_spawn_file_actions_destroy (& actions );
484
- restore_signal_mask (& old_signal_mask );
486
+ restore_signal_mask (& old_signal_mask , "launch_process" );
485
487
return -1 ;
486
488
}
487
489
488
490
// Perform cleanup and return 0 to indicate success.
489
491
return_success : {
490
492
posix_spawn_file_actions_destroy (& actions );
491
- restore_signal_mask (& old_signal_mask );
493
+ restore_signal_mask (& old_signal_mask , "launch_process" );
492
494
return 0 ;
493
495
}
494
496
}
@@ -531,7 +533,7 @@ stz_int launch_process(stz_byte* file, stz_byte** argvs, stz_int input,
531
533
if (pid > 0 ) {
532
534
533
535
//Block SIGCHLD until setup is finished
534
- sigset_t old_signal_mask = block_sigchild ();
536
+ sigset_t old_signal_mask = block_sigchild ("launch_process" );
535
537
536
538
//Set up the pipes in the parent process.
537
539
FILE * fin = NULL ;
@@ -568,13 +570,13 @@ stz_int launch_process(stz_byte* file, stz_byte** argvs, stz_int input,
568
570
569
571
//Perform cleanup and return -1 to indicate error.
570
572
return_error : {
571
- restore_signal_mask (& old_signal_mask );
573
+ restore_signal_mask (& old_signal_mask , "launch_process" );
572
574
return -1 ;
573
575
}
574
576
575
577
//Perform cleanup and return 0 to indicate success.
576
578
return_success : {
577
- restore_signal_mask (& old_signal_mask );
579
+ restore_signal_mask (& old_signal_mask , "launch_process" );
578
580
return 0 ;
579
581
}
580
582
}
0 commit comments