diff options
author | 2018-02-06 00:05:24 +0000 | |
---|---|---|
committer | 2018-02-06 00:05:24 +0000 | |
commit | 81b62b1398e0590d09caab10e11b836e3236f6fb (patch) | |
tree | b9831e27250b652bc2c9ade0edbf23f498882381 | |
parent | Switch a few lists to tailqs. Mainly the prefix list per aspath needs (diff) | |
download | wireguard-openbsd-81b62b1398e0590d09caab10e11b836e3236f6fb.tar.xz wireguard-openbsd-81b62b1398e0590d09caab10e11b836e3236f6fb.zip |
chdir to the target directory, run make there and fchdir back after.
allows Makefiles with ${.CURDIR} constructs to work with crunchgen.
pointed out by Holger Mikolon, input from theo, ok theo millert
-rw-r--r-- | usr.sbin/crunchgen/crunchgen.c | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/usr.sbin/crunchgen/crunchgen.c b/usr.sbin/crunchgen/crunchgen.c index c86ee922b2e..5e088b9844b 100644 --- a/usr.sbin/crunchgen/crunchgen.c +++ b/usr.sbin/crunchgen/crunchgen.c @@ -1,4 +1,4 @@ -/* $OpenBSD: crunchgen.c,v 1.19 2017/07/27 15:33:42 espie Exp $ */ +/* $OpenBSD: crunchgen.c,v 1.20 2018/02/06 00:05:24 henning Exp $ */ /* * Copyright (c) 1994 University of Maryland @@ -42,6 +42,8 @@ #include <ctype.h> #include <string.h> #include <limits.h> +#include <fcntl.h> +#include <libgen.h> #define CRUNCH_VERSION "1.3" @@ -657,8 +659,8 @@ fillin_program(prog_t * p) void fillin_program_objs(prog_t * p, char *path) { - char *cp, *obj, tempfname[PATH_MAX]; - int fd, rc; + char *cp, *obj, tempfname[PATH_MAX], cwd[PATH_MAX]; + int fd, dotfd, rc; FILE *f; /* discover the objs from the srcdir Makefile */ @@ -678,12 +680,28 @@ fillin_program_objs(prog_t * p, char *path) fprintf(f, "crunchgen_objs:\n\t@echo 'OBJS= '${OBJS}\n"); fclose(f); - snprintf(line, sizeof(line), "make -f %s crunchgen_objs 2>&1", tempfname); + if ((dotfd = open(".", O_RDONLY, 0)) == -1 || + getcwd(cwd, sizeof(cwd)) == NULL) { + perror("get cwd"); + goterror = 1; + return; + } + if (chdir(dirname(path)) == -1) { + perror("chdir target dir"); + goterror = 1; + return; + } + snprintf(line, sizeof(line), "make -f %s/%s crunchgen_objs 2>&1", cwd, tempfname); if ((f = popen(line, "r")) == NULL) { perror("submake pipe"); goterror = 1; return; } + if (fchdir(dotfd) == -1) { + perror("fchdir back"); + goterror = 1; + return; + } while (fgets(line, MAXLINELEN, f)) { if (strncmp(line, "OBJS= ", 6)) { if (strcmp(line, |