lib/replace: Improve mkstemp test in autoconf and waf
authorAndrew Bartlett <abartlet@samba.org>
Sun, 23 Sep 2012 20:03:31 +0000 (06:03 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 24 Sep 2012 01:51:07 +0000 (03:51 +0200)
On the Sernet-solaris8 host, this test passed in the autoconf build,
then failed in the recursive waf build.  This newer test should probe
the behaviour more closely, by checking we get two distinct, secure
files.

Andrew Bartlett

lib/replace/libreplace.m4
lib/replace/wscript

index d298b9242b50f2e5ff577b809b534020a8f78021..796069c8ca1603c0ef73b18dfeec1ec25a64f18e 100644 (file)
@@ -212,12 +212,27 @@ AC_TRY_RUN([#include <stdlib.h>
 #include <unistd.h>
 main() { 
   struct stat st;
 #include <unistd.h>
 main() { 
   struct stat st;
-  char tpl[20]="/tmp/test.XXXXXX"; 
-  int fd = mkstemp(tpl); 
-  if (fd == -1) exit(1);
+  char tpl[20]="/tmp/test.XXXXXX";
+  char tpl2[20]="/tmp/test.XXXXXX";
+  int fd = mkstemp(tpl);
+  int fd2 = mkstemp(tpl2);
+  if (fd == -1) {
+        if (fd2 != -1) {
+                unlink(tpl2);
+        }
+        exit(1);
+  }
+  if (fd2 == -1) exit(1);
   unlink(tpl);
   unlink(tpl);
+  unlink(tpl2);
   if (fstat(fd, &st) != 0) exit(1);
   if ((st.st_mode & 0777) != 0600) exit(1);
   if (fstat(fd, &st) != 0) exit(1);
   if ((st.st_mode & 0777) != 0600) exit(1);
+  if (strcmp(tpl, "/tmp/test.XXXXXX") == 0) {
+        exit(1);
+  }
+  if (strcmp(tpl, tpl2) == 0) {
+        exit(1);
+  }
   exit(0);
 }],
 libreplace_cv_HAVE_SECURE_MKSTEMP=yes,
   exit(0);
 }],
 libreplace_cv_HAVE_SECURE_MKSTEMP=yes,
index 2f632e18a7a1bcf0101a0c7c68deb863955c812f..58053057d790667e36cc3582baa2e0a4cf33b050 100644 (file)
@@ -399,11 +399,26 @@ removeea setea
     conf.CHECK_CODE('''
                     struct stat st;
                     char tpl[20]="/tmp/test.XXXXXX";
     conf.CHECK_CODE('''
                     struct stat st;
                     char tpl[20]="/tmp/test.XXXXXX";
+                    char tpl2[20]="/tmp/test.XXXXXX";
                     int fd = mkstemp(tpl);
                     int fd = mkstemp(tpl);
-                    if (fd == -1) exit(1);
+                    int fd2 = mkstemp(tpl2);
+                    if (fd == -1) {
+                          if (fd2 != -1) {
+                                  unlink(tpl2);
+                          }
+                          exit(1);
+                    }
+                    if (fd2 == -1) exit(1);
                     unlink(tpl);
                     unlink(tpl);
+                    unlink(tpl2);
                     if (fstat(fd, &st) != 0) exit(1);
                     if ((st.st_mode & 0777) != 0600) exit(1);
                     if (fstat(fd, &st) != 0) exit(1);
                     if ((st.st_mode & 0777) != 0600) exit(1);
+                    if (strcmp(tpl, "/tmp/test.XXXXXX") == 0) {
+                          exit(1);
+                    }
+                    if (strcmp(tpl, tpl2) == 0) {
+                          exit(1);
+                    }
                     exit(0);
                     ''',
                     define='HAVE_SECURE_MKSTEMP',
                     exit(0);
                     ''',
                     define='HAVE_SECURE_MKSTEMP',