From 5f4a681eeb5e353f09aa895770f7336a2b381467 Mon Sep 17 00:00:00 2001 From: Cheyenne Wills Date: Wed, 17 Jun 2020 13:08:18 -0600 Subject: [PATCH] tests: Emulate mkdtemp when not available Commit "Build tests by default" 68f406436cc21853ff854c514353e7eb607cb6cb changes the build so tests are always built. On Solaris 10 Update 10 and earlier the build fails because the mkdtemp function is not available. Introduce a wrapper 'afstest_mkdtemp' that uses mkdtemp if available, otherwise uses mktemp/mkdir. Change-Id: I0118f838ed9a89927e2ddac4cad822574601558a Reviewed-on: https://gerrit.openafs.org/14243 Reviewed-by: Andrew Deason Tested-by: Andrew Deason Reviewed-by: Benjamin Kaduk --- src/cf/functions.m4 | 1 + tests/auth/writekeyfile.c | 2 +- tests/common/common.h | 1 + tests/common/config.c | 26 +++++++++++++++++++++++++- 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/cf/functions.m4 b/src/cf/functions.m4 index ac4f5d9..442f759 100644 --- a/src/cf/functions.m4 +++ b/src/cf/functions.m4 @@ -12,6 +12,7 @@ AC_CHECK_FUNCS([ \ getuid \ getrlimit \ issetugid \ + mkdtemp \ mkstemp \ openlog \ poll \ diff --git a/tests/auth/writekeyfile.c b/tests/auth/writekeyfile.c index 2387da0..a622ce0 100644 --- a/tests/auth/writekeyfile.c +++ b/tests/auth/writekeyfile.c @@ -24,7 +24,7 @@ main(int argc, char **argv) int code; snprintf(buffer, sizeof(buffer), "%s/afs_XXXXXX", gettmpdir()); - mkdtemp(buffer); + afstest_mkdtemp(buffer); dirEnd = buffer + strlen(buffer); /* Create a CellServDB file */ diff --git a/tests/common/common.h b/tests/common/common.h index e1a407c..88bd745 100644 --- a/tests/common/common.h +++ b/tests/common/common.h @@ -25,6 +25,7 @@ /* config.c */ extern char *afstest_BuildTestConfig(void); extern void afstest_UnlinkTestConfig(char *); +extern char *afstest_mkdtemp(char *template); struct afsconf_dir; extern int afstest_AddDESKeyFile(struct afsconf_dir *dir); diff --git a/tests/common/config.c b/tests/common/config.c index 6a0e3e1..debd71e 100644 --- a/tests/common/config.c +++ b/tests/common/config.c @@ -62,6 +62,30 @@ unlinkConfigFile(char *dirname, char *filename) { } /*! + * Wrapper for mkdtemp + */ + +char * +afstest_mkdtemp(char *template) +{ +#if defined(HAVE_MKDTEMP) + return mkdtemp(template); +#else + /* + * Note that using the following is not a robust replacement + * for mkdtemp as there is a possible race condition between + * creating the name and creating the directory itself. The + * use of this routine is limited to running tests. + */ + if (mktemp(template) == NULL) + return NULL; + if (mkdir(template, 0700)) + return NULL; + return template; +#endif +} + +/*! * Build a test configuration directory, containing a CellServDB and ThisCell * file for the "example.org" cell * @@ -82,7 +106,7 @@ afstest_BuildTestConfig(void) { if (asprintf(&dir, "%s/afs_XXXXXX", gettmpdir()) == -1) goto fail; - if (mkdtemp(dir) == NULL) + if (afstest_mkdtemp(dir) == NULL) goto fail; /* Work out which IP address to use in our CellServDB. We figure this out -- 1.9.4