Browse Source

Straighten up the headers, fix some cases where we had a few things out of order.

Brian Aker 12 years ago
parent
commit
d89d683226

+ 6 - 1
configure.ac

@@ -165,7 +165,12 @@ AC_FUNC_REALLOC
 AC_FUNC_STRERROR_R
 AC_FUNC_VPRINTF
 AC_CHECK_FUNCS([dup2 gettimeofday memchr memmove memset socket strcasecmp strdup strerror strncasecmp uname])
-AC_CHECK_FUNCS([pipe2])
+AC_CHECK_FUNCS([pipe2], 
+               AC_DEFINE([HAVE_PIPE2], [1], [Have pipe2]),
+               AC_DEFINE([HAVE_PIPE2], [0], [Have pipe2]))
+AC_CHECK_FUNCS([pthread_timedjoin_np], 
+               AC_DEFINE([HAVE_PTHREAD_TIMEDJOIN_NP], [1], [Have pthread_timedjoin_np]),
+               AC_DEFINE([HAVE_PTHREAD_TIMEDJOIN_NP], [0], [Have pthread_timedjoin_np]))
 AC_CHECK_FUNCS([select])
 AC_CHECK_FUNCS([setenv])
 AC_CHECK_FUNCS([strtol])

+ 35 - 33
libgearman/pipe.cc

@@ -37,6 +37,8 @@
 
 #include <config.h>
 
+#include "libgearman/common.h"
+
 #include <cassert>
 #include <cerrno>
 #include <cstdio>
@@ -46,55 +48,55 @@
 
 bool setup_shutdown_pipe(int pipedes_[2])
 {
-#ifdef HAVE_PIPE2
-  assert(_GNU_SOURCE);
-  if (pipe2(pipedes_, O_NONBLOCK|O_CLOEXEC) == -1)
+  if (HAVE_PIPE2)
   {
-    return false;
+    if (pipe2(pipedes_, O_NONBLOCK|O_CLOEXEC) == -1)
+    {
+      return false;
+    }
   }
-#else // HAVE_PIPE2
-  if (pipe(pipedes_) == -1)
+  else if (pipe(pipedes_) == -1)
   {
     return false;
   }
-#endif // HAVE_PIPE2
 
   for (size_t x= 0; x < 2; ++x)
   {
-#ifndef HAVE_PIPE2
-    int returned_flags;
-    do 
+    if (HAVE_PIPE2)
     {
-      if ((returned_flags= fcntl(pipedes_[x], F_GETFL, 0)) == -1)
+      int returned_flags;
+      do 
       {
-        if (errno != EBADF)
+        if ((returned_flags= fcntl(pipedes_[x], F_GETFL, 0)) == -1)
         {
-          close(pipedes_[0]);
-          close(pipedes_[1]);
-        }
+          if (errno != EBADF)
+          {
+            close(pipedes_[0]);
+            close(pipedes_[1]);
+          }
 
-        return false;
-      }
-    } while (returned_flags == -1 and errno == EINTR);
+          return false;
+        }
+      } while (returned_flags == -1 and errno == EINTR);
 
-    int fcntl_error;
-    do
-    {
-      if ((fcntl_error= fcntl(pipedes_[x], F_SETFL, returned_flags | O_NONBLOCK)) == -1)
+      int fcntl_error;
+      do
       {
-        close(pipedes_[0]);
-        close(pipedes_[1]);
+        if ((fcntl_error= fcntl(pipedes_[x], F_SETFL, returned_flags | O_NONBLOCK)) == -1)
+        {
+          close(pipedes_[0]);
+          close(pipedes_[1]);
 
-        return false;
-      }
-    } while (fcntl_error == -1 and errno == EINTR);
+          return false;
+        }
+      } while (fcntl_error == -1 and errno == EINTR);
 
-    int rval;
-    do
-    { 
-      rval= fcntl (pipedes_[x], F_SETFD, FD_CLOEXEC);
-    } while (rval == -1 && (errno == EINTR or errno == EAGAIN));
-#endif // _GNU_SOURCE
+      int rval;
+      do
+      { 
+        rval= fcntl (pipedes_[x], F_SETFD, FD_CLOEXEC);
+      } while (rval == -1 && (errno == EINTR or errno == EAGAIN));
+    }
 
 #ifdef F_SETNOSIGPIPE
     int fcntl_sig_error;

+ 1 - 4
libgearman/pipe.h

@@ -35,9 +35,6 @@
  *
  */
 
-#undef _GNU_SOURCE 
-#define _GNU_SOURCE 
-
-#include <config.h>
+#pragma once
 
 bool setup_shutdown_pipe(int pipedes_[2]);

+ 1 - 3
libgearman/worker.cc

@@ -36,10 +36,8 @@
  *
  */
 
-#undef _GNU_SOURCE 
-#define _GNU_SOURCE 
-
 #include <config.h>
+
 #include <libgearman/common.h>
 #include <libgearman/function/base.hpp>
 #include <libgearman/function/make.hpp>

+ 3 - 10
libhostile/accept.c

@@ -36,24 +36,17 @@
 
 #include <config.h>
 
-/*
-  Random accept failing library for testing accept failures.
-  LD_PRELOAD="/usr/lib/libdl.so ./util/libhostile_accept.so" ./binary
-*/
-
-//#define _GNU_SOURCE
-#include <dlfcn.h>
-
 #include <errno.h>
+#include <pthread.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <unistd.h>
 #include <sys/socket.h>
 #include <sys/types.h>
 #include <time.h>
+#include <unistd.h>
 
 #include <libhostile/initialize.h>
-
+#include <libhostile/function.h>
 
 static int not_until= 500;
 

+ 2 - 6
libhostile/called.c

@@ -36,15 +36,11 @@
 
 #include <config.h>
 
+#include <libhostile/initialize.h>
+
 #include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
-/*
-  Random getaddrinfo failing library for testing getaddrinfo() failures.
-  LD_PRELOAD="/usr/lib/libdl.so ./util/libhostile_getaddrinfo.so" ./binary
-*/
-
-#include <libhostile/initialize.h>
 
 __thread bool is_called_= false;
 static __thread char** unique_ptr= NULL;

+ 4 - 0
libhostile/called.h

@@ -36,6 +36,10 @@
 
 #pragma once
 
+#ifdef HAVE_STDBOOL_H
+# include <stdbool.h>
+#endif
+
 bool is_called(void);
 void set_called();
 void reset_called();

+ 2 - 1
libhostile/function.c

@@ -38,12 +38,13 @@
 
 #if defined(TARGET_OS_LINUX) && TARGET_OS_LINUX
 
+#include <libhostile/function.h>
 #include <libhostile/initialize.h>
 
+#include <dlfcn.h>
 #include <pthread.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <dlfcn.h>
 
 int64_t function_cache_index;
 struct function_st function_cache[10];

+ 5 - 9
libhostile/function.h

@@ -36,13 +36,8 @@
 
 #pragma once
 
-#include <pthread.h>
-
-#include <stdbool.h>
-
 #include <libhostile/accept.h>
 #include <libhostile/action.h>
-#include <libhostile/called.h>
 #include <libhostile/getaddrinfo.h>
 #include <libhostile/malloc.h>
 #include <libhostile/pipe.h>
@@ -53,10 +48,6 @@
 #include <libhostile/setsockopt.h>
 #include <libhostile/write.h>
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 union function_un {
   accept_fn *accept;
   getaddrinfo_fn *getaddrinfo;
@@ -79,9 +70,14 @@ struct function_st {
   int _used;
 };
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 void function_setup();
 void print_function_cache_usage();
 
+struct function_st set_function(const char *name, const char *environ_name);
 
 #ifdef __cplusplus
 }

+ 6 - 8
libhostile/getaddrinfo.c

@@ -36,23 +36,21 @@
 
 #include <config.h>
 
-/*
-  Random getaddrinfo failing library for testing getaddrinfo() failures.
-  LD_PRELOAD="/usr/lib/libdl.so ./util/libhostile_getaddrinfo.so" ./binary
-*/
-
-#include <dlfcn.h>
+#include <libhostile/function.h>
+#include <libhostile/initialize.h>
 
 #include <assert.h>
 #include <errno.h>
+#include <netdb.h>
+#include <pthread.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <sys/socket.h>
+#include <sys/types.h>
 #include <time.h>
 #include <unistd.h>
 
-#include <libhostile/initialize.h>
-
 static int not_until= 500;
 
 static struct function_st __function;

Some files were not shown because too many files changed in this diff