From ecbc211003d9db5f9cf4b09c5d147c37fe6fa12e Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Thu, 17 Oct 2024 06:44:18 +0200 Subject: [PATCH 1/4] [FIX] configure.c: Fix '.' and '..' detection Otherwise, hidden files such as '.file.' would be ignored. --- configure.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/configure.c b/configure.c index b01b351..b0cbee6 100644 --- a/configure.c +++ b/configure.c @@ -293,7 +293,8 @@ collect_sources(char *dir, bool head, char *ext) while ((ent = readdir(handle))) { char *name = ent->d_name; - if (*name == '.') continue; + + if (!strcmp(name, ".") || !strcmp(name, "..")) continue; if (strlen(name) > strlen(ext) && !strcmp(name + strlen(name) - strlen(ext), ext)) From a66021bf46fb2a32041a1ffb078761d1b33d17fd Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Thu, 17 Oct 2024 06:45:42 +0200 Subject: [PATCH 2/4] [FIX] configure.c: Improve recursion rule So far, collect_sources was called recursively when the entry name did not match a pre-defined list. However, this assumption broke with files such as `etc/media/README`, that were not in the list. Therefore, a deterministic way to distinguish files from directories is to rely on the S_ISDIR macro. This avoids the need for a pre-defined list. --- configure.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/configure.c b/configure.c index b0cbee6..6d1f1a7 100644 --- a/configure.c +++ b/configure.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -306,22 +307,29 @@ collect_sources(char *dir, bool head, char *ext) free(na); continue; } - if (!strchr(name, '.') && - strcmp(name, "out") && - strcmp(name, "Makefile")) { - str_array_t *sub; char *d1 = string_cat(dir, "/"); char *d2 = string_cat(d1, name); size_t i; + struct stat sb; - sub = collect_sources(d2, false, ext); - for (i = 0; i < str_array_len(sub); i++) + if (stat(d2, &sb)) { - char *file = str_array_get(sub, i); - str_array_add(ret, file); + fprintf(stderr, "stat(2) %s: %s\n", d2, strerror(errno)); + free(d2); + free(d1); } - str_array_free(sub); + else if (S_ISDIR(sb.st_mode)) + { + str_array_t *sub = collect_sources(d2, false, ext); + for (i = 0; i < str_array_len(sub); i++) + { + char *file = str_array_get(sub, i); + str_array_add(ret, file); + } + str_array_free(sub); + } + free(d2); free(d1); } From e0f76e7929a3a3a5216852a05752ee06db958ed8 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Thu, 17 Oct 2024 07:00:59 +0200 Subject: [PATCH 3/4] [FIX] configure.c: Add missing -I $(CYTO_INC) Some tools depend on header files defined by Cytoplasm. --- configure.c | 1 + 1 file changed, 1 insertion(+) diff --git a/configure.c b/configure.c index 6d1f1a7..e04b8e0 100644 --- a/configure.c +++ b/configure.c @@ -564,6 +564,7 @@ main_build(int argc, char *argv[]) fprintf(makefile, " -static"); } fprintf(makefile, " $<"); + fprintf(makefile, " -I $(CYTO_INC)"); fprintf(makefile, " -L $(CYTO_LIB)"); if (with_static) { From 2074d8e7680c122e0d501d7c37734c4d891066d4 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Thu, 17 Oct 2024 07:28:07 +0200 Subject: [PATCH 4/4] [FIX] configure.c: Do not assume git If parsee were downloaded from sources other than git-clone(1) (e.g.: a tarball), perror(3) fails and/or git(1) is not available on the system, "git remote get-url origin" would have unexpected results or even return a NULL pointer, which would cause undefined behaviour on strchr(repo, ...); In such conditions, a placeholder string, namely "N/A", is strdup(3)ed to `repo`. --- configure.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/configure.c b/configure.c index e04b8e0..574b75f 100644 --- a/configure.c +++ b/configure.c @@ -186,18 +186,34 @@ cmd_stdout(char *cmd) FILE *f; char *line = NULL; size_t size; + int result; if (!cmd) { - return NULL; + goto failure; } if (!(f = popen(cmd, "r"))) { - return NULL; + goto failure; } getline(&line, &size, f); - pclose(f); + result = pclose(f); + + if (result < 0) + { + perror("pclose(3)"); + goto failure; + } + else if (result) + { + fprintf(stderr, "command exited with status %d: %s\n", result, cmd); + goto failure; + } return line; + +failure: + free(line); + return NULL; } static int exec_code(char *program, char *argv[]) @@ -426,10 +442,13 @@ main_build(int argc, char *argv[]) int opt; str_array_t *sources, *images, *utils, *aya; - if (strchr(repo, '\n')) + if (repo) { - *(strchr(repo, '\n')) = '\0'; + char *lf = strchr(repo, '\n'); + *lf = '\0'; } + else + repo = strdup("N/A"); while ((opt = getopt(argc, argv, "sl")) != -1) {