1 #include <sys/resource.h>
8 char *ubus_socket
= NULL
;
9 static struct ubus_context
*ctx
;
10 static struct uloop_process ubus_proc
;
11 static bool ubus_connected
= false;
13 static void procd_ubus_connection_lost(struct ubus_context
*old_ctx
);
15 static void ubus_proc_cb(struct uloop_process
*proc
, int ret
)
17 /* nothing to do here */
20 static void procd_restart_ubus(void)
22 char *argv
[] = { "ubusd", NULL
, ubus_socket
, NULL
};
24 if (ubus_proc
.pending
) {
25 DPRINTF("Killing existing ubus instance, pid=%d\n", (int) ubus_proc
.pid
);
26 kill(ubus_proc
.pid
, SIGKILL
);
27 uloop_process_delete(&ubus_proc
);
33 ubus_proc
.pid
= fork();
35 setpriority(PRIO_PROCESS
, 0, -20);
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;
64 procd_init_service(ctx
);
67 static void procd_ubus_connection_lost(struct ubus_context
*old_ctx
)
69 procd_ubus_try_connect();
70 while (!ubus_connected
) {
73 procd_ubus_try_connect();
76 DPRINTF("Connected to ubus, id=%08x\n", ctx
->local_id
);
80 void procd_connect_ubus(void)
82 ubus_proc
.cb
= ubus_proc_cb
;
83 procd_ubus_connection_lost(NULL
);