qcom: qrtr: ns: Go dormant when exsting name server is found
With the introduction of the in-kernel nameserver launching the user
space qrtr-ns will fail, but typically other services depends on its
presence. As such, go dormant instead of failing when noticed that the
name service is already present.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
Change-Id: I62aa002294e6980bab0b5e1b7282212b8d2c3d57
diff --git a/qcom/qrtr/src/ns.c b/qcom/qrtr/src/ns.c
index 4b88a9c..393cc68 100644
--- a/qcom/qrtr/src/ns.c
+++ b/qcom/qrtr/src/ns.c
@@ -685,6 +685,14 @@
free(node);
}
+static void go_dormant(int sock)
+{
+ close(sock);
+
+ for (;;)
+ sleep(UINT_MAX);
+}
+
static void usage(const char *progname)
{
fprintf(stderr, "%s [-f] [-s] [<node-id>]\n", progname);
@@ -760,8 +768,14 @@
ctx.local_node = sq.sq_node;
rc = bind(ctx.sock, (void *)&sq, sizeof(sq));
- if (rc < 0)
+ if (rc < 0) {
+ if (errno == EADDRINUSE) {
+ PLOGE("nameserver already running, going dormant");
+ go_dormant(ctx.sock);
+ }
+
PLOGE_AND_EXIT("bind control socket");
+ }
ctx.bcast_sq.sq_family = AF_QIPCRTR;
ctx.bcast_sq.sq_node = QRTR_NODE_BCAST;