]> git.ozlabs.org Git - ccan/blobdiff - tools/configurator/configurator.c
closefrom: Close all file descriptors above a certain value.
[ccan] / tools / configurator / configurator.c
index 33651ef4df3bc95c27ad12a25327439a40ce4213..57779f29905b68d82e537e8c4f0c49c2d282ebec 100644 (file)
@@ -142,6 +142,9 @@ static const struct test base_tests[] = {
        { "HAVE_ATTRIBUTE_NONNULL", "__attribute__((nonnull)) support",
          "DEFINES_FUNC", NULL, NULL,
          "static char *__attribute__((nonnull)) func(char *p) { return p; }" },
+       { "HAVE_ATTRIBUTE_RETURNS_NONNULL", "__attribute__((returns_nonnull)) support",
+         "DEFINES_FUNC", NULL, NULL,
+         "static const char *__attribute__((returns_nonnull)) func(void) { return \"hi\"; }" },
        { "HAVE_ATTRIBUTE_SENTINEL", "__attribute__((sentinel)) support",
          "DEFINES_FUNC", NULL, NULL,
          "static int __attribute__((sentinel)) func(int i, ...) { return i; }" },
@@ -495,6 +498,43 @@ static const struct test base_tests[] = {
          "     return __builtin_cpu_supports(\"mmx\");\n"
          "}"
        },
+       { "HAVE_CLOSEFROM", "closefrom() offered by system",
+         "DEFINES_EVERYTHING", NULL, NULL,
+         "#include <stdlib.h>\n"
+         "#include <unistd.h>\n"
+         "int main(void) {\n"
+         "    closefrom(STDERR_FILENO + 1);\n"
+         "    return 0;\n"
+         "}\n"
+       },
+       { "HAVE_F_CLOSEM", "F_CLOSEM defined for fctnl.",
+         "DEFINES_EVERYTHING", NULL, NULL,
+         "#include <fcntl.h>\n"
+         "#include <unistd.h>\n"
+         "int main(void) {\n"
+         "    int res = fcntl(STDERR_FILENO + 1, F_CLOSEM, 0);\n"
+         "    return res < 0;\n"
+         "}\n"
+       },
+       { "HAVE_NR_CLOSE_RANGE", "close_range syscall available as __NR_close_range.",
+         "DEFINES_EVERYTHING", NULL, NULL,
+         "#include <limits.h>\n"
+         "#include <sys/syscall.h>\n"
+         "#include <unistd.h>\n"
+         "int main(void) {\n"
+         "    int res = syscall(__NR_close_range, STDERR_FILENO + 1, INT_MAX, 0);\n"
+         "    return res < 0;\n"
+         "}\n"
+       },
+       { "HAVE_F_MAXFD", "F_MAXFD defined for fcntl.",
+         "DEFINES_EVERYTHING", NULL, NULL,
+         "#include <fcntl.h>\n"
+         "#include <unistd.h>\n"
+         "int main(void) {\n"
+         "    int res = fcntl(0, F_MAXFD);\n"
+         "    return res < 0;\n"
+         "}\n"
+       },
 };
 
 static void c12r_err(int eval, const char *fmt, ...)
@@ -762,9 +802,7 @@ static bool run_test(const char *cmd, const char *wrapper, struct test *test)
                        strcpy(cmd, wrapper);
                        strcat(cmd, " ." DIR_SEP OUTPUT_FILE);
                        output = run(cmd, &status);
-                       if (wrapper) {
-                               free(cmd);
-                       }
+                       free(cmd);
                        if (!strstr(test->style, "EXECUTE") && status != 0)
                                c12r_errx(EXIT_BAD_TEST,
                                          "Test for %s failed with %i:\n%s",