6 #include <libubox/uloop.h>
12 char *hotplug_cmd_path = DEFAULT_HOTPLUG_PATH;
13 static struct interface *current;
14 static enum interface_event current_ev;
15 static struct list_head pending = LIST_HEAD_INIT(pending);
17 static void task_complete(struct uloop_process *proc, int ret);
18 static struct uloop_process task = {
23 run_cmd(const char *ifname, bool up)
30 return task_complete(NULL, -1);
34 uloop_process_add(&task);
38 setenv("ACTION", up ? "ifup" : "ifdown", 1);
39 setenv("INTERFACE", ifname, 1);
40 argv[0] = hotplug_cmd_path;
43 execvp(argv[0], argv);
50 if (list_empty(&pending))
53 current = list_first_entry(&pending, struct interface, hotplug_list);
54 current_ev = current->hotplug_ev;
55 list_del_init(¤t->hotplug_list);
57 D(SYSTEM, "Call hotplug handler for interface '%s'\n", current->name);
58 run_cmd(current->name, current_ev == IFEV_UP);
62 task_complete(struct uloop_process *proc, int ret)
65 D(SYSTEM, "Complete hotplug handler for interface '%s'\n", current->name);
71 * Queue an interface for an up/down event.
72 * An interface can only have one event in the queue and one
73 * event waiting for completion.
74 * When queueing an event that is the same as the one waiting for
75 * completion, remove the interface from the queue
78 interface_queue_event(struct interface *iface, enum interface_event ev)
80 enum interface_event last_ev;
82 D(SYSTEM, "Queue hotplug handler for interface '%s'\n", iface->name);
83 netifd_ubus_interface_event(iface, ev == IFEV_UP);
87 last_ev = iface->hotplug_ev;
89 iface->hotplug_ev = ev;
90 if (last_ev == ev && !list_empty(&iface->hotplug_list))
91 list_del(&iface->hotplug_list);
92 else if (last_ev != ev && list_empty(&iface->hotplug_list))
93 list_add(&iface->hotplug_list, &pending);
95 if (!task.pending && !current)
100 interface_dequeue_event(struct interface *iface)
102 if (iface == current)
105 if (!list_empty(&iface->hotplug_list))
106 list_del_init(&iface->hotplug_list);