[systemd-devel] [PATCH] udev: settle should return immediately when timeout is 0
Andrei Borzenkov
arvidjaar at gmail.com
Sat Apr 11 23:45:06 PDT 2015
В Sat, 11 Apr 2015 23:31:05 +0300
Nir Soffer <nirsof at gmail.com> пишет:
> udevadm manual says:
>
> A value of 0 will check if the queue is empty and always return
> immediately.
>
> However, currently we ignore the deadline if the value is 0, and wait
> without any limit.
>
> Zero timeout behaved according to the documentation until commit
> ead7c62ab7 (udevadm: settle - kill alarm()). Looking at this patch, it
> seems that the behavior change was unintended.
>
> This patch restores the documented behavior.
> ---
> src/udev/udevadm-settle.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/src/udev/udevadm-settle.c b/src/udev/udevadm-settle.c
> index 2c84ada..0c9c1d9 100644
> --- a/src/udev/udevadm-settle.c
> +++ b/src/udev/udevadm-settle.c
> @@ -49,7 +49,7 @@ static int adm_settle(struct udev *udev, int argc, char *argv[]) {
> { "quiet", no_argument, NULL, 'q' }, /* removed */
> {}
> };
> - usec_t deadline;
> + usec_t deadline = 0;
This is redundant.
> const char *exists = NULL;
> unsigned int timeout = 120;
> struct pollfd pfd[1] = { {.fd = -1}, };
> @@ -99,7 +99,8 @@ static int adm_settle(struct udev *udev, int argc, char *argv[]) {
> return EXIT_FAILURE;
> }
>
> - deadline = now(CLOCK_MONOTONIC) + timeout * USEC_PER_SEC;
> + if (timeout != 0)
> + deadline = now(CLOCK_MONOTONIC) + timeout * USEC_PER_SEC;
>
And this.
> /* guarantee that the udev daemon isn't pre-processing */
> if (getuid() == 0) {
> @@ -142,7 +143,7 @@ static int adm_settle(struct udev *udev, int argc, char *argv[]) {
> break;
> }
>
> - if (timeout > 0 && now(CLOCK_MONOTONIC) >= deadline)
> + if (timeout == 0 || now(CLOCK_MONOTONIC) >= deadline)
Just remove "timeout > 0 && " condition. This will cause loop to always
exit after first iteration.
> break;
>
> /* wake up when queue is empty */
More information about the systemd-devel
mailing list