/*
* Copyright (C) 2006-2008 Kay Sievers <kay@vrfy.org>
+ * Copyright (C) 2009 Canonical Ltd.
+ * Copyright (C) 2009 Scott James Remnant <scott@netsplit.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#define DEFAULT_TIMEOUT 180
#define LOOP_PER_SECOND 20
-static int volatile is_timeout;
+static volatile sig_atomic_t is_timeout;
-static void asmlinkage sig_handler(int signum)
+static void sig_handler(int signum)
{
switch (signum) {
case SIGALRM:
is_timeout = 1;
+ case SIGUSR1:
+ ;
}
}
/* set signal handlers */
memset(&act, 0x00, sizeof(act));
- act.sa_handler = (void (*)(int)) sig_handler;
+ act.sa_handler = sig_handler;
sigemptyset (&act.sa_mask);
act.sa_flags = 0;
sigaction(SIGALRM, &act, NULL);
+ sigaction(SIGUSR1, &act, NULL);
while (1) {
int option;
}
}
- while (!is_timeout) {
- /* exit if queue is empty */
- if (udev_queue_get_queue_is_empty(udev_queue))
- break;
+ /* guarantee that the udev daemon isn't pre-processing */
+ if (getuid() == 0) {
+ struct udev_ctrl *uctrl;
+
+ uctrl = udev_ctrl_new_from_socket(udev, UDEV_CTRL_SOCK_PATH);
+ if (uctrl != NULL) {
+ sigset_t mask, oldmask;
+
+ sigemptyset(&mask);
+ sigaddset(&mask, SIGUSR1);
+ sigaddset(&mask, SIGALRM);
+ sigprocmask(SIG_BLOCK, &mask, &oldmask);
+ if (udev_ctrl_send_settle(uctrl) > 0)
+ sigsuspend(&oldmask);
+ sigprocmask(SIG_SETMASK, &oldmask, NULL);
+ udev_ctrl_unref(uctrl);
+ }
+ }
- /* if asked for, wait for a specific sequence of events */
+ while (!is_timeout) {
if (start > 0) {
- unsigned long long seq;
- int finished;
-
- finished = 0;
- for (seq = start; seq <= end; seq++) {
- finished = udev_queue_get_seqnum_is_finished(udev_queue, seq);
- if (!finished)
- break;
- }
- if (finished)
+ /* if asked for, wait for a specific sequence of events */
+ if (udev_queue_get_seqnum_sequence_is_finished(udev_queue, start, end) == 1)
+ break;
+ } else {
+ /* exit if queue is empty */
+ if (udev_queue_get_queue_is_empty(udev_queue))
break;
}
+
usleep(1000 * 1000 / LOOP_PER_SECOND);
}