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 { "help", no_argument, NULL, 'h' },
43 int timeout = DEFAULT_TIMEOUT;
44 struct udev_queue *udev_queue = NULL;
48 dbg(udev, "version %s\n", VERSION);
54 option = getopt_long(argc, argv, "t:h", options, NULL);
60 seconds = atoi(optarg);
64 fprintf(stderr, "invalid timeout value\n");
65 dbg(udev, "timeout=%i\n", timeout);
68 printf("Usage: udevadm settle [--help] [--timeout=<seconds>]\n\n");
73 udev_queue = udev_queue_new(udev);
74 if (udev_queue == NULL)
76 loop = timeout * LOOP_PER_SECOND;
78 if (udev_queue_get_queue_is_empty(udev_queue))
80 usleep(1000 * 1000 / LOOP_PER_SECOND);
83 struct udev_list_entry *list_entry;
85 info(udev, "timeout waiting for udev queue\n");
86 printf("\ndevadm settle timeout of %i seconds reached, the event queue contains:\n", timeout);
87 udev_list_entry_foreach(list_entry, udev_queue_get_queued_list_entry(udev_queue))
88 printf(" '%s' [%s]\n",
89 udev_list_entry_get_name(list_entry),
90 udev_list_entry_get_value(list_entry));
94 udev_queue_unref(udev_queue);