qcom: qrtr: ns: Go dormant when exsting name server is found am: bf70b7d649 am: 553fd0cd72
Change-Id: I32fedbd0bf875ce209e483ff732ff4705dfb23f2
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;