Skip to content

Commit bf829df

Browse files
committed
More messages.
1 parent fbfa67c commit bf829df

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

runtime/process-posix.c

+14-12
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ void obtain_lock (char* ctxt) {
2323
exit(-1);
2424
}
2525
locked = 1;
26+
printf("Obtained lock (%s).\n", ctxt);
2627
}
2728

2829
void release_lock (char* ctxt) {
@@ -31,6 +32,7 @@ void release_lock (char* ctxt) {
3132
exit(-1);
3233
}
3334
locked = 0;
35+
printf("Released lock (%s).\n", ctxt);
3436
}
3537

3638
//============================================================
@@ -256,8 +258,8 @@ void install_autoreaping_sigchld_handler () {
256258

257259
//Blocks the SIGCHILD signal by updating the signal mask.
258260
//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);
261263

262264
//Create signal mask containing only SIGCHLD.
263265
sigset_t sigchld_mask;
@@ -291,10 +293,10 @@ static void suspend_until_sigchild () {
291293

292294
//Restore the signal mask to the given mask.
293295
//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) {
295297
if(sigprocmask(SIG_SETMASK, old_mask, NULL))
296298
exit_with_error();
297-
release_lock("restore_signal_mask");
299+
release_lock(ctxt);
298300
}
299301

300302
//============================================================
@@ -323,7 +325,7 @@ stz_int retrieve_process_state (Process* process,
323325
stz_int wait_for_termination){
324326

325327
//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");
327329

328330
//Read the current status code of the process.
329331
stz_int status = process->status->status_code;
@@ -342,7 +344,7 @@ stz_int retrieve_process_state (Process* process,
342344
*s = make_process_state(status);
343345

344346
//End Block SIGCHLD.
345-
restore_signal_mask(&old_signal_mask);
347+
restore_signal_mask(&old_signal_mask, "retrieve_process_state");
346348

347349
//Return 0 to indicate success.
348350
//TODO: In this implementation failures halt the program
@@ -369,7 +371,7 @@ stz_int launch_process(stz_byte* file, stz_byte** argvs,
369371
stz_int input, stz_int output, stz_int error,
370372
stz_byte* working_dir, stz_byte** env_vars, Process* process) {
371373
//block sigchld
372-
sigset_t old_signal_mask = block_sigchild();
374+
sigset_t old_signal_mask = block_sigchild("launch_process");
373375

374376
//Compute which pipes to create for the process.
375377
//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,
481483
// Perform cleanup and return -1 to indicate error.
482484
return_error: {
483485
posix_spawn_file_actions_destroy(&actions);
484-
restore_signal_mask(&old_signal_mask);
486+
restore_signal_mask(&old_signal_mask, "launch_process");
485487
return -1;
486488
}
487489

488490
// Perform cleanup and return 0 to indicate success.
489491
return_success: {
490492
posix_spawn_file_actions_destroy(&actions);
491-
restore_signal_mask(&old_signal_mask);
493+
restore_signal_mask(&old_signal_mask, "launch_process");
492494
return 0;
493495
}
494496
}
@@ -531,7 +533,7 @@ stz_int launch_process(stz_byte* file, stz_byte** argvs, stz_int input,
531533
if(pid > 0) {
532534

533535
//Block SIGCHLD until setup is finished
534-
sigset_t old_signal_mask = block_sigchild();
536+
sigset_t old_signal_mask = block_sigchild("launch_process");
535537

536538
//Set up the pipes in the parent process.
537539
FILE* fin = NULL;
@@ -568,13 +570,13 @@ stz_int launch_process(stz_byte* file, stz_byte** argvs, stz_int input,
568570

569571
//Perform cleanup and return -1 to indicate error.
570572
return_error: {
571-
restore_signal_mask(&old_signal_mask);
573+
restore_signal_mask(&old_signal_mask, "launch_process");
572574
return -1;
573575
}
574576

575577
//Perform cleanup and return 0 to indicate success.
576578
return_success: {
577-
restore_signal_mask(&old_signal_mask);
579+
restore_signal_mask(&old_signal_mask, "launch_process");
578580
return 0;
579581
}
580582
}

0 commit comments

Comments
 (0)