Exit if not able to create server.
authorThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sun, 7 Jun 2009 15:35:20 +0000 (12:35 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sun, 7 Jun 2009 15:35:20 +0000 (12:35 -0300)
If we cannot bind to the address, exit. Only log the listen address if
it is successfull.

popproxy.c

index f2a7f30..e525afa 100644 (file)
@@ -21,6 +21,7 @@
 #include <glib.h>
 #include <gnet.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <unistd.h>
 #include <gnutls/gnutls.h>
 #include "log.h"
@@ -84,10 +85,15 @@ int main (int argc, char** argv)
   port = g_key_file_get_integer (keyfile, "global", "port", NULL);
   server_address = g_key_file_get_string (keyfile, "global", "server", NULL);
 
-  g_message ("Listen address is %s:%d.", conf_address, port);
-
   inetaddr = gnet_inetaddr_new_nonblock (conf_address, port);
-  gnet_server_new (inetaddr, port, new_client, server_address);
+  if (gnet_server_new (inetaddr, port,
+                       new_client, server_address) == NULL)
+    {
+      fprintf (stderr, "Could not create server.\n");
+      exit (1);
+    }
+
+  g_message ("Listening at %s:%d.", conf_address, port);
 
   daemon (0, 0);