summaryrefslogtreecommitdiff
path: root/src/udev/udevd.c
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-09-13 08:52:01 -0400
committerAnthony G. Basile <blueness@gentoo.org>2014-09-13 08:52:01 -0400
commit7ac0491cdb6e7e970d0721824fdea2f675272192 (patch)
tree0b2a5b3efb2dcbaef7d8c879cd7692f2b9d92d87 /src/udev/udevd.c
parentffdc02f45bcc973249406b2c9bd996f8b27fa2a5 (diff)
udev: timeout - warn after a third of the timeout before killing
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'src/udev/udevd.c')
-rw-r--r--src/udev/udevd.c40
1 files changed, 27 insertions, 13 deletions
diff --git a/src/udev/udevd.c b/src/udev/udevd.c
index 68fd34bfdf..171bf83d05 100644
--- a/src/udev/udevd.c
+++ b/src/udev/udevd.c
@@ -74,6 +74,7 @@ static int children;
static int children_max;
static int exec_delay;
static usec_t event_timeout_usec = 180 * USEC_PER_SEC;
+static usec_t event_timeout_warn_usec = 180 * USEC_PER_SEC / 3;
static sigset_t sigmask_orig;
static UDEV_LIST(event_list);
static UDEV_LIST(worker_list);
@@ -124,6 +125,7 @@ struct worker {
enum worker_state state;
struct event *event;
usec_t event_start_usec;
+ bool event_warned;
};
/* passed from worker to main process */
@@ -302,9 +304,9 @@ static void worker_new(struct event *event) {
}
/* apply rules, create node, symlinks */
- udev_event_execute_rules(udev_event, event_timeout_usec, rules, &sigmask_orig);
+ udev_event_execute_rules(udev_event, event_timeout_usec, event_timeout_warn_usec, rules, &sigmask_orig);
- udev_event_execute_run(udev_event, event_timeout_usec, &sigmask_orig);
+ udev_event_execute_run(udev_event, event_timeout_usec, event_timeout_warn_usec, &sigmask_orig);
/* apply/restore inotify watch */
if (udev_event->inotify_watch) {
@@ -395,6 +397,7 @@ out:
worker->pid = pid;
worker->state = WORKER_RUNNING;
worker->event_start_usec = now(CLOCK_MONOTONIC);
+ worker->event_warned = false;
worker->event = event;
event->state = EVENT_RUNNING;
udev_list_node_append(&worker->node, &worker_list);
@@ -425,6 +428,7 @@ static void event_run(struct event *event) {
worker->event = event;
worker->state = WORKER_RUNNING;
worker->event_start_usec = now(CLOCK_MONOTONIC);
+ worker->event_warned = false;
event->state = EVENT_RUNNING;
return;
}
@@ -1013,6 +1017,7 @@ static void kernel_cmdline_options(struct udev *udev) {
exec_delay = strtoul(opt + 16, NULL, 0);
} else if (startswith(opt, "udev.event-timeout=")) {
event_timeout_usec = strtoul(opt + 16, NULL, 0) * USEC_PER_SEC;
+ event_timeout_warn_usec = (event_timeout_usec / 3) ? : 1;
}
free(s);
@@ -1074,6 +1079,7 @@ int main(int argc, char *argv[]) {
break;
case 't':
event_timeout_usec = strtoul(optarg, NULL, 0) * USEC_PER_SEC;
+ event_timeout_warn_usec = (event_timeout_usec / 3) ? : 1;
break;
case 'D':
debug = true;
@@ -1402,21 +1408,29 @@ int main(int argc, char *argv[]) {
/* check for hanging events */
udev_list_node_foreach(loop, &worker_list) {
struct worker *worker = node_to_worker(loop);
+ usec_t ts;
if (worker->state != WORKER_RUNNING)
continue;
- if ((now(CLOCK_MONOTONIC) - worker->event_start_usec) > event_timeout_usec) {
- log_error("worker [%u] %s timeout; kill it", worker->pid, worker->event->devpath);
- kill(worker->pid, SIGKILL);
- worker->state = WORKER_KILLED;
-
- /* drop reference taken for state 'running' */
- worker_unref(worker);
- log_error("seq %llu '%s' killed", udev_device_get_seqnum(worker->event->dev), worker->event->devpath);
- worker->event->exitcode = -64;
- event_queue_delete(worker->event);
- worker->event = NULL;
+ ts = now(CLOCK_MONOTONIC);
+
+ if ((ts - worker->event_start_usec) > event_timeout_warn_usec) {
+ if ((ts - worker->event_start_usec) > event_timeout_usec) {
+ log_error("worker [%u] %s timeout; kill it", worker->pid, worker->event->devpath);
+ kill(worker->pid, SIGKILL);
+ worker->state = WORKER_KILLED;
+
+ /* drop reference taken for state 'running' */
+ worker_unref(worker);
+ log_error("seq %llu '%s' killed", udev_device_get_seqnum(worker->event->dev), worker->event->devpath);
+ worker->event->exitcode = -64;
+ event_queue_delete(worker->event);
+ worker->event = NULL;
+ } else if (!worker->event_warned) {
+ log_warning("worker [%u] %s is taking a long time", worker->pid, worker->event->devpath);
+ worker->event_warned = true;
+ }
}
}