X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=common.cc;h=26f6d5d8cd42bdd28484c231a995b5fbe84c633b;hb=130a35155171503883aaf18e57f8957ce63d06e8;hp=a43064d527a03340d0f62d260b13b7638cf131f5;hpb=e52837077816345a2afa94b42195992a5871824c;p=model-checker.git diff --git a/common.cc b/common.cc index a43064d..26f6d5d 100644 --- a/common.cc +++ b/common.cc @@ -22,9 +22,7 @@ int model_out = STDOUT_FILENO; void print_trace(void) { #ifdef CONFIG_STACKTRACE - FILE *file = fdopen(model_out, "w"); - print_stacktrace(file); - fclose(file); + print_stacktrace(model_out); #else void *array[MAX_TRACE_LEN]; char **strings; @@ -42,11 +40,6 @@ void print_trace(void) #endif /* CONFIG_STACKTRACE */ } -void model_print_summary(void) -{ - model->print_summary(); -} - void assert_hook(void) { model_print("Add breakpoint to line %u in file %s.\n", __LINE__, __FILE__); @@ -88,10 +81,12 @@ static int fd_user_out; /**< @brief File descriptor from which to read user prog */ void redirect_output() { - int fd; - /* Save stdout for later use */ - model_out = dup(fileno(stdout)); + model_out = dup(STDOUT_FILENO); + if (model_out < 0) { + perror("dup"); + exit(EXIT_FAILURE); + } /* Redirect program output to a pipe */ int pipefd[2]; @@ -99,11 +94,17 @@ void redirect_output() perror("pipe"); exit(EXIT_FAILURE); } - fd = dup2(pipefd[1], fileno(stdout)); // STDOUT_FILENO + if (dup2(pipefd[1], STDOUT_FILENO) < 0) { + perror("dup2"); + exit(EXIT_FAILURE); + } close(pipefd[1]); /* Save the "read" side of the pipe for use later */ - fcntl(pipefd[0], F_SETFL, O_NONBLOCK); + if (fcntl(pipefd[0], F_SETFL, O_NONBLOCK) < 0) { + perror("fcntl"); + exit(EXIT_FAILURE); + } fd_user_out = pipefd[0]; } @@ -146,6 +147,8 @@ void print_program_output() { char buf[200]; + model_print("---- BEGIN PROGRAM OUTPUT ----\n"); + /* Gather all program output */ fflush(stdout); @@ -164,5 +167,7 @@ void print_program_output() ret -= res; } } + + model_print("---- END PROGRAM OUTPUT ----\n"); } #endif /* ! CONFIG_DEBUG */