From: henning Date: Tue, 6 Feb 2018 00:05:24 +0000 (+0000) Subject: chdir to the target directory, run make there and fchdir back after. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=81b62b1398e0590d09caab10e11b836e3236f6fb;p=openbsd 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 --- 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 #include #include +#include +#include #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,