errors.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * dpkg - main program for package management
  3. * errors.c - per package error handling
  4. *
  5. * Copyright © 1994,1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
  6. * Copyright © 2007-2014 Guillem Jover <guillem@debian.org>
  7. *
  8. * This is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. #include <config.h>
  22. #include <compat.h>
  23. #include <sys/types.h>
  24. #include <sys/stat.h>
  25. #include <sys/wait.h>
  26. #include <errno.h>
  27. #include <limits.h>
  28. #include <string.h>
  29. #include <dirent.h>
  30. #include <unistd.h>
  31. #include <stdlib.h>
  32. #include <stdio.h>
  33. #include <dpkg/i18n.h>
  34. #include <dpkg/dpkg.h>
  35. #include <dpkg/dpkg-db.h>
  36. #include <dpkg/options.h>
  37. #include "main.h"
  38. bool abort_processing = false;
  39. static int nerrs = 0;
  40. struct error_report {
  41. struct error_report *next;
  42. char *what;
  43. };
  44. static struct error_report *reports = NULL;
  45. static struct error_report **lastreport= &reports;
  46. static struct error_report emergency;
  47. static void
  48. enqueue_error_report(const char *arg)
  49. {
  50. struct error_report *nr;
  51. nr= malloc(sizeof(struct error_report));
  52. if (!nr) {
  53. notice(_("failed to allocate memory for new entry in list of failed packages: %s"),
  54. strerror(errno));
  55. abort_processing = true;
  56. nr= &emergency;
  57. }
  58. nr->what = m_strdup(arg);
  59. nr->next = NULL;
  60. *lastreport= nr;
  61. lastreport= &nr->next;
  62. if (nerrs++ < errabort) return;
  63. notice(_("too many errors, stopping"));
  64. abort_processing = true;
  65. }
  66. void
  67. print_error_perpackage(const char *emsg, const void *data)
  68. {
  69. const char *pkgname = data;
  70. notice(_("error processing package %s (--%s):\n %s"),
  71. pkgname, cipaction->olong, emsg);
  72. statusfd_send("status: %s : %s : %s", pkgname, "error", emsg);
  73. enqueue_error_report(pkgname);
  74. }
  75. void
  76. print_error_perarchive(const char *emsg, const void *data)
  77. {
  78. const char *filename = data;
  79. notice(_("error processing archive %s (--%s):\n %s"),
  80. filename, cipaction->olong, emsg);
  81. statusfd_send("status: %s : %s : %s", filename, "error", emsg);
  82. enqueue_error_report(filename);
  83. }
  84. int
  85. reportbroken_retexitstatus(int ret)
  86. {
  87. if (reports) {
  88. fputs(_("Errors were encountered while processing:\n"),stderr);
  89. while (reports) {
  90. fprintf(stderr," %s\n",reports->what);
  91. free(reports->what);
  92. reports= reports->next;
  93. }
  94. }
  95. if (abort_processing) {
  96. fputs(_("Processing was halted because there were too many errors.\n"),stderr);
  97. }
  98. return nerrs ? 1 : ret;
  99. }
  100. bool
  101. skip_due_to_hold(struct pkginfo *pkg)
  102. {
  103. if (pkg->want != PKG_WANT_HOLD)
  104. return false;
  105. if (fc_hold) {
  106. notice(_("package %s was on hold, processing it anyway as you requested"),
  107. pkg_name(pkg, pnaw_nonambig));
  108. return false;
  109. }
  110. printf(_("Package %s is on hold, not touching it. Use --force-hold to override.\n"),
  111. pkg_name(pkg, pnaw_nonambig));
  112. return true;
  113. }
  114. void forcibleerr(int forceflag, const char *fmt, ...) {
  115. va_list args;
  116. va_start(args, fmt);
  117. if (forceflag) {
  118. warning(_("overriding problem because --force enabled:"));
  119. warningv(fmt, args);
  120. } else {
  121. ohshitv(fmt, args);
  122. }
  123. va_end(args);
  124. }