Don't segfault if bind() fails.

Add a return code to DIAL_start, and check it.
Fixes b/23789345

Change-Id: I1c4dae02ef4b22c96bc1aa9a06deff19e2de2826
diff --git a/src/server/dial_server.c b/src/server/dial_server.c
index cdf6186..745dfe2 100644
--- a/src/server/dial_server.c
+++ b/src/server/dial_server.c
@@ -597,8 +597,9 @@
     return ds;
 }
 
-void DIAL_start(DIALServer *ds) {
+int DIAL_start(DIALServer *ds) {
     ds->ctx = mg_start(&request_handler, ds, DIAL_PORT);
+    return (ds->ctx == NULL) ? 1 : 0;
 }
 
 void DIAL_stop(DIALServer *ds) {
diff --git a/src/server/dial_server.h b/src/server/dial_server.h
index 32afef8..ba85b10 100644
--- a/src/server/dial_server.h
+++ b/src/server/dial_server.h
@@ -121,11 +121,11 @@
 DIALServer *DIAL_create();
 
 /*
- * Starts the DIAL server.
+ * Starts the DIAL server. Returns 0 on success, !0 on failure.
  *
  * @param[in] ds DIAL server handle
  */
-void DIAL_start(DIALServer *ds);
+int DIAL_start(DIALServer *ds);
 
 /*
  * Stop the DIAL server.
diff --git a/src/server/main.c b/src/server/main.c
index caa9d65..1f650c2 100644
--- a/src/server/main.c
+++ b/src/server/main.c
@@ -457,7 +457,10 @@
     } else {
       DIAL_register_app(ds, "FiberTV", &cb_ft, NULL, 0, NULL);
     }
-    DIAL_start(ds);
+    if (DIAL_start(ds)) {
+        fprintf(stderr, "DIAL_start failed, exiting.\n");
+        exit(1);
+    }
 
     gDialPort = DIAL_get_port(ds);
     fprintf(stderr, "launcher listening on gDialPort %d\n", gDialPort);