udevadm-settle.c revision 0736455b1186c9515e0f093e1e686e684d225787
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * Copyright (C) 2006-2009 Kay Sievers <kay@vrfy.org>
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * Copyright (C) 2009 Canonical Ltd.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * Copyright (C) 2009 Scott James Remnant <scott@netsplit.com>
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * This program is free software: you can redistribute it and/or modify
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * it under the terms of the GNU General Public License as published by
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * the Free Software Foundation, either version 2 of the License, or
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * (at your option) any later version.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * This program is distributed in the hope that it will be useful,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * but WITHOUT ANY WARRANTY; without even the implied warranty of
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * GNU General Public License for more details.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * You should have received a copy of the GNU General Public License
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * along with this program. If not, see <http://www.gnu.org/licenses/>.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic void help(void) {
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering "Wait for pending udev events.\n\n"
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering " -h --help Show this help\n"
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering " --version Show package version\n"
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering " -t --timeout=SECONDS Maximum time to wait for events\n"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " -E --exit-if-exists=FILE Stop waiting if file exists\n"
ad867662936a4c7ab2c7116d804c272338801231Lennart Poetteringstatic int adm_settle(struct udev *udev, int argc, char *argv[]) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering { "timeout", required_argument, NULL, 't' },
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering { "exit-if-exists", required_argument, NULL, 'E' },
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering { "seq-start", required_argument, NULL, 's' }, /* removed */
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering { "seq-end", required_argument, NULL, 'e' }, /* removed */
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering { "quiet", no_argument, NULL, 'q' }, /* removed */
818f766b12e025683cf4fed12b3da2a025bb0b31Lennart Poettering while ((c = getopt_long(argc, argv, "t:E:hs:e:q", options, NULL)) >= 0) {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering fprintf(stderr, "Invalid timeout value '%s': %s\n",
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering log_info("Option -%c no longer supported.", c);
8ba9fd9cee0eef572f7b3ed7a8c3ed31160e93d3Lennart Poettering fprintf(stderr, "Extraneous argument: '%s'\n", argv[optind]);
8ba9fd9cee0eef572f7b3ed7a8c3ed31160e93d3Lennart Poettering deadline = now(CLOCK_MONOTONIC) + timeout * USEC_PER_SEC;
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering /* guarantee that the udev daemon isn't pre-processing */
8ba9fd9cee0eef572f7b3ed7a8c3ed31160e93d3Lennart Poettering if (udev_ctrl_send_ping(uctrl, timeout) < 0) {
8ba9fd9cee0eef572f7b3ed7a8c3ed31160e93d3Lennart Poettering log_debug("queue is empty, nothing to watch");
8ba9fd9cee0eef572f7b3ed7a8c3ed31160e93d3Lennart Poettering if (exists && access(exists, F_OK) >= 0) {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering /* exit if queue is empty */
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (udev_queue_get_queue_is_empty(queue)) {
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering if (timeout > 0 && now(CLOCK_MONOTONIC) >= deadline)
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering /* wake up when queue is empty */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (poll(pfd, 1, MSEC_PER_SEC) > 0 && pfd[0].revents & POLLIN)