team-ljyzipelo

공개
28줄772 바이트
1#define _GNU_SOURCE
2#include <dlfcn.h>
3#include <stdatomic.h>
4#include <stdlib.h>
5#include <string.h>
6#include <time.h>
7#include <unistd.h>
8
9static atomic_long elapsed;
10
11int clock_gettime(clockid_t id, struct timespec *value) {
12 int (*original)(clockid_t, struct timespec *) = dlsym(RTLD_NEXT, "clock_gettime");
13 int result = original(id, value);
14 if (result == 0 && id == CLOCK_MONOTONIC) {
15 value->tv_sec += atomic_load(&elapsed);
16 }
17 return result;
18}
19
20int fsync(int fd) {
21 int (*original)(int) = dlsym(RTLD_NEXT, "fsync");
22 int result = original(fd);
23 if (result == 0) {
24 const char *mode = getenv("ZIPELO_TEST_FAULT");
25 atomic_fetch_add(&elapsed, mode && !strcmp(mode, "clock-stall") ? 60 : 10);
26 }
27 return result;
28}