This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch master
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=e14213a278574c0dbdec02f26fa8c7c4c02dfe7c

commit e14213a278574c0dbdec02f26fa8c7c4c02dfe7c
Author: Guillem Jover <[email protected]>
AuthorDate: Sat Feb 23 04:37:13 2019 +0100

    dpkg: Move force options support into its own file
    
    This unifies all force related code in a single file, and will make it
    possible to use it in other programs.
---
 debian/changelog |   1 +
 po/POTFILES.in   |   1 +
 src/Makefile.am  |   1 +
 src/errors.c     |  20 ----
 src/force.c      | 315 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/force.h      |  61 +++++++++++
 src/main.c       | 160 ----------------------------
 src/main.h       |  14 +--
 8 files changed, 381 insertions(+), 192 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index c31d1fb23..6c5abb227 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -14,6 +14,7 @@ dpkg (1.19.5) UNRELEASED; urgency=medium
   * Code internals:
     - dpkg: Move SELinux fallback label to the SELinux specific code path.
     - dpkg: Simplify maintscript_set_exec_context().
+    - dpkg: Move force options support into its own file.
   * Build system:
     - Check whether this dist is a release, based only on the version format.
       This will avoid having to do a two staged release to get a proper perl
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 1fc14b9f6..2bc37a9b3 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -81,6 +81,7 @@ src/enquiry.c
 src/errors.c
 src/file-match.c
 src/filters.c
+src/force.c
 src/help.c
 src/main.c
 src/packages.c
diff --git a/src/Makefile.am b/src/Makefile.am
index e6c957062..93494db22 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -34,6 +34,7 @@ dpkg_SOURCES = \
        errors.c \
        file-match.c file-match.h \
        filters.c filters.h \
+       force.c force.h \
        help.c \
        main.c main.h \
        packages.c \
diff --git a/src/errors.c b/src/errors.c
index 5ecc101c3..2c5d147a5 100644
--- a/src/errors.c
+++ b/src/errors.c
@@ -134,23 +134,3 @@ skip_due_to_hold(struct pkginfo *pkg)
   return true;
 }
 
-void forcibleerr(int forceflag, const char *fmt, ...) {
-  va_list args;
-
-  va_start(args, fmt);
-  if (forceflag) {
-    warning(_("overriding problem because --force enabled:"));
-    warningv(fmt, args);
-  } else {
-    ohshitv(fmt, args);
-  }
-  va_end(args);
-}
-
-int
-forcible_nonroot_error(int rc)
-{
-  if (fc_nonroot && errno == EPERM)
-    return 0;
-  return rc;
-}
diff --git a/src/force.c b/src/force.c
new file mode 100644
index 000000000..ce0077e6f
--- /dev/null
+++ b/src/force.c
@@ -0,0 +1,315 @@
+/*
+ * dpkg - main program for package management
+ * force.c - force operation support
+ *
+ * Copyright © 1994,1995 Ian Jackson <[email protected]>
+ * Copyright © 2006-2019 Guillem Jover <[email protected]>
+ *
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include <compat.h>
+
+#include <errno.h>
+#include <string.h>
+#include <stdbool.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <dpkg/macros.h>
+#include <dpkg/i18n.h>
+#include <dpkg/dpkg.h>
+#include <dpkg/dpkg-db.h>
+#include <dpkg/options.h>
+
+#include "force.h"
+
+int fc_architecture = 0;
+int fc_badpath = 0;
+int fc_badverify = 0;
+int fc_badversion = 0;
+int fc_breaks = 0;
+int fc_conff_ask = 0;
+int fc_conff_def = 0;
+int fc_conff_miss = 0;
+int fc_conff_new = 0;
+int fc_conff_old = 0;
+int fc_configureany = 0;
+int fc_conflicts = 0;
+int fc_depends = 0;
+int fc_dependsversion = 0;
+int fc_downgrade = 1;
+int fc_hold = 0;
+int fc_nonroot = 0;
+int fc_overwrite = 0;
+int fc_overwritedir = 0;
+int fc_overwritediverted = 0;
+int fc_removeessential = 0;
+int fc_removereinstreq = 0;
+int fc_script_chrootless = 0;
+int fc_unsafe_io = 0;
+
+static const char *
+forcetype_str(char type)
+{
+       switch (type) {
+       case '\0':
+       case ' ':
+               return "   ";
+       case '*':
+               return "[*]";
+       case '!':
+               return "[!]";
+       default:
+               internerr("unknown force type '%c'", type);
+       }
+}
+
+static const struct forceinfo {
+       const char *name;
+       int *opt;
+       char type;
+       const char *desc;
+} forceinfos[] = {
+       {
+               "all",
+               NULL,
+               '!',
+               N_("Set all force options"),
+       }, {
+               "downgrade",
+               &fc_downgrade,
+               '*',
+               N_("Replace a package with a lower version"),
+       }, {
+               "configure-any",
+               &fc_configureany,
+               ' ',
+               N_("Configure any package which may help this one"),
+       }, {
+               "hold",
+               &fc_hold,
+               ' ',
+               N_("Process incidental packages even when on hold"),
+       }, {
+               "not-root",
+               &fc_nonroot,
+               ' ',
+               N_("Try to (de)install things even when not root"),
+       }, {
+               "bad-path",
+               &fc_badpath,
+               ' ',
+               N_("PATH is missing important programs, problems likely"),
+       }, {
+               "bad-verify",
+               &fc_badverify,
+               ' ',
+               N_("Install a package even if it fails authenticity check"),
+       }, {
+               "bad-version",
+               &fc_badversion,
+               ' ',
+               N_("Process even packages with wrong versions"),
+       }, {
+               "overwrite",
+               &fc_overwrite,
+               ' ',
+               N_("Overwrite a file from one package with another"),
+       }, {
+               "overwrite-diverted",
+               &fc_overwritediverted,
+               ' ',
+               N_("Overwrite a diverted file with an undiverted version"),
+       }, {
+               "overwrite-dir",
+               &fc_overwritedir,
+               '!',
+               N_("Overwrite one package's directory with another's file"),
+       }, {
+               "unsafe-io",
+               &fc_unsafe_io,
+               '!',
+               N_("Do not perform safe I/O operations when unpacking"),
+       }, {
+               "script-chrootless",
+               &fc_script_chrootless,
+               '!',
+               N_("Do not chroot into maintainer script environment"),
+       }, {
+               "confnew",
+               &fc_conff_new,
+               '!',
+               N_("Always use the new config files, don't prompt"),
+       }, {
+               "confold",
+               &fc_conff_old,
+               '!',
+               N_("Always use the old config files, don't prompt"),
+       }, {
+               "confdef",
+               &fc_conff_def,
+               '!',
+               N_("Use the default option for new config files if one\n"
+                  "is available, don't prompt. If no default can be found,\n"
+                  "you will be prompted unless one of the confold or\n"
+                  "confnew options is also given"),
+       }, {
+               "confmiss",
+               &fc_conff_miss,
+               '!',
+               N_("Always install missing config files"),
+       }, {
+               "confask",
+               &fc_conff_ask,
+               '!',
+               N_("Offer to replace config files with no new versions"),
+       }, {
+               "architecture",
+               &fc_architecture,
+               '!',
+               N_("Process even packages with wrong or no architecture"),
+       }, {
+               "breaks",
+               &fc_breaks,
+               '!',
+               N_("Install even if it would break another package"),
+       }, {
+               "conflicts",
+               &fc_conflicts,
+               '!',
+               N_("Allow installation of conflicting packages"),
+       }, {
+               "depends",
+               &fc_depends,
+               '!',
+               N_("Turn all dependency problems into warnings"),
+       }, {
+               "depends-version",
+               &fc_dependsversion,
+               '!',
+               N_("Turn dependency version problems into warnings"),
+       }, {
+               "remove-reinstreq",
+               &fc_removereinstreq,
+               '!',
+               N_("Remove packages which require installation"),
+       }, {
+               "remove-essential",
+               &fc_removeessential,
+               '!',
+               N_("Remove an essential package"),
+       }, {
+               NULL
+       }
+};
+
+static inline void
+print_forceinfo_line(int type, const char *name, const char *desc)
+{
+       printf("  %s %-18s %s\n", forcetype_str(type), name, desc);
+}
+
+static void
+print_forceinfo(const struct forceinfo *fi)
+{
+       char *desc, *line;
+
+       desc = m_strdup(gettext(fi->desc));
+
+       line = strtok(desc, "\n");
+       print_forceinfo_line(fi->type, fi->name, line);
+       while ((line = strtok(NULL, "\n")))
+               print_forceinfo_line(' ', "", line);
+
+       free(desc);
+}
+
+void
+set_force(const struct cmdinfo *cip, const char *value)
+{
+       const char *comma;
+       size_t l;
+       const struct forceinfo *fip;
+
+       if (strcmp(value, "help") == 0) {
+               printf(_(
+"%s forcing options - control behaviour when problems found:\n"
+"  warn but continue:  --force-<thing>,<thing>,...\n"
+"  stop with error:    --refuse-<thing>,<thing>,... | --no-force-<thing>,...\n"
+" Forcing things:\n"), DPKG);
+
+               for (fip = forceinfos; fip->name; fip++)
+                       print_forceinfo(fip);
+
+               printf(_(
+"\n"
+"WARNING - use of options marked [!] can seriously damage your installation.\n"
+"Forcing options marked [*] are enabled by default.\n"));
+               m_output(stdout, _("<standard output>"));
+               exit(0);
+       }
+
+       for (;;) {
+               comma = strchrnul(value, ',');
+               l = (size_t)(comma - value);
+               for (fip = forceinfos; fip->name; fip++)
+                       if (strncmp(fip->name, value, l) == 0 &&
+                           strlen(fip->name) == l)
+                               break;
+
+               if (!fip->name) {
+                       badusage(_("unknown force/refuse option '%.*s'"),
+                                (int)min(l, 250), value);
+               } else if (strcmp(fip->name, "all") == 0) {
+                       for (fip = forceinfos; fip->name; fip++)
+                               if (fip->opt)
+                                       *fip->opt = cip->arg_int;
+               } else if (fip->opt) {
+                       *fip->opt = cip->arg_int;
+               } else {
+                       warning(_("obsolete force/refuse option '%s'"),
+                               fip->name);
+               }
+
+               if (*comma == '\0')
+                       break;
+               value = ++comma;
+       }
+}
+
+void
+forcibleerr(int forceflag, const char *fmt, ...)
+{
+       va_list args;
+
+       va_start(args, fmt);
+       if (forceflag) {
+               warning(_("overriding problem because --force enabled:"));
+               warningv(fmt, args);
+       } else {
+               ohshitv(fmt, args);
+       }
+       va_end(args);
+}
+
+int
+forcible_nonroot_error(int rc)
+{
+       if (fc_nonroot && errno == EPERM)
+               return 0;
+       return rc;
+}
diff --git a/src/force.h b/src/force.h
new file mode 100644
index 000000000..2e9a84d9e
--- /dev/null
+++ b/src/force.h
@@ -0,0 +1,61 @@
+/*
+ * dpkg - main program for package management
+ * force.h - forced operation support
+ *
+ * Copyright © 1995 Ian Jackson <[email protected]>
+ * Copyright © 2006, 2008-2019 Guillem Jover <[email protected]>
+ *
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef DPKG_FORCE_H
+#define DPKG_FORCE_H
+
+#include <dpkg/dpkg.h>
+#include <dpkg/options.h>
+
+extern int fc_architecture;
+extern int fc_badpath;
+extern int fc_badverify;
+extern int fc_badversion;
+extern int fc_breaks;
+extern int fc_conff_ask;
+extern int fc_conff_def;
+extern int fc_conff_miss;
+extern int fc_conff_new;
+extern int fc_conff_old;
+extern int fc_configureany;
+extern int fc_conflicts;
+extern int fc_depends;
+extern int fc_dependsversion;
+extern int fc_downgrade;
+extern int fc_hold;
+extern int fc_nonroot;
+extern int fc_overwrite;
+extern int fc_overwritedir;
+extern int fc_overwritediverted;
+extern int fc_removeessential;
+extern int fc_removereinstreq;
+extern int fc_script_chrootless;
+extern int fc_unsafe_io;
+
+void
+set_force(const struct cmdinfo *cip, const char *value);
+
+void
+forcibleerr(int forceflag, const char *format, ...) DPKG_ATTR_PRINTF(2);
+int
+forcible_nonroot_error(int rc);
+
+#endif /* DPKG_FORCE_H */
diff --git a/src/main.c b/src/main.c
index a6b225c51..d3488d52a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -192,100 +192,12 @@ static const char printforhelp[] = N_(
 int f_pending=0, f_recursive=0, f_alsoselect=1, f_skipsame=0, f_noact=0;
 int f_autodeconf=0, f_nodebsig=0;
 int f_triggers = 0;
-int fc_downgrade=1, fc_configureany=0, fc_hold=0, fc_removereinstreq=0, 
fc_overwrite=0;
-int fc_removeessential=0, fc_conflicts=0, fc_depends=0, fc_dependsversion=0;
-int fc_breaks=0, fc_badpath=0, fc_overwritediverted=0, fc_architecture=0;
-int fc_nonroot=0, fc_overwritedir=0, fc_conff_new=0, fc_conff_miss=0;
-int fc_conff_old=0, fc_conff_def=0;
-int fc_conff_ask = 0;
-int fc_unsafe_io = 0;
-int fc_badverify = 0;
-int fc_badversion = 0;
-int fc_script_chrootless = 0;
 
 int errabort = 50;
 static const char *admindir = ADMINDIR;
 const char *instdir= "";
 struct pkg_list *ignoredependss = NULL;
 
-static const char *
-forcetype_str(char type)
-{
-  switch (type) {
-  case '\0':
-  case ' ':
-    return "   ";
-  case '*':
-    return "[*]";
-  case '!':
-    return "[!]";
-  default:
-    internerr("unknown force type '%c'", type);
-  }
-}
-
-static const struct forceinfo {
-  const char *name;
-  int *opt;
-  char type;
-  const char *desc;
-} forceinfos[]= {
-  { "all",                 NULL,
-    '!', N_("Set all force options")},
-  { "downgrade",           &fc_downgrade,
-    '*', N_("Replace a package with a lower version") },
-  { "configure-any",       &fc_configureany,
-    ' ', N_("Configure any package which may help this one") },
-  { "hold",                &fc_hold,
-    ' ', N_("Process incidental packages even when on hold") },
-  { "not-root",            &fc_nonroot,
-    ' ', N_("Try to (de)install things even when not root") },
-  { "bad-path",            &fc_badpath,
-    ' ', N_("PATH is missing important programs, problems likely") },
-  { "bad-verify",          &fc_badverify,
-    ' ', N_("Install a package even if it fails authenticity check") },
-  { "bad-version",         &fc_badversion,
-    ' ', N_("Process even packages with wrong versions") },
-  { "overwrite",           &fc_overwrite,
-    ' ', N_("Overwrite a file from one package with another") },
-  { "overwrite-diverted",  &fc_overwritediverted,
-    ' ', N_("Overwrite a diverted file with an undiverted version") },
-  { "overwrite-dir",       &fc_overwritedir,
-    '!', N_("Overwrite one package's directory with another's file") },
-  { "unsafe-io",           &fc_unsafe_io,
-    '!', N_("Do not perform safe I/O operations when unpacking") },
-  { "script-chrootless",   &fc_script_chrootless,
-    '!', N_("Do not chroot into maintainer script environment") },
-  { "confnew",             &fc_conff_new,
-    '!', N_("Always use the new config files, don't prompt") },
-  { "confold",             &fc_conff_old,
-    '!', N_("Always use the old config files, don't prompt") },
-  { "confdef",             &fc_conff_def,
-    '!', N_("Use the default option for new config files if one\n"
-            "is available, don't prompt. If no default can be found,\n"
-            "you will be prompted unless one of the confold or\n"
-            "confnew options is also given") },
-  { "confmiss",            &fc_conff_miss,
-    '!', N_("Always install missing config files") },
-  { "confask",             &fc_conff_ask,
-    '!', N_("Offer to replace config files with no new versions") },
-  { "architecture",        &fc_architecture,
-    '!', N_("Process even packages with wrong or no architecture") },
-  { "breaks",              &fc_breaks,
-    '!', N_("Install even if it would break another package") },
-  { "conflicts",           &fc_conflicts,
-    '!', N_("Allow installation of conflicting packages") },
-  { "depends",             &fc_depends,
-    '!', N_("Turn all dependency problems into warnings") },
-  { "depends-version",     &fc_dependsversion,
-    '!', N_("Turn dependency version problems into warnings") },
-  { "remove-reinstreq",    &fc_removereinstreq,
-    '!', N_("Remove packages which require installation") },
-  { "remove-essential",    &fc_removeessential,
-    '!', N_("Remove an essential package") },
-  { NULL }
-};
-
 #define DBG_DEF(n, d) \
   { .flag = dbg_##n, .name = #n, .desc = d }
 
@@ -599,78 +511,6 @@ arch_remove(const char *const *argv)
   return 0;
 }
 
-static inline void
-print_forceinfo_line(int type, const char *name, const char *desc)
-{
-  printf("  %s %-18s %s\n", forcetype_str(type), name, desc);
-}
-
-static void
-print_forceinfo(const struct forceinfo *fi)
-{
-  char *desc, *line;
-
-  desc = m_strdup(gettext(fi->desc));
-
-  line = strtok(desc, "\n");
-  print_forceinfo_line(fi->type, fi->name, line);
-  while ((line = strtok(NULL, "\n")))
-    print_forceinfo_line(' ', "", line);
-
-  free(desc);
-}
-
-static void
-set_force(const struct cmdinfo *cip, const char *value)
-{
-  const char *comma;
-  size_t l;
-  const struct forceinfo *fip;
-
-  if (strcmp(value, "help") == 0) {
-    printf(_(
-"%s forcing options - control behaviour when problems found:\n"
-"  warn but continue:  --force-<thing>,<thing>,...\n"
-"  stop with error:    --refuse-<thing>,<thing>,... | --no-force-<thing>,...\n"
-" Forcing things:\n"), DPKG);
-
-    for (fip = forceinfos; fip->name; fip++)
-      print_forceinfo(fip);
-
-    printf(_(
-"\n"
-"WARNING - use of options marked [!] can seriously damage your installation.\n"
-"Forcing options marked [*] are enabled by default.\n"));
-    m_output(stdout, _("<standard output>"));
-    exit(0);
-  }
-
-  for (;;) {
-    comma = strchrnul(value, ',');
-    l = (size_t)(comma - value);
-    for (fip=forceinfos; fip->name; fip++)
-      if (strncmp(fip->name, value, l) == 0 && strlen(fip->name) == l)
-        break;
-
-    if (!fip->name) {
-      badusage(_("unknown force/refuse option '%.*s'"),
-               (int)min(l, 250), value);
-    } else if (strcmp(fip->name, "all") == 0) {
-      for (fip = forceinfos; fip->name; fip++)
-        if (fip->opt)
-          *fip->opt = cip->arg_int;
-    } else if (fip->opt) {
-      *fip->opt = cip->arg_int;
-    } else {
-      warning(_("obsolete force/refuse option '%s'"), fip->name);
-    }
-
-    if (*comma == '\0')
-      break;
-    value= ++comma;
-  }
-}
-
 int execbackend(const char *const *argv) DPKG_ATTR_NORET;
 int commandfd(const char *const *argv);
 
diff --git a/src/main.h b/src/main.h
index 944be5ea5..e4a251969 100644
--- a/src/main.h
+++ b/src/main.h
@@ -25,6 +25,8 @@
 #include <dpkg/debug.h>
 #include <dpkg/pkg-list.h>
 
+#include "force.h"
+
 /* These two are defined in <dpkg/fsys.h>. */
 struct fsys_namenode_list;
 struct fsys_namenode;
@@ -123,16 +125,6 @@ extern const char *const statusstrings[];
 extern int f_pending, f_recursive, f_alsoselect, f_skipsame, f_noact;
 extern int f_autodeconf, f_nodebsig;
 extern int f_triggers;
-extern int fc_downgrade, fc_configureany, fc_hold, fc_removereinstreq, 
fc_overwrite;
-extern int fc_removeessential, fc_conflicts, fc_depends, fc_dependsversion;
-extern int fc_breaks, fc_badpath, fc_overwritediverted, fc_architecture;
-extern int fc_nonroot, fc_overwritedir, fc_conff_new, fc_conff_miss;
-extern int fc_conff_old, fc_conff_def;
-extern int fc_conff_ask;
-extern int fc_badverify;
-extern int fc_badversion;
-extern int fc_unsafe_io;
-extern int fc_script_chrootless;
 
 extern bool abort_processing;
 extern int errabort;
@@ -268,8 +260,6 @@ void cu_prermremove(int argc, void **argv);
 
 void print_error_perpackage(const char *emsg, const void *data);
 void print_error_perarchive(const char *emsg, const void *data);
-void forcibleerr(int forceflag, const char *format, ...) DPKG_ATTR_PRINTF(2);
-int forcible_nonroot_error(int rc);
 int reportbroken_retexitstatus(int ret);
 bool skip_due_to_hold(struct pkginfo *pkg);
 

-- 
Dpkg.Org's dpkg

Reply via email to