This cleans up some accidental linking we were getting with curses.
[m6w6/libmemcached] / libtest / server.c
index c96ffb5153d546cab133f2cf7e1f230d55cc1719..31238fe64e4c0808ba614e559e3355664a4eb1f5 100644 (file)
@@ -28,6 +28,7 @@
 #include <sys/time.h>
 #include <time.h>
 #include <unistd.h>
+#include <errno.h>
 
 #include <libmemcached/memcached.h>
 #include <libmemcached/util.h>
@@ -45,6 +46,27 @@ static void global_sleep(void)
 #endif
 }
 
+static bool wait_for_file(const char *filename)
+{
+  uint32_t timeout= 6;
+  uint32_t waited;
+  uint32_t this_wait;
+  uint32_t retry;
+
+  for (waited= 0, retry= 1; ; retry++, waited+= this_wait)
+  {
+    if ((! access(filename, R_OK)) || (waited >= timeout))
+    {
+      return true;
+    }
+
+    this_wait= retry * retry / 3 + 1;
+    sleep(this_wait);
+  }
+
+  return false;
+}
+
 static void kill_file(const char *file_buffer)
 {
   FILE *fp;
@@ -179,7 +201,21 @@ void server_startup(server_startup_st *construct)
             }
             fclose(file);
           }
-          global_sleep();
+          switch (errno)
+          {
+          default:
+            fprintf(stderr, "%s\n", strerror(errno));
+            abort();
+          case ENOENT:
+          case EINTR:
+          case EACCES:
+            break;
+          }
+
+          if (! wait_for_file(buffer))
+          {
+            abort();
+          }
         }
 
         bool was_started= false;