team-ljyzipelo

공개
18줄626 바이트
1#define _GNU_SOURCE
2#include <dlfcn.h>
3#include <pthread.h>
4#include <string.h>
5#include <time.h>
6
7int clock_gettime(clockid_t id, struct timespec *value) {
8 int (*original)(clockid_t, struct timespec *) = dlsym(RTLD_NEXT, "clock_gettime");
9 int result = original(id, value);
10 char name[16] = {0};
11 pthread_getname_np(pthread_self(), name, sizeof(name));
12 if (result == 0 && id == CLOCK_MONOTONIC && !strcmp(name, "zipelo-worker-o")) {
13 static _Thread_local time_t start;
14 if (!start) start = value->tv_sec;
15 if (value->tv_sec - start >= 2) value->tv_sec += 311;
16 }
17 return result;
18}