[commit] r2362 - configure UUID plugin based on available features, not on platform type; disable UUID plugin during init if uuid_generate() causes SEGV

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[commit] r2362 - configure UUID plugin based on available features, not on platform type; disable UUID plugin during init if uuid_generate() causes SEGV

commits-3
 
Author: piumarta
Date: 2011-02-15 21:52:50 -0800 (Tue, 15 Feb 2011)
New Revision: 2362

Modified:
   trunk/platforms/unix/ChangeLog
   trunk/platforms/unix/plugins/UUIDPlugin/config.cmake
   trunk/platforms/unix/plugins/UUIDPlugin/sqUnixUUID.c
Log:
configure UUID plugin based on available features, not on platform type; disable UUID plugin during init if uuid_generate() causes SEGV

Modified: trunk/platforms/unix/ChangeLog
===================================================================
--- trunk/platforms/unix/ChangeLog 2011-02-07 02:55:17 UTC (rev 2361)
+++ trunk/platforms/unix/ChangeLog 2011-02-16 05:52:50 UTC (rev 2362)
@@ -1,3 +1,13 @@
+2011-02-16  Ian Piumarta  <com -dot- gmail -at- piumarta (backwards)>
+
+ * plugins/UUIDPlugin/sqUnixUUID.c (sqUUIDInit): Fail plugin
+ initialisation if using uuid_generate() causes SIGSEGV.
+
+2011-01-29  Ian Piumarta  <com -dot- gmail -at- piumarta (backwards)>
+
+ * plugins/UUIDPlugin/sqUnixUUID.c (MakeUUID): NetBSD and FreeBSD
+ use uuidgen(), others use uuid_generate().
+
 2011-01-27  Ian Piumarta  <com -dot- gmail -at- piumarta (backwards)>
 
  * cmake/Plugins.cmake: Append ${plugin}_extra_sources to
@@ -13,7 +23,7 @@
 2011-01-23  Ian Piumarta  <com -dot- gmail -at- piumarta (backwards)>
 
  * plugins/UUIDPlugin/sqUnixUUID.c (MakeUUID): NetBSD has
- uuid_generate() not uuidgen().
+ uuidgen() not uuid_generate().
 
  * vm-display-X11/config.cmake: Use configured variable
  X11_Xrender_LIB in link libraries list.

Modified: trunk/platforms/unix/plugins/UUIDPlugin/config.cmake
===================================================================
--- trunk/platforms/unix/plugins/UUIDPlugin/config.cmake 2011-02-07 02:55:17 UTC (rev 2361)
+++ trunk/platforms/unix/plugins/UUIDPlugin/config.cmake 2011-02-16 05:52:50 UTC (rev 2362)
@@ -1,2 +1,23 @@
-PLUGIN_REQUIRE_INCLUDE(UUID uuid.h /usr/include/uuid)
-PLUGIN_FIND_LIBRARY(UUID uuid)
+PLUGIN_FIND_INCLUDE (UUID uuid.h /usr/include/uuid)
+CONFIG_DEFINE (HAVE_UUID_H)
+
+PLUGIN_FIND_INCLUDE (SYS_UUID sys/uuid.h)
+CONFIG_DEFINE (HAVE_SYS_UUID_H)
+
+PLUGIN_FIND_LIBRARY (UUID uuid)
+
+IF (HAVE_LIBUUID)
+  SET (CMAKE_REQUIRED_LIBRARIES uuid)
+ENDIF (HAVE_LIBUUID)
+
+CHECK_FUNCTION_EXISTS (uuidgen HAVE_UUIDGEN)
+CONFIG_DEFINE (HAVE_UUIDGEN)
+
+CHECK_FUNCTION_EXISTS (uuid_generate HAVE_UUID_GENERATE)
+CONFIG_DEFINE (HAVE_UUID_GENERATE)
+
+# IF (UUID_UUID_GENERATE)
+#   SET (HAVE_UUID_GENERATE 1)
+#   PLUGIN_LINK_LIBRARIES (uuid)
+# ENDIF (UUID_UUID_GENERATE)
+

Modified: trunk/platforms/unix/plugins/UUIDPlugin/sqUnixUUID.c
===================================================================
--- trunk/platforms/unix/plugins/UUIDPlugin/sqUnixUUID.c 2011-02-07 02:55:17 UTC (rev 2361)
+++ trunk/platforms/unix/plugins/UUIDPlugin/sqUnixUUID.c 2011-02-16 05:52:50 UTC (rev 2362)
@@ -1,33 +1,80 @@
 #include "config.h"
 
-#if defined(__NetBSD__)
+#if defined(HAVE_SYS_UUID_H)
 # include <sys/types.h>
 # include <sys/uuid.h>
 #endif
+#if defined(HAVE_UUID_H)
+  #include <uuid.h>
+#endif
 
-#include <uuid.h>
 #include "sq.h"
 
-int sqUUIDInit(void)
+
+int MakeUUID(char *location)
 {
+  uuid_t uuid;
+
+#if defined(HAVE_UUIDGEN)
+  uuidgen(&uuid, 1);
+#elif defined(HAVE_UUID_GENERATE)
+  uuid_generate(uuid);
+#endif
+
+  memcpy((void *)location, (void *)&uuid, sizeof(uuid));
   return 1;
 }
 
-int sqUUIDShutdown(void)
+
+#if defined(__linux__)
+
+# include <setjmp.h>
+# include <signal.h>
+
+static sigjmp_buf env;
+
+static void sigsegvHandler(int signal)
 {
-  return 1;
+  siglongjmp(env, 1);
 }
 
-int MakeUUID(char *location)
+int sqUUIDInit(void)
 {
+  /* check if we get a segmentation fault when using libuuid */
+  int pluginAvailable= 0;
+  struct sigaction originalAction;
   uuid_t uuid;
 
-#if defined(__NetBSD__)
-  uuidgen(&uuid, 1);
-#else
-  uuid_generate(uuid);
-#endif
+  if (!sigsetjmp(env, 1))
+    {
+      struct sigaction newAction;
+      newAction.sa_handler= sigsegvHandler;
+      newAction.sa_flags= 0;
+      sigemptyset(&newAction.sa_mask);
+  
+      if (sigaction(SIGSEGV, &newAction, &originalAction))
+ /* couldn't change the signal handler: give up now */
+ return 0;
+      else
+ pluginAvailable= MakeUUID((char *)&uuid);
+    }
 
-  memcpy((void *)location, (void *)&uuid, sizeof(uuid));
+  sigaction(SIGSEGV, &originalAction, NULL);
+
+  return pluginAvailable;
+}
+
+#else /* !__linux__ */
+
+int sqUUIDInit(void)
+{
   return 1;
 }
+
+#endif /* !__linux__ */
+
+
+int sqUUIDShutdown(void)
+{
+  return 1;
+}