From 69f5a7f1f2d4ace9c324b82a294a56df8b09dffe Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Sun, 9 Apr 2006 18:13:21 +0000 Subject: [PATCH] Pass '--admindir' option over to dpkg-query when passing '--admindir' or '--root' to dpkg (initial patch by Branden Robinson). Closes: #153305, #271041, #282853, #307715, #355915 --- ChangeLog | 6 ++++ debian/changelog | 3 ++ src/main.c | 71 ++++++++++++++++++++++++++++++++++++------------ 3 files changed, 63 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index ef732d44..c7594066 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-04-04 Branden Robinson , + Guillem Jover + + * src/main.c (execbackend): Pass '--admindir' over to dpkg-query + when passing '--admindir' or '--root' to dpkg. + 2006-04-04 Andrew Suffield * dpkg-buildpackage.sh: Use mustsetvar to set sversion variable. diff --git a/debian/changelog b/debian/changelog index 40edf8c7..86d3b927 100644 --- a/debian/changelog +++ b/debian/changelog @@ -31,6 +31,9 @@ dpkg (1.13.18~) UNRELEASED; urgency=low Closes: #354869 * Use mustsetvar when setting the value of the sversion variable in dpkg-buildpackage (Andrew Suffield). Closes: #158953 + * Pass '--admindir' option over to dpkg-query when passing '--admindir' or + '--root' to dpkg (initial patch by Branden Robinson). + Closes: #153305, #271041, #282853, #307715, #355915 [ Christian Perrier ] * diff --git a/src/main.c b/src/main.c index fc141b9f..b820ee3e 100644 --- a/src/main.c +++ b/src/main.c @@ -435,27 +435,64 @@ static const struct cmdinfo cmdinfos[]= { }; void execbackend(const char *const *argv) { - char **nargv; - int i, argc = 1; + char **nargv; /* argv for backend command */ + int i = 0; /* index for nargv */ + int offset = 0; /* offset for copying argv strings to nargv */ + int argc = 1; /* for nargv */ const char *const *arg = argv; - while(*arg != 0) { arg++; argc++; } - nargv= malloc(sizeof(char *) * (argc + 2)); - - if (!nargv) ohshite(_("couldn't malloc in execbackend")); - nargv[0]= strdup(cipaction->parg); - if (!nargv[0]) ohshite(_("couldn't strdup in execbackend")); - nargv[1]= malloc(strlen(cipaction->olong) + 3); - if (!nargv[1]) ohshite(_("couldn't malloc in execbackend")); - strcpy(nargv[1], "--"); - strcat(nargv[1], cipaction->olong); - for (i= 2; i <= argc; i++) { - nargv[i]= strdup(argv[i-2]); - if (!nargv[i]) ohshite(_("couldn't strdup in execbackend")); + int pass_admindir = 0; + + while (*arg != 0) { + arg++; argc++; + } + + /* + * Special case: dpkg-query takes the --admindir option, and if dpkg itself + * was given a different admin directory, we need to pass it along to it. + */ + if (strcmp(cipaction->parg, DPKGQUERY) == 0 && + strcmp(admindir, ADMINDIR) != 0) { + argc++; + pass_admindir = 1; } - nargv[i]= 0; + + nargv = malloc(sizeof(char *) * (argc + 2)); + if (!nargv) + ohshite(_("couldn't malloc in execbackend")); + + nargv[i] = strdup(cipaction->parg); + if (!nargv[i]) + ohshite(_("couldn't strdup in execbackend")); + i++, offset++; + + if (pass_admindir) { + nargv[i] = malloc((strlen("--admindir=") + strlen(admindir) + 1)); + if (!nargv[i]) + ohshite(_("couldn't malloc in execbackend")); + + sprintf(nargv[i], "--admindir=%s", admindir); + i++, offset++; + } + + nargv[i] = malloc(2 + strlen(cipaction->olong) + 1); + if (!nargv[i]) + ohshite(_("couldn't malloc in execbackend")); + strcpy(nargv[i], "--"); + strcat(nargv[i], cipaction->olong); + i++, offset++; + + /* Copy arguments from argv to nargv. */ + for (; i <= argc; i++) { + nargv[i] = strdup(argv[i - offset]); + if (!nargv[i]) + ohshite(_("couldn't strdup in execbackend")); + } + nargv[i] = 0; + execvp(cipaction->parg, nargv); - ohshite(_("failed to exec %s"),(char *)cipaction->parg); + ohshite(_("failed to exec %s"), (char *)cipaction->parg); } + void commandfd(const char *const *argv) { jmp_buf ejbuf; struct varbuf linevb; -- 2.39.5