diff --git a/compiler-rt/lib/fuzzer/FuzzerUtilPosix.cpp b/compiler-rt/lib/fuzzer/FuzzerUtilPosix.cpp index 392c1e5be4eea..36a1122c9f7cc 100644 --- a/compiler-rt/lib/fuzzer/FuzzerUtilPosix.cpp +++ b/compiler-rt/lib/fuzzer/FuzzerUtilPosix.cpp @@ -104,14 +104,19 @@ bool ExecuteCommand(const Command &Cmd, std::string *CmdOutput) { } void SetTimer(int Seconds) { - struct itimerval T { + timer_t TimerId; + struct itimerspec T { {Seconds, 0}, { Seconds, 0 } }; - if (setitimer(ITIMER_REAL, &T, nullptr)) { - Printf("libFuzzer: setitimer failed with %d\n", errno); + SetSigaction(SIGALRM, AlarmHandler); + if (timer_create(CLOCK_REALTIME, nullptr, &TimerId) == -1) { + Printf("libFuzzer: timer_create failed with %d\n", errno); + exit(1); + } + if (timer_settime(TimerId, 0, &T, nullptr) == -1) { + Printf("libFuzzer: timer_settime failed with %d\n", errno); exit(1); } - SetSigaction(SIGALRM, AlarmHandler); } void SetSignalHandler(const FuzzingOptions& Options) {