Skip to content

Commit

Permalink
Merge pull request wolfcw#400 from sveyret/shared-mem-sync
Browse files Browse the repository at this point in the history
Reset shared memory when start time is reset
  • Loading branch information
wolfcw authored Jun 20, 2022
2 parents b61fade + 431f09e commit be4e373
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/libfaketime.c
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,25 @@ static void next_time(struct timespec *tp, struct timespec *ticklen)
}
}

static void reset_time()
{
system_time_from_system(&ftpl_starttime);
if (shared_sem != NULL)
{
if (sem_wait(shared_sem) == -1)
{
perror("libfaketime: In reset_time(), sem_wait failed");
exit(1);
}
ft_shared->start_time = ftpl_starttime;
if (sem_post(shared_sem) == -1)
{
perror("libfaketime: In reset_time(), sem_post failed");
exit(1);
}
}
}


/*
* =======================================================================
Expand Down Expand Up @@ -2533,7 +2552,7 @@ static void parse_ft_string(const char *user_faked_time)

/* Reset starttime */
if (NULL == getenv("FAKETIME_DONT_RESET"))
system_time_from_system(&ftpl_starttime);
reset_time();
goto parse_modifiers;
break;

Expand Down Expand Up @@ -2561,7 +2580,7 @@ static void parse_ft_string(const char *user_faked_time)
}
}
if (NULL == getenv("FAKETIME_DONT_RESET"))
system_time_from_system(&ftpl_starttime);
reset_time();
goto parse_modifiers;
break;

Expand Down

0 comments on commit be4e373

Please sign in to comment.