Skip to content

Commit

Permalink
executor: use /proc/thread-self/fail-nth instead of /proc/self/task/%…
Browse files Browse the repository at this point in the history
…d/fail-nth

Makes code slightly simpler.
  • Loading branch information
dvyukov committed Nov 27, 2017
1 parent 4bd70f8 commit 01b82d4
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions executor/common_linux.h
Expand Up @@ -921,15 +921,14 @@ static void remove_dir(const char* dir)
static int inject_fault(int nth)
{
int fd;
char buf[128];
char buf[16];

sprintf(buf, "/proc/self/task/%d/fail-nth", (int)syscall(SYS_gettid));
fd = open(buf, O_RDWR);
fd = open("/proc/thread-self/fail-nth", O_RDWR);
if (fd == -1)
fail("failed to open /proc/self/task/tid/fail-nth");
fail("failed to open /proc/thread-self/fail-nth");
sprintf(buf, "%d", nth + 1);
if (write(fd, buf, strlen(buf)) != (ssize_t)strlen(buf))
fail("failed to write /proc/self/task/tid/fail-nth");
fail("failed to write /proc/thread-self/fail-nth");
return fd;
}
#endif
Expand All @@ -940,11 +939,11 @@ static int fault_injected(int fail_fd)
char buf[16];
int n = read(fail_fd, buf, sizeof(buf) - 1);
if (n <= 0)
fail("failed to read /proc/self/task/tid/fail-nth");
fail("failed to read /proc/thread-self/fail-nth");
int res = n == 2 && buf[0] == '0' && buf[1] == '\n';
buf[0] = '0';
if (write(fail_fd, buf, 1) != 1)
fail("failed to write /proc/self/task/tid/fail-nth");
fail("failed to write /proc/thread-self/fail-nth");
close(fail_fd);
return res;
}
Expand Down

0 comments on commit 01b82d4

Please sign in to comment.