aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Konovalov <andreyknvl@google.com>2017-05-18 20:24:41 +0200
committerAndrey Konovalov <andreyknvl@google.com>2017-06-12 19:48:23 +0200
commited6891f2edb833a3ba06dc656bb8cfe371d0bc6a (patch)
tree1c03b260340fb340fcca8c3628915734dcdaf90e
parent19015af81522aa5d8aaa16d07306c48c3a61571e (diff)
csource: use tmp dir in repeat loop when tmpdir flag is on
-rw-r--r--csource/common.go10
-rw-r--r--executor/common.h10
2 files changed, 18 insertions, 2 deletions
diff --git a/csource/common.go b/csource/common.go
index 466e6de43..0d78bca5f 100644
--- a/csource/common.go
+++ b/csource/common.go
@@ -1760,7 +1760,7 @@ static int do_sandbox_namespace(int executor_pid, bool enable_tun)
}
#endif
-#if defined(SYZ_EXECUTOR) || (defined(SYZ_REPEAT) && defined(SYZ_WAIT_REPEAT))
+#if defined(SYZ_EXECUTOR) || (defined(SYZ_REPEAT) && defined(SYZ_WAIT_REPEAT) && defined(SYZ_USE_TMP_DIR))
static void remove_dir(const char* dir)
{
DIR* dp;
@@ -1841,7 +1841,9 @@ retry:
exitf("rmdir(%s) failed", dir);
}
}
+#endif
+#if defined(SYZ_EXECUTOR) || (defined(SYZ_REPEAT) && defined(SYZ_WAIT_REPEAT))
static uint64_t current_time_ms()
{
struct timespec ts;
@@ -1877,18 +1879,22 @@ void loop()
{
int iter;
for (iter = 0;; iter++) {
+#ifdef SYZ_USE_TMP_DIR
char cwdbuf[256];
sprintf(cwdbuf, "./%d", iter);
if (mkdir(cwdbuf, 0777))
fail("failed to mkdir");
+#endif
int pid = fork();
if (pid < 0)
fail("clone failed");
if (pid == 0) {
prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
setpgrp();
+#ifdef SYZ_USE_TMP_DIR
if (chdir(cwdbuf))
fail("failed to chdir");
+#endif
#ifdef SYZ_TUN_ENABLE
flush_tun();
#endif
@@ -1910,7 +1916,9 @@ void loop()
break;
}
}
+#ifdef SYZ_USE_TMP_DIR
remove_dir(cwdbuf);
+#endif
}
}
#else
diff --git a/executor/common.h b/executor/common.h
index ef2778f64..7f0bfb7f5 100644
--- a/executor/common.h
+++ b/executor/common.h
@@ -859,7 +859,7 @@ static int do_sandbox_namespace(int executor_pid, bool enable_tun)
}
#endif
-#if defined(SYZ_EXECUTOR) || (defined(SYZ_REPEAT) && defined(SYZ_WAIT_REPEAT))
+#if defined(SYZ_EXECUTOR) || (defined(SYZ_REPEAT) && defined(SYZ_WAIT_REPEAT) && defined(SYZ_USE_TMP_DIR))
// One does not simply remove a directory.
// There can be mounts, so we need to try to umount.
// Moreover, a mount can be mounted several times, so we need to try to umount in a loop.
@@ -948,7 +948,9 @@ retry:
exitf("rmdir(%s) failed", dir);
}
}
+#endif
+#if defined(SYZ_EXECUTOR) || (defined(SYZ_REPEAT) && defined(SYZ_WAIT_REPEAT))
static uint64_t current_time_ms()
{
struct timespec ts;
@@ -984,18 +986,22 @@ void loop()
{
int iter;
for (iter = 0;; iter++) {
+#ifdef SYZ_USE_TMP_DIR
char cwdbuf[256];
sprintf(cwdbuf, "./%d", iter);
if (mkdir(cwdbuf, 0777))
fail("failed to mkdir");
+#endif
int pid = fork();
if (pid < 0)
fail("clone failed");
if (pid == 0) {
prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
setpgrp();
+#ifdef SYZ_USE_TMP_DIR
if (chdir(cwdbuf))
fail("failed to chdir");
+#endif
#ifdef SYZ_TUN_ENABLE
flush_tun();
#endif
@@ -1017,7 +1023,9 @@ void loop()
break;
}
}
+#ifdef SYZ_USE_TMP_DIR
remove_dir(cwdbuf);
+#endif
}
}
#else