[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [PATCH] Add --foreign-architecture and --print-foreign-architectures options



On Sat, Aug 29, 2009 at 01:31:17PM -0700, Steve Langasek wrote:
> On Sat, Aug 29, 2009 at 01:29:47PM -0700, Steve Langasek wrote:
> > The rest are included in the attached revised patch.

> > > And do not call it yet, I'd like to add that part only later on once
> > > it's safe to install foreign architecture packages. Or rather, split it
> > > into another patch that
> > > we'll keep at the end of the branch.

> > Right, done - also attached as a separate patch.

> Pff, let's try this again.

And I missed updating the header definition, doh.  Updated again.

-- 
Steve Langasek                   Give me a lever long enough and a Free OS
Debian Developer                   to set it on, and I can move the world.
Ubuntu Developer                                    http://www.debian.org/
slangasek@ubuntu.com                                     vorlon@debian.org
From a2dffe5db0a0c6b94e0ca3396d20bf4ea7f01c1b Mon Sep 17 00:00:00 2001
From: Steve Langasek <steve.langasek@canonical.com>
Date: Thu, 27 Aug 2009 12:42:35 -0700
Subject: [PATCH 1/2] Add --foreign-architecture and --print-foreign-architectures options

Two new options to dpkg, needed for multiarch:

 --foreign-architecture lets you specify that packages for the named
 architecture should be installable without the use of --force-architecture

 --print-foreign-architectures prints out a space-separated list of all
 architectures so configured, so that front-ends can query the list.
---
 man/dpkg.1       |   10 ++++++++++
 src/enquiry.c    |   17 +++++++++++++++++
 src/main.c       |   14 ++++++++++++++
 src/main.h       |    8 ++++++++
 src/processarc.c |   13 +++++++++++++
 5 files changed, 62 insertions(+), 0 deletions(-)

diff --git a/man/dpkg.1 b/man/dpkg.1
index d22d802..125273d 100644
--- a/man/dpkg.1
+++ b/man/dpkg.1
@@ -238,6 +238,16 @@ reason still haven't been installed.
 .B \-\-print\-architecture
 Print architecture of packages \fBdpkg\fP installs (for example, "i386").
 .TP
+.B \-\-foreign\-architecture \fIarchitecture\fP
+Add \fIarchitecture\fP to the list of architectures for which packages can be
+installed without using \fB\-\-force\-architecture\fP, in addition to the
+architecture \fBdpkg\fP is built for (i.e.: the output of
+\fB\-\-print\-architecture\fP).
+.TP
+.B \-\-print\-foreign\-architectures
+Print a space-separated list of the extra architectures \fBdpkg\fP is
+configured to allow packages to be installed for.
+.TP
 .B \-\-compare\-versions \fIver1 op ver2\fP
 Compare version numbers, where \fIop\fP is a binary operator. \fBdpkg\fP
 returns success (zero result) if the specified condition is satisfied,
diff --git a/src/enquiry.c b/src/enquiry.c
index 5f773f8..02ede15 100644
--- a/src/enquiry.c
+++ b/src/enquiry.c
@@ -395,6 +395,23 @@ printinstarch(const char *const *argv)
   printarch(argv);
 }
 
+void
+print_foreign_archs(const char *const *argv)
+{
+  struct architecture *archp;
+
+  if (*argv)
+    badusage(_("--%s takes no arguments"), cipaction->olong);
+
+  for (archp = foreign_archs; archp; archp = archp->next) {
+    printf("%s ", archp->name);
+  }
+  printf("\n");
+  fflush(stdout);
+  if (ferror(stdout) != 0)
+    werr("stdout");
+}
+
 void cmpversions(const char *const *argv) {
   struct relationinfo {
     const char *string;
diff --git a/src/main.c b/src/main.c
index d237054..ca32a07 100644
--- a/src/main.c
+++ b/src/main.c
@@ -152,6 +152,7 @@ usage(void)
 
 const char thisname[]= "dpkg";
 const char architecture[]= ARCHITECTURE;
+struct architecture *foreign_archs = NULL;
 const char printforhelp[]= N_(
 "Type dpkg --help for help about installing and deinstalling packages [*];\n"
 "Use `dselect' or `aptitude' for user-friendly package management;\n"
@@ -315,6 +316,17 @@ static void setpipe(const struct cmdinfo *cip, const char *value) {
   *pipe_head = pipe_new;
 }
 
+static void
+set_foreign_arch(const struct cmdinfo *cip, const char *value)
+{
+  struct architecture *arch_new;
+
+  arch_new = nfmalloc(sizeof(struct architecture));
+  arch_new->name = m_strdup(value);
+  arch_new->next = *cip->parg;
+  *cip->parg = arch_new;
+}
+
 static void setforce(const struct cmdinfo *cip, const char *value) {
   const char *comma;
   size_t l;
@@ -424,12 +436,14 @@ static const struct cmdinfo cmdinfos[]= {
   ACTION( "assert-multi-conrep",             0,  act_assertmulticonrep,    assertmulticonrep ),
   ACTION( "print-architecture",              0,  act_printarch,            printarch   ),
   ACTION( "print-installation-architecture", 0,  act_printinstarch,        printinstarch  ),
+  ACTION( "print-foreign-architectures",     0,  act_foreignarchs,         print_foreign_archs ),
   ACTION( "predep-package",                  0,  act_predeppackage,        predeppackage   ),
   ACTION( "compare-versions",                0,  act_cmpversions,          cmpversions     ),
 /*
   ACTION( "command-fd",                   'c', act_commandfd,   commandfd     ),
 */
   
+  { "foreign-architecture", 0,1, NULL,          NULL,      set_foreign_arch, 0, &foreign_archs },
   { "status-fd",         0,   1, NULL,          NULL,      setpipe, 0, &status_pipes },
   { "log",               0,   1, NULL,          &log_file, NULL,    0 },
   { "pending",           'a', 0, &f_pending,    NULL,      NULL,    1 },
diff --git a/src/main.h b/src/main.h
index eb5bfce..ec12fdf 100644
--- a/src/main.h
+++ b/src/main.h
@@ -57,6 +57,7 @@ enum action { act_unset, act_install, act_unpack, act_avail, act_configure,
               act_unpackchk, act_status, act_searchfiles, act_audit, act_listfiles,
               act_controlpath,
               act_assertpredep, act_printarch, act_predeppackage, act_cmpversions,
+              act_foreignarchs,
               act_printinstarch, act_compareversions, act_printavail, act_avclear,
               act_forgetold,
               act_getselections, act_setselections, act_clearselections,
@@ -102,6 +103,12 @@ extern const char *instdir;
 extern struct pkginqueue *ignoredependss;
 extern const char architecture[];
 
+struct architecture {
+	struct architecture *next;
+	const char *name;
+};
+extern struct architecture *foreign_archs;
+
 /* from archives.c */
 
 void archivefiles(const char *const *argv);
@@ -130,6 +137,7 @@ void assertmulticonrep(const char *const *argv);
 void predeppackage(const char *const *argv);
 void printarch(const char *const *argv);
 void printinstarch(const char *const *argv);
+void print_foreign_archs(const char *const *argv);
 void cmpversions(const char *const *argv) DPKG_ATTR_NORET;
 
 /* Intended for use as a comparison function for qsort when
diff --git a/src/processarc.c b/src/processarc.c
index 0b8d248..313f2f3 100644
--- a/src/processarc.c
+++ b/src/processarc.c
@@ -48,6 +48,19 @@
 #include "main.h"
 #include "archives.h"
 
+static int
+allowed_foreign_arch(char *this_arch)
+{
+  struct architecture *archp;
+
+  for (archp = foreign_archs; archp; archp = archp->next)
+    if (strcmp(this_arch, archp->name) == 0)
+      return 1;
+
+  return 0;
+}
+
+
 void process_archive(const char *filename) {
   static const struct TarFunctions tf = {
     tarfileread,
-- 
1.6.3.3

From 43a50967859371af7c6ed852d176a4086c2e88ff Mon Sep 17 00:00:00 2001
From: Steve Langasek <steve.langasek@canonical.com>
Date: Sat, 29 Aug 2009 12:35:31 -0700
Subject: [PATCH 2/2] Hook in the foreign_archs list when checking if a package is ok to install

---
 src/processarc.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/src/processarc.c b/src/processarc.c
index 313f2f3..ce6771c 100644
--- a/src/processarc.c
+++ b/src/processarc.c
@@ -229,7 +229,8 @@ void process_archive(const char *filename) {
 
   if (pkg->available.architecture && *pkg->available.architecture &&
       strcmp(pkg->available.architecture,"all") &&
-      strcmp(pkg->available.architecture,architecture))
+      strcmp(pkg->available.architecture,architecture) &&
+      !allowed_foreign_arch(pkg->available.architecture))
     forcibleerr(fc_architecture,
                 _("package architecture (%s) does not match system (%s)"),
                 pkg->available.architecture,architecture);
-- 
1.6.3.3

Attachment: signature.asc
Description: Digital signature


Reply to: