]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tests: stop using `freopen` in `test-fileio`
authorEvegeny Vereshchagin <evvers@ya.ru>
Mon, 5 Mar 2018 21:23:33 +0000 (21:23 +0000)
committerEvegeny Vereshchagin <evvers@ya.ru>
Mon, 5 Mar 2018 21:57:14 +0000 (21:57 +0000)
This helps get around a bug confusing `glibc` and making the test bail
out with the following error under `asan` on `x86`:

Fatal error: glibc detected an invalid stdio handle
Aborted (core dumped)

The bug has been reported in https://github.com/google/sanitizers/issues/778,
but it is unlikely to be fixed anytime soon.

src/test/test-fileio.c

index 286867d2dc2aec8c937474440e198569a7e02a5b..3b4ee4b92a4cd1c1d633e324520f60e588186da9 100644 (file)
@@ -406,7 +406,7 @@ static void test_capeff(void) {
 
 static void test_write_string_stream(void) {
         char fn[] = "/tmp/test-write_string_stream-XXXXXX";
-        _cleanup_fclose_ FILE *f = NULL;
+        FILE *f = NULL;
         int fd;
         char buf[64];
 
@@ -416,8 +416,9 @@ static void test_write_string_stream(void) {
         f = fdopen(fd, "r");
         assert_se(f);
         assert_se(write_string_stream(f, "boohoo", 0) < 0);
+        f = safe_fclose(f);
 
-        f = freopen(fn, "r+", f);
+        f = fopen(fn, "r+");
         assert_se(f);
 
         assert_se(write_string_stream(f, "boohoo", 0) == 0);
@@ -425,8 +426,9 @@ static void test_write_string_stream(void) {
 
         assert_se(fgets(buf, sizeof(buf), f));
         assert_se(streq(buf, "boohoo\n"));
+        f = safe_fclose(f);
 
-        f = freopen(fn, "w+", f);
+        f = fopen(fn, "w+");
         assert_se(f);
 
         assert_se(write_string_stream(f, "boohoo", WRITE_STRING_FILE_AVOID_NEWLINE) == 0);
@@ -435,6 +437,7 @@ static void test_write_string_stream(void) {
         assert_se(fgets(buf, sizeof(buf), f));
         printf(">%s<", buf);
         assert_se(streq(buf, "boohoo"));
+        f = safe_fclose(f);
 
         unlink(fn);
 }