Additional cleanup for config.h
[awesomized/libmemcached] / tests / server.c
index c96f5972dbda3a5c2b2e32df8ea43bed999e0fd9..543d5bacebd21ffc838e00e0921209e1c3858f1e 100644 (file)
@@ -24,6 +24,7 @@
 #include <assert.h>
 #include <signal.h>
 #include <libmemcached/memcached.h>
+#include <libmemcached/util.h>
 #include <unistd.h>
 #include "server.h"
 
@@ -73,15 +74,22 @@ void server_startup(server_startup_st *construct)
         if (x == 0)
         {
           sprintf(buffer, "%s -d -P /tmp/%umemc.pid -t 1 -p %u -U %u -m 128",
-                    MEMCACHED_BINARY, x, x + TEST_PORT_BASE, x + TEST_PORT_BASE);
+                 MEMCACHED_BINARY, x, x + TEST_PORT_BASE, x + TEST_PORT_BASE);
         }
         else
         {
           sprintf(buffer, "%s -d -P /tmp/%umemc.pid -t 1 -p %u -U %u",
-                    MEMCACHED_BINARY, x, x + TEST_PORT_BASE, x + TEST_PORT_BASE);
+                 MEMCACHED_BINARY, x, x + TEST_PORT_BASE, x + TEST_PORT_BASE);
         }
-        fprintf(stderr, "STARTING SERVER: %s\n", buffer);
-        status= system(buffer);
+       if (libmemcached_util_ping("localhost", (in_port_t)(x + TEST_PORT_BASE), NULL))
+       {
+         fprintf(stderr, "Server on port %u already exists\n", x + TEST_PORT_BASE);
+       }
+       else
+       {
+         status= system(buffer);
+         fprintf(stderr, "STARTING SERVER: %s  status:%d\n", buffer, status);
+       }
         count= sprintf(end_ptr, "localhost:%u,", x + TEST_PORT_BASE);
         end_ptr+= count;
       }