[SSSD] [PATCH] Make krb5 and open checks work if forking is disabled

Sumit Bose sbose at redhat.com
Wed Feb 3 12:54:16 UTC 2010


On Wed, Feb 03, 2010 at 01:13:53PM +0100, Sumit Bose wrote:
> Hi,
> 
> this patch fixes two unit tests which failed of CK_FORK is set to no.
> 

New version with a more detailed description and a check if strdup() was
successful.

bye,
Sumit
-------------- next part --------------
From f33fd73501bcfa6ab5329ba3b56612ccf355b986 Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose at redhat.com>
Date: Tue, 2 Feb 2010 17:22:34 +0100
Subject: [PATCH] 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 +++++-
 server/tests/krb5_utils-tests.c     |    1 +
 2 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/server/tests/check_and_open-tests.c b/server/tests/check_and_open-tests.c
index 2e96455..b0d638b 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));
 }
 
diff --git a/server/tests/krb5_utils-tests.c b/server/tests/krb5_utils-tests.c
index c3d9f4c..8676f3b 100644
--- a/server/tests/krb5_utils-tests.c
+++ b/server/tests/krb5_utils-tests.c
@@ -92,6 +92,7 @@ void free_talloc_context(void)
     int ret;
     fail_unless(tmp_ctx != NULL, "Talloc context already freed.");
     ret = talloc_free(tmp_ctx);
+    tmp_ctx = NULL;
     fail_unless(ret == 0, "Connot free talloc context.");
 }
 
-- 
1.6.6



More information about the sssd-devel mailing list