From 45febf05db2be90441119d96a53e56be22dc1e96 Mon Sep 17 00:00:00 2001 From: Sumit Bose Date: Tue, 2 Feb 2010 17:22:34 +0100 Subject: Make krb5 and open checks work if forking is disabled When CK_FORK is set to 'no' the fixtures are executed for every new test inside of the same process. Global variables must be set to the expected values by the fixtures. check_and_open-tests.c: the filename template for mkstemp() was a globally defined character string. After the first call to mkstemp() the trailing XXXXXX are substituted by random values, a second call to mkstemp() with this character string fails. This patch initialize the filename template before mkstemp() is called with the help of strdup() and the memory is freed in the teardown fixture. krb5_utils-tests.c: this patch sets the just freed global talloc context to NULL to make a consistency check in the setup fixture pass. --- server/tests/check_and_open-tests.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'server/tests/check_and_open-tests.c') diff --git a/server/tests/check_and_open-tests.c b/server/tests/check_and_open-tests.c index 2e9645571..b0d638b55 100644 --- a/server/tests/check_and_open-tests.c +++ b/server/tests/check_and_open-tests.c @@ -32,7 +32,8 @@ #define SUFFIX ".symlink" -char filename[] = "check_and_open-tests-XXXXXX"; +#define FILENAME_TEMPLATE "check_and_open-tests-XXXXXX" +char *filename; uid_t uid; gid_t gid; mode_t mode; @@ -42,6 +43,8 @@ void setup_check_and_open(void) { int ret; + filename = strdup(FILENAME_TEMPLATE); + fail_unless(filename != NULL, "strdup failed"); ret = mkstemp(filename); fail_unless(ret != -1, "mkstemp failed [%d][%s]", errno, strerror(errno)); close(ret); @@ -63,6 +66,7 @@ void teardown_check_and_open(void) fail_unless(filename != NULL, "unknown filename"); ret = unlink(filename); + free(filename); fail_unless(ret == 0, "unlink failed [%d][%s]", errno, strerror(errno)); } -- cgit