7 char *ubus_socket
= NULL
;
8 static struct ubus_context
*ctx
;
9 static struct uloop_process ubus_proc
;
10 static bool ubus_connected
= false;
12 static void procd_ubus_connection_lost(struct ubus_context
*old_ctx
);
14 static void ubus_proc_cb(struct uloop_process
*proc
, int ret
)
16 /* nothing to do here */
19 static void procd_restart_ubus(void)
21 char *argv
[] = { "ubusd", NULL
, ubus_socket
, NULL
};
23 if (ubus_proc
.pending
) {
24 DPRINTF("Killing existing ubus instance, pid=%d\n", (int) ubus_proc
.pid
);
25 kill(ubus_proc
.pid
, SIGKILL
);
26 uloop_process_delete(&ubus_proc
);
32 ubus_proc
.pid
= fork();
34 execvp(argv
[0], argv
);
38 if (ubus_proc
.pid
<= 0) {
39 DPRINTF("Failed to start new ubus instance\n");
43 DPRINTF("Launched new ubus instance, pid=%d\n", (int) ubus_proc
.pid
);
44 uloop_process_add(&ubus_proc
);
47 static void procd_ubus_try_connect(void)
50 ubus_connected
= !ubus_reconnect(ctx
, ubus_socket
);
54 ctx
= ubus_connect(ubus_socket
);
56 DPRINTF("Connection to ubus failed\n");
60 ctx
->connection_lost
= procd_ubus_connection_lost
;
61 ubus_connected
= true;
62 procd_init_service(ctx
);
65 static void procd_ubus_connection_lost(struct ubus_context
*old_ctx
)
67 procd_ubus_try_connect();
68 while (!ubus_connected
) {
71 procd_ubus_try_connect();
74 DPRINTF("Connected to ubus, id=%08x\n", ctx
->local_id
);
78 void procd_connect_ubus(void)
80 ubus_proc
.cb
= ubus_proc_cb
;
81 procd_ubus_connection_lost(NULL
);