Switch from pipes to temporary file to store program output to get rid length limits.
authorroot <root@dw-6.eecs.uci.edu>
Thu, 1 Aug 2019 06:12:32 +0000 (23:12 -0700)
committerroot <root@dw-6.eecs.uci.edu>
Thu, 1 Aug 2019 06:20:53 +0000 (23:20 -0700)
common.cc
common.mk
main.cc

index 904a298e9070327100e968daf55573fc25afcbf4..8bef5194201c59f3ee3ff16bf87e1dbaa18a3319 100644 (file)
--- a/common.cc
+++ b/common.cc
@@ -79,6 +79,8 @@ static int fd_user_out;       /**< @brief File descriptor from which to read user prog
  *
  * This function should only be called once.
  */
+char filename[256];
+
 void redirect_output()
 {
        /* Save stdout for later use */
@@ -87,25 +89,13 @@ void redirect_output()
                perror("dup");
                exit(EXIT_FAILURE);
        }
-
-       /* Redirect program output to a pipe */
-       int pipefd[2];
-       if (pipe(pipefd) < 0) {
-               perror("pipe");
-               exit(EXIT_FAILURE);
-       }
-       if (dup2(pipefd[1], STDOUT_FILENO) < 0) {
+       snprintf_(filename, sizeof(filename), "C11FuzzerTmp%d", getpid());
+       fd_user_out = open(filename, O_CREAT | O_TRUNC| O_RDWR, S_IRWXU);
+       if (dup2(fd_user_out, STDOUT_FILENO) < 0) {
                perror("dup2");
                exit(EXIT_FAILURE);
        }
-       close(pipefd[1]);
 
-       /* Save the "read" side of the pipe for use later */
-       if (fcntl(pipefd[0], F_SETFL, O_NONBLOCK) < 0) {
-               perror("fcntl");
-               exit(EXIT_FAILURE);
-       }
-       fd_user_out = pipefd[0];
 }
 
 /**
@@ -138,8 +128,8 @@ static ssize_t read_to_buf(int fd, char *buf, size_t maxlen)
 void clear_program_output()
 {
        fflush(stdout);
-       char buf[200];
-       while (read_to_buf(fd_user_out, buf, sizeof(buf))) ;
+       close(fd_user_out);
+       unlink(filename);
 }
 
 /** @brief Print out any pending program output */
@@ -152,6 +142,7 @@ void print_program_output()
        /* Gather all program output */
        fflush(stdout);
 
+       lseek(fd_user_out, 0, SEEK_SET);
        /* Read program output pipe and write to (real) stdout */
        ssize_t ret;
        while (1) {
@@ -168,6 +159,9 @@ void print_program_output()
                }
        }
 
+       close(fd_user_out);
+       unlink(filename);
+
        model_print("---- END PROGRAM OUTPUT   ----\n");
 }
 #endif /* ! CONFIG_DEBUG */
index aca498c7dffc8ab426fea26f84abc3b76e9f3e4f..bc068dff1fb1e559b4aafb9b01881028c28b615a 100644 (file)
--- a/common.mk
+++ b/common.mk
@@ -8,7 +8,7 @@ UNAME := $(shell uname)
 LIB_NAME := model
 LIB_SO := lib$(LIB_NAME).so
 
-CPPFLAGS += -Wall -g -O0
+CPPFLAGS += -Wall -g -O3
 
 # Mac OSX options
 ifeq ($(UNAME), Darwin)
diff --git a/main.cc b/main.cc
index 53495072e32d3c75f855d5cc82582a8dfc8e112b..590a41d27f33c07118592912fc73f582a4624050 100644 (file)
--- a/main.cc
+++ b/main.cc
@@ -189,8 +189,6 @@ int main(int argc, char **argv)
                                 "Distributed under the GPLv2\n"
                                 "Written by Weiyu Luo, Brian Norris, and Brian Demsky\n\n");
 
-       /* Configure output redirection for the model-checker */
-       redirect_output();
 
        //Initialize snapshotting library and model checker object
        if (!model) {
@@ -199,6 +197,9 @@ int main(int argc, char **argv)
                model->startChecker();
        }
 
+       /* Configure output redirection for the model-checker */
+       redirect_output();
+
        register_plugins();
 
        //Parse command line options