2 * Copyright (C) 2006-2008 Kay Sievers <kay@vrfy.org>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 #include <sys/types.h>
33 #define DEFAULT_TIMEOUT 180
34 #define LOOP_PER_SECOND 20
36 int udevadm_settle(struct udev *udev, int argc, char *argv[])
38 static const struct option options[] = {
39 { "timeout", required_argument, NULL, 't' },
40 { "quiet", no_argument, NULL, 'q' },
41 { "help", no_argument, NULL, 'h' },
44 int timeout = DEFAULT_TIMEOUT;
46 struct udev_queue *udev_queue = NULL;
50 dbg(udev, "version %s\n", VERSION);
56 option = getopt_long(argc, argv, "t:qh", options, NULL);
62 seconds = atoi(optarg);
66 fprintf(stderr, "invalid timeout value\n");
67 dbg(udev, "timeout=%i\n", timeout);
73 printf("Usage: udevadm settle [--help] [--timeout=<seconds>] [--quiet]\n\n");
78 udev_queue = udev_queue_new(udev);
79 if (udev_queue == NULL)
81 loop = timeout * LOOP_PER_SECOND;
83 if (udev_queue_get_queue_is_empty(udev_queue))
85 usleep(1000 * 1000 / LOOP_PER_SECOND);
88 struct udev_list_entry *list_entry;
91 info(udev, "timeout waiting for udev queue\n");
92 printf("\ndevadm settle timeout of %i seconds reached, the event queue contains:\n", timeout);
93 udev_list_entry_foreach(list_entry, udev_queue_get_queued_list_entry(udev_queue))
95 udev_list_entry_get_name(list_entry),
96 udev_list_entry_get_value(list_entry));
101 udev_queue_unref(udev_queue);