tests: Emulate mkdtemp when not available

Commit "Build tests by default" 68f406436c
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 <adeason@sinenomine.net>
Tested-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
This commit is contained in:
Cheyenne Wills 2020-06-17 13:08:18 -06:00 committed by Benjamin Kaduk
parent 188ca8bf52
commit 5f4a681eeb
4 changed files with 28 additions and 2 deletions

View File

@ -12,6 +12,7 @@ AC_CHECK_FUNCS([ \
getuid \
getrlimit \
issetugid \
mkdtemp \
mkstemp \
openlog \
poll \

View File

@ -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 */

View File

@ -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);

View File

@ -61,6 +61,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