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) {