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);
55 run_cmd(current->name, current_ev == IFEV_UP);
59 task_complete(struct uloop_process *proc, int ret)
66 * Queue an interface for an up/down event.
67 * An interface can only have one event in the queue and one
68 * event waiting for completion.
69 * When queueing an event that is the same as the one waiting for
70 * completion, remove the interface from the queue
73 interface_queue_event(struct interface *iface, enum interface_event ev)
75 enum interface_event last_ev;
77 D(SYSTEM, "Queue hotplug handler for interface '%s'\n", iface->name);
81 last_ev = iface->hotplug_ev;
83 iface->hotplug_ev = ev;
84 if (last_ev == ev && !list_empty(&iface->hotplug_list))
85 list_del(&iface->hotplug_list);
86 else if (last_ev != ev && list_empty(&iface->hotplug_list))
87 list_add(&iface->hotplug_list, &pending);
89 if (!task.pending && !current)
94 interface_dequeue_event(struct interface *iface)
99 if (!list_empty(&iface->hotplug_list))
100 list_del_init(&iface->hotplug_list);