Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug/fix_alternative_timer #13

Merged
merged 1 commit into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ format:
find . -path ./packages -prune -o -name '*.[hc]' -print0 | xargs -0 -n 1 clang-format -i

install: /usr/local/lib/$(notdir $(SCR_SHARED_LIBRARY)) $(foreach file,$(SCR_ONLY_HEADER_FILES),/usr/local/include/scrutiny/$(notdir $(file)))
ldconfig

/usr/local/lib/$(notdir $(SCR_SHARED_LIBRARY)): $(SCR_SHARED_LIBRARY)
cp $< $@
ldconfig

/usr/local/include/scrutiny/%.h: include/scrutiny/%.h
@mkdir -p $(@D)
Expand Down
17 changes: 11 additions & 6 deletions src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,13 @@ waitForProcess(pid_t child, unsigned int timeout, int *status, bool *timed_out)

#else // no pidfd_open

#include <stdbool.h>
#include <time.h>
#ifdef CLOCK_MONOTONIC_COARSE
#define SCR_CLOCK_TYPE CLOCK_MONOTONIC_COARSE
#else
#define SCR_CLOCK_TYPE CLOCK_MONOTONIC
#endif

#define ONE_TENTH_SECOND 10000000

static bool
caughtSignal(void)
Expand All @@ -163,11 +168,11 @@ caughtSignal(void)
void
waitForProcess(pid_t child, unsigned int timeout, int *status, bool *timed_out)
{
struct timespec start_time, lapse = {.tv_nsec = 10000000};
struct timespec start_time, lapse = {.tv_nsec = ONE_TENTH_SECOND};

*timed_out = false;
if (timeout > 0) {
clock_gettime(CLOCK_MOOTONIC_COARSE, &start_time);
clock_gettime(SCR_CLOCK_TYPE, &start_time);
}

while (1) {
Expand All @@ -179,11 +184,11 @@ waitForProcess(pid_t child, unsigned int timeout, int *status, bool *timed_out)
return;
}

nanosleep(&spec, NULL);
nanosleep(&lapse, NULL);
if (timeout > 0 && !*timed_out) {
struct timespec now;

clock_gettime(CLOCK_MONOTONIC_COARSE, &now);
clock_gettime(SCR_CLOCK_TYPE, &now);
if (now.tv_sec - start_time.tv_sec >= timeout) {
*timed_out = true;
kill(child, SIGKILL);
Expand Down