6 #include <libubox/uloop.h>
11 char *hotplug_cmd_path = DEFAULT_HOTPLUG_PATH;
12 static struct interface *current;
13 static enum interface_event current_ev;
14 static struct list_head pending = LIST_HEAD_INIT(pending);
16 static void task_complete(struct uloop_process *proc, int ret);
17 static struct uloop_process task = {
22 run_cmd(const char *ifname, bool up)
29 return task_complete(NULL, -1);
33 uloop_process_add(&task);
37 setenv("ACTION", up ? "ifup" : "ifdown", 1);
38 setenv("INTERFACE", ifname, 1);
39 argv[0] = hotplug_cmd_path;
42 execvp(argv[0], argv);
49 if (list_empty(&pending))
52 current = list_first_entry(&pending, struct interface, hotplug_list);
53 current_ev = current->hotplug_ev;
54 list_del_init(¤t->hotplug_list);
56 D(SYSTEM, "Call hotplug handler for interface '%s'\n", current->name);
57 run_cmd(current->name, current_ev == IFEV_UP);
61 task_complete(struct uloop_process *proc, int ret)
64 D(SYSTEM, "Complete hotplug handler for interface '%s'\n", current->name);
70 * Queue an interface for an up/down event.
71 * An interface can only have one event in the queue and one
72 * event waiting for completion.
73 * When queueing an event that is the same as the one waiting for
74 * completion, remove the interface from the queue
77 interface_queue_event(struct interface *iface, enum interface_event ev)
79 enum interface_event last_ev;
81 D(SYSTEM, "Queue hotplug handler for interface '%s'\n", iface->name);
85 last_ev = iface->hotplug_ev;
87 iface->hotplug_ev = ev;
88 if (last_ev == ev && !list_empty(&iface->hotplug_list))
89 list_del(&iface->hotplug_list);
90 else if (last_ev != ev && list_empty(&iface->hotplug_list))
91 list_add(&iface->hotplug_list, &pending);
93 if (!task.pending && !current)
98 interface_dequeue_event(struct interface *iface)
100 if (iface == current)
103 if (!list_empty(&iface->hotplug_list))
104 list_del_init(&iface->hotplug_list);