]> mj.ucw.cz Git - eval.git/blobdiff - box/box.c
Oops, there was a typo in the previous patch.
[eval.git] / box / box.c
index 09f7fe4c8c577bd0503201b6763f3a8442ce1400..1394a85d5f62d95b6d581d48d4ca14acd2a2a519 100644 (file)
--- a/box/box.c
+++ b/box/box.c
@@ -94,7 +94,6 @@ final_stats(struct rusage *rus)
   timeradd(&rus->ru_utime, &rus->ru_stime, &total);
   total_ms = total.tv_sec*1000 + total.tv_usec/1000;
   gettimeofday(&now, NULL);
-  // FIXME: We are not guaranteed to have start_time always initialized
   timersub(&now, &start_time, &wall);
   wall_ms = wall.tv_sec*1000 + wall.tv_usec/1000;
 
@@ -134,6 +133,7 @@ flush_line(void)
   partial_line = 0;
 }
 
+/* Report an error of the sandbox itself */
 static void NONRET __attribute__((format(printf,1,2)))
 die(char *msg, ...)
 {
@@ -148,6 +148,7 @@ die(char *msg, ...)
   box_exit(2);
 }
 
+/* Report an error of the program inside the sandbox */
 static void NONRET __attribute__((format(printf,1,2)))
 err(char *msg, ...)
 {
@@ -167,6 +168,7 @@ err(char *msg, ...)
   box_exit(1);
 }
 
+/* Write a message, but only if in verbose mode */
 static void __attribute__((format(printf,1,2)))
 msg(char *msg, ...)
 {
@@ -260,12 +262,14 @@ static unsigned char syscall_action[NUM_ACTIONS] = {
     S(fcntl) = A_YES,
     S(fcntl64) = A_YES,
     S(mmap) = A_YES,
+    S(mmap2) = A_YES,
     S(munmap) = A_YES,
     S(ioctl) = A_YES,
     S(uname) = A_YES,
     S(gettid) = A_YES,
     S(set_thread_area) = A_YES,
     S(get_thread_area) = A_YES,
+    S(set_tid_address) = A_YES,
     S(exit_group) = A_YES,
 
     // Syscalls permitted only in liberal mode
@@ -305,7 +309,6 @@ static unsigned char syscall_action[NUM_ACTIONS] = {
     S(rt_sigtimedwait) = A_YES | A_LIBERAL,
     S(rt_sigqueueinfo) = A_YES | A_LIBERAL,
     S(rt_sigsuspend) = A_YES | A_LIBERAL,
-    S(mmap2) = A_YES | A_LIBERAL,
     S(_sysctl) = A_YES | A_LIBERAL,
 #undef S
 };
@@ -799,11 +802,18 @@ boxkeeper(void)
        {
          box_pid = 0;
          final_stats(&rus);
-         // FIXME: If the process has exited before being ptraced, signal an internal error
          if (WEXITSTATUS(stat))
            {
-             meta_printf("exitcode:%d\n", WEXITSTATUS(stat));
-             err("RE: Exited with error status %d", WEXITSTATUS(stat));
+             if (syscall_count)
+               {
+                 meta_printf("exitcode:%d\n", WEXITSTATUS(stat));
+                 err("RE: Exited with error status %d", WEXITSTATUS(stat));
+               }
+             else
+               {
+                 // Internal error happened inside the child process and it has been already reported.
+                 box_exit(2);
+               }
            }
          if (timeout && total_ms > timeout)
            err("TO: Time limit exceeded");