9 char *ubus_socket
= NULL
;
10 static struct ubus_context
*ctx
;
11 static struct uloop_process ubus_proc
;
12 static bool ubus_connected
= false;
14 static void procd_ubus_connection_lost(struct ubus_context
*old_ctx
);
16 static void ubus_proc_cb(struct uloop_process
*proc
, int ret
)
18 /* nothing to do here */
21 static void procd_restart_ubus(void)
23 char *argv
[] = { "ubusd", NULL
, ubus_socket
, NULL
};
25 if (ubus_proc
.pending
) {
26 DPRINTF("Killing existing ubus instance, pid=%d\n", (int) ubus_proc
.pid
);
27 kill(ubus_proc
.pid
, SIGKILL
);
28 uloop_process_delete(&ubus_proc
);
34 ubus_proc
.pid
= fork();
36 execvp(argv
[0], argv
);
40 if (ubus_proc
.pid
<= 0) {
41 DPRINTF("Failed to start new ubus instance\n");
45 DPRINTF("Launched new ubus instance, pid=%d\n", (int) ubus_proc
.pid
);
46 uloop_process_add(&ubus_proc
);
49 static void procd_ubus_try_connect(void)
52 ubus_connected
= !ubus_reconnect(ctx
, ubus_socket
);
56 ctx
= ubus_connect(ubus_socket
);
58 DPRINTF("Connection to ubus failed\n");
62 ctx
->connection_lost
= procd_ubus_connection_lost
;
63 ubus_connected
= true;
66 static void procd_ubus_connection_lost(struct ubus_context
*old_ctx
)
68 procd_ubus_try_connect();
69 while (!ubus_connected
) {
72 procd_ubus_try_connect();
75 DPRINTF("Connected to ubus, id=%08x\n", ctx
->local_id
);
79 void procd_connect_ubus(void)
81 ubus_proc
.cb
= ubus_proc_cb
;
82 procd_ubus_connection_lost(NULL
);