[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[LTP] patch for glibc-2.1.x systems



On Tue, Mar 13, 2001 at 01:37:57PM -0600, Nathan Straz wrote:
> It appears that mkdtemp was not part of glibc 2.1.x.  I'll have to find
> a reliable way of detecting this exists.  As a temporary workaround,
> suggest downloading an old tarball and extracting the file
> lib/tst_tempdir.c.  That should allow you to compile and run the tests.

Okay, I *think* I found a reliable way of detecting glibc 2.2 and 2.1.x.
It's so nice that mkdtemp() _and_ __GLIB_PREREQ() are part of glibc 2.2
only.  With this patch, LTP should compile again on 2.1.3 and 2.2.

Those of you still running 2.1.2 (Redhat 6.1 users), should upgrade to
2.1.3.  lseek03 won't compile for you.  Redhat has update packages for
you so you don't have to updated to 6.2 if you don't want to.

Without further ado, the patch for ltp-20010313...

Index: lib/tst_tmpdir.c
===================================================================
RCS file: /oss/CVS/cvs/ltp/lib/tst_tmpdir.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- lib/tst_tmpdir.c	2001/03/13 16:33:54	1.2
+++ lib/tst_tmpdir.c	2001/03/13 21:54:05	1.3
@@ -30,7 +30,7 @@
  * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
  */
 
-/* $Id: tst_tmpdir.c,v 1.2 2001/03/13 16:33:54 nstraz Exp $ */
+/* $Id: tst_tmpdir.c,v 1.3 2001/03/13 21:54:05 nstraz Exp $ */
 
 /**********************************************************
  *
@@ -119,7 +119,7 @@
 void
 tst_tmpdir()
 {
- 	char template[PATH_MAX];      /* template for mkstemp, mkdtemp */
+ 	char template[PATH_MAX];      /* template for mktemp, mkdtemp */
   	int  no_cleanup = 0;          /* !0 means TDIRECTORY env var was set */
 	char *env_tmpdir;            /* temporary storage for TMPDIR env var */
 
@@ -148,6 +148,18 @@
 			snprintf(template, PATH_MAX, "%s/%.3sXXXXXX", TEMPDIR, TCID);
 		}
 		
+/* This is an AWEFUL hack to figure out if mkdtemp() is available */
+#if defined(__GLIBC_PREREQ)
+# if __GLIBC_PREREQ(2,2)
+#  define HAVE_MKDTEMP 1
+# else
+#  define HAVE_MKDTEMP 0
+# endif
+#else 
+# define HAVE_MKDTEMP 0
+#endif
+
+#if HAVE_MKDTEMP
 		/*
 		 * Make the temporary directory in one shot using mkdtemp()
 		 */
@@ -155,6 +167,23 @@
 			tst_brkm(TBROK, tmpdir_cleanup, 
 							"%s: mkdtemp(%s) failed; errno = %d: %s",
 						   	FN_NAME, template, errno, strerror(errno));
+#else 
+		/*
+		 * Make the template name, then the directory
+		 */
+		if ((TESTDIR = mktemp(template)) == NULL)
+			tst_brkm(TBROK, tmpdir_cleanup,
+							"%s: mktemp(%s) failed; errno = %d: %s",
+							FN_NAME, template, errno, strerror(errno));
+		if (mkdir(TESTDIR, DIR_MODE)) {
+			/* If we start failing with EEXIST, wrap this section in 
+			 * a loop so we can try again.
+			 */
+			tst_brkm(TBROK, tmpdir_cleanup,
+							"%s: mkdir(%s, %#o) failed; errno = %d: %s",
+							FN_NAME, TESTDIR, DIR_MODE, errno, strerror(errno));
+		}
+#endif
 
 		/*
 		 * Change the group on this temporary directory to be that of the

-- 
Nate Straz                                              nstraz@sgi.com
sgi, inc                                           http://www.sgi.com/
Linux Test Project                    http://oss.sgi.com/projects/ltp/