summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@vrfy.org>2009-03-11 15:06:14 +0100
committerKay Sievers <kay.sievers@vrfy.org>2009-03-11 15:06:14 +0100
commitc2c24d4d3c8f83c5f4507bb13ba6c989f9d6ea45 (patch)
tree86af01aa6ad167c180d4161371ad605a244f0a74
parent89d080c3aedacadfb0b1022e101957998d4cdaf1 (diff)
udevadm: settle - use timeout signal, instead of loop counter
-rw-r--r--udev/udevadm-settle.c32
1 files changed, 27 insertions, 5 deletions
diff --git a/udev/udevadm-settle.c b/udev/udevadm-settle.c
index f9e6415a00..54f905bf6f 100644
--- a/udev/udevadm-settle.c
+++ b/udev/udevadm-settle.c
@@ -25,6 +25,7 @@
#include <fcntl.h>
#include <syslog.h>
#include <getopt.h>
+#include <signal.h>
#include <sys/stat.h>
#include <sys/types.h>
@@ -33,6 +34,16 @@
#define DEFAULT_TIMEOUT 180
#define LOOP_PER_SECOND 20
+static int volatile is_timeout;
+
+static void asmlinkage sig_handler(int signum)
+{
+ switch (signum) {
+ case SIGALRM:
+ is_timeout = 1;
+ }
+}
+
int udevadm_settle(struct udev *udev, int argc, char *argv[])
{
static const struct option options[] = {
@@ -45,14 +56,21 @@ int udevadm_settle(struct udev *udev, int argc, char *argv[])
};
unsigned long long start = 0;
unsigned long long end = 0;
- int timeout = DEFAULT_TIMEOUT;
int quiet = 0;
+ int timeout = 0;
+ struct sigaction act;
struct udev_queue *udev_queue = NULL;
- int loop;
int rc = 0;
dbg(udev, "version %s\n", VERSION);
+ /* set signal handlers */
+ memset(&act, 0x00, sizeof(act));
+ act.sa_handler = (void (*)(int)) sig_handler;
+ sigemptyset (&act.sa_mask);
+ act.sa_flags = 0;
+ sigaction(SIGALRM, &act, NULL);
+
while (1) {
int option;
int seconds;
@@ -90,10 +108,14 @@ int udevadm_settle(struct udev *udev, int argc, char *argv[])
}
}
+ if (timeout > 0)
+ alarm(timeout);
+ else
+ alarm(DEFAULT_TIMEOUT);
+
udev_queue = udev_queue_new(udev);
if (udev_queue == NULL)
goto exit;
- loop = timeout * LOOP_PER_SECOND;
if (start > 0) {
unsigned long long kernel_seq;
@@ -126,7 +148,7 @@ int udevadm_settle(struct udev *udev, int argc, char *argv[])
}
}
- while (loop--) {
+ while (!is_timeout) {
/* exit if queue is empty */
if (udev_queue_get_queue_is_empty(udev_queue))
break;
@@ -149,7 +171,7 @@ int udevadm_settle(struct udev *udev, int argc, char *argv[])
}
/* if we reached the timeout, print the list of remaining events */
- if (loop <= 0) {
+ if (is_timeout) {
struct udev_list_entry *list_entry;
if (!quiet) {