diff options
author | Henning Brauer <henning@cvs.openbsd.org> | 2018-02-06 00:05:25 +0000 |
---|---|---|
committer | Henning Brauer <henning@cvs.openbsd.org> | 2018-02-06 00:05:25 +0000 |
commit | 8602ce4afa2b8667a2ceec3c6b25b9c8fa152bc0 (patch) | |
tree | 9a645ad80bf3a7c9fc9c6c94273db8bdf317af33 /usr.sbin/crunchgen | |
parent | 2a0b6585ba875e198caffe8f7697465caa466c4d (diff) |
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
Diffstat (limited to 'usr.sbin/crunchgen')
-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, |