Sigh.  Patch really attached this time.

-- 
Branden Robinson          | GPG signed/encrypted mail welcome
[EMAIL PROTECTED]       | 1024D/9C0BCBFB
Progeny Linux Systems     | D5F6 D4C9 E25B 3D37 068C
                          | 72E8 0F42 191A 9C0B CBFB
Index: dpkg/branches/dpkg-opensolaris/src/main.c
===================================================================
--- dpkg/branches/dpkg-opensolaris/src/main.c   (revision 5334)
+++ dpkg/branches/dpkg-opensolaris/src/main.c   (revision 5335)
@@ -349,16 +349,17 @@
 void execbackend(const char *const *argv) NONRETURNING;
 void commandfd(const char *const *argv);
 static const struct cmdinfo cmdinfos[]= {
-  /* This table has both the action entries in it and the normal options.
-   * The action entries are made with the ACTION macro, as they all
+  /*
+   * This table has both the action entries in it and the normal options.
+   * The action entries are made with the ACTION macros, as they all
    * have a very similar structure.
    */
 #define ACTION(longopt,shortopt,code,function) \
  { longopt, shortopt, 0,0,0, setaction, code, 0, (voidfnp)function }
 #define OBSOLETE(longopt,shortopt) \
  { longopt, shortopt, 0,0,0, setobsolete, 0, 0, 0 }
-#define ACTIONBACKEND(longopt,shortop, backend) \
- { longopt, shortop, 0,0,0, setaction, 0, (void*)backend, (voidfnp)execbackend 
}
+#define ACTIONBACKEND(longopt,shortopt,backend) \
+ { longopt, shortopt, 0,0,0, setaction, 0, (void*)backend, 
(voidfnp)execbackend }
 
   ACTION( "install",                        'i', act_install,              
archivefiles    ),
   ACTION( "unpack",                          0,  act_unpack,               
archivefiles    ),
@@ -433,27 +434,57 @@
 };
 
 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]);
+  nargv[i]= strdup(cipaction->parg);
+  if (!nargv[i]) ohshite(_("couldn't strdup in execbackend"));
+  i++, offset++;
+
+  /*
+   * 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 dpkg-query.
+   *
+   * No other backend takes any of --root, --admindir, or
+   * --instdir.
+   */
+  if (!strcmp(nargv[0], DPKGQUERY)) {
+    if (strcmp(admindir, ADMINDIR)) {
+      nargv[i] = malloc((strlen("--admindir=") + strlen(admindir) + 1));
+      if (!nargv[i]) ohshite(_("couldn't malloc in execbackend"));
+      (void) sprintf(nargv[i], "--admindir=%s", admindir);
+      /*
+       * We've added an argument, so increment the current
+       * position, the offset, and the number of arguments.
+       */
+      i++, offset++, argc++;
+    }
+  }
+
+  nargv[i]= malloc(strlen(cipaction->olong) + 3);
+  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);
 }
+
 void commandfd(const char *const *argv) {
   jmp_buf ejbuf;
   struct varbuf linevb;

Reply via email to