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
(#1899402) detect initial timer state from serialized data #165
Merged
systemd-rhel-bot
merged 2 commits into
redhat-plumbers:master
from
dtardon:bz1899402-timer-reload
Jun 22, 2021
Merged
(#1899402) detect initial timer state from serialized data #165
systemd-rhel-bot
merged 2 commits into
redhat-plumbers:master
from
dtardon:bz1899402-timer-reload
Jun 22, 2021
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
… is changed There is difference between time set by the user and real elapsed time because of accuracy feature. If you change the system date(or time) between these times, the timer drops. You can easily reproduce it with the following command. ----------------------------------------------------------- $ systemd-run --on-active=3s ls; sleep 3; date -s "`date`" ----------------------------------------------------------- In the following command, the problem is rarely reproduced. But it exists. --------------------------------------------------------------------------------------------- $ systemd-run --on-active=3s --timer-property=AccuracySec=1us ls ; sleep 1; date -s "`date`" --------------------------------------------------------------------------------------------- Note : Global AccuracySec value. ---------------------------------------------------------------------- $ cat /etc/systemd/system.conf DefaultTimerAccuracySec=1min ---------------------------------------------------------------------- (cherry picked from commit fee04d7) Related: #1899402
We keep a mark whether a single-shot timer was triggered in the caller's variable initial. When such a timer elapses while we are serializing/deserializing the inner state, we consider the timer incorrectly as elapsed and don't trigger it later. This patch exploits last_trigger timestamp that we already serialize, hence we can eliminate the argument initial completely. A reproducer for OnBootSec= timers: cat >repro.c <<EOD /* * Compile: gcc repro.c -o repro * Run: ./repro */ #include <errno.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <sys/stat.h> #include <sys/types.h> #include <time.h> #include <unistd.h> int main(int argc, char *argv[]) { char command[1024]; int pause; struct timespec now; while (1) { usleep(rand() % 200000); // prevent periodic repeats clock_gettime(CLOCK_MONOTONIC, &now); printf("%i\n", now.tv_sec); system("rm -f $PWD/mark"); snprintf(command, 1024, "systemd-run --user --on-boot=%i --timer-property=AccuracySec=100ms " "touch $PWD/mark", now.tv_sec + 1); system(command); system("systemctl --user list-timers"); pause = (1000000000 - now.tv_nsec)/1000 - 70000; // fiddle to hit the middle of reloading usleep(pause > 0 ? pause : 0); system("systemctl --user daemon-reload"); sync(); sleep(2); if (open("./mark", 0) < 0) if (errno == ENOENT) { printf("mark file does not exist\n"); break; } } return 0; } EOD (cherry picked from commit aa1f95d) Resolves: #1899402
systemd-rhel-bot
changed the title
detect initial timer state from serialized data
(#1899402) detect initial timer state from serialized data
Apr 1, 2021
msekletar
reviewed
Jun 16, 2021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
msekletar
approved these changes
Jun 16, 2021
systemd-rhel-bot
removed
pr/needs-review
Formerly needs-review
tracker/unapproved
Formerly needs-acks
labels
Jun 16, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.