+ struct hotplug_msg *loop_msg;
+ struct hotplug_msg *tmp_msg;
+ time_t msg_age = 0;
+
+ dbg("msg queue manager, next expected is %d", expected_seqnum);
+recheck:
+ list_for_each_entry_safe(loop_msg, tmp_msg, &msg_list, list) {
+ /* move event with expected sequence to the exec list */
+ if (loop_msg->seqnum == expected_seqnum) {
+ msg_move_exec(loop_msg);
+ continue;
+ }
+
+ /* move event with expired timeout to the exec list */
+ msg_age = time(NULL) - loop_msg->queue_time;
+ if (msg_age > EVENT_TIMEOUT_SEC-1) {
+ msg_move_exec(loop_msg);
+ goto recheck;
+ } else {
+ break;
+ }
+ }
+
+ msg_dump_queue();
+
+ if (list_empty(&msg_list) == 0) {
+ /* set timeout for remaining queued events */
+ struct itimerval itv = {{0, 0}, {EVENT_TIMEOUT_SEC - msg_age, 0}};
+ dbg("next event expires in %li seconds",
+ EVENT_TIMEOUT_SEC - msg_age);
+ setitimer(ITIMER_REAL, &itv, 0);