errors.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * dpkg - main program for package management
  3. * errors.c - per package error handling
  4. *
  5. * Copyright © 1994,1995 Ian Jackson <ian@chiark.greenend.org.uk>
  6. *
  7. * This is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include <config.h>
  21. #include <compat.h>
  22. #include <sys/types.h>
  23. #include <sys/stat.h>
  24. #include <sys/wait.h>
  25. #include <errno.h>
  26. #include <limits.h>
  27. #include <ctype.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/myopt.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. const char *what;
  43. };
  44. static struct error_report *reports = NULL;
  45. static struct error_report **lastreport= &reports;
  46. static struct error_report emergency;
  47. void print_error_perpackage(const char *emsg, const char *arg) {
  48. struct error_report *nr;
  49. fprintf(stderr, _("%s: error processing %s (--%s):\n %s\n"),
  50. DPKG, arg, cipaction->olong, emsg);
  51. statusfd_send("status: %s : %s : %s", arg, "error", emsg);
  52. nr= malloc(sizeof(struct error_report));
  53. if (!nr) {
  54. perror(_("dpkg: failed to allocate memory for new entry in list of failed packages."));
  55. abort_processing = true;
  56. nr= &emergency;
  57. }
  58. nr->what= arg;
  59. nr->next = NULL;
  60. *lastreport= nr;
  61. lastreport= &nr->next;
  62. if (nerrs++ < errabort) return;
  63. fprintf(stderr, _("dpkg: too many errors, stopping\n"));
  64. abort_processing = true;
  65. }
  66. int reportbroken_retexitstatus(void) {
  67. if (reports) {
  68. fputs(_("Errors were encountered while processing:\n"),stderr);
  69. while (reports) {
  70. fprintf(stderr," %s\n",reports->what);
  71. reports= reports->next;
  72. }
  73. }
  74. if (abort_processing) {
  75. fputs(_("Processing was halted because there were too many errors.\n"),stderr);
  76. }
  77. return nerrs ? 1 : 0;
  78. }
  79. bool
  80. skip_due_to_hold(struct pkginfo *pkg)
  81. {
  82. if (pkg->want != want_hold)
  83. return false;
  84. if (fc_hold) {
  85. fprintf(stderr, _("Package %s was on hold, processing it anyway as you requested\n"),
  86. pkg->name);
  87. return false;
  88. }
  89. printf(_("Package %s is on hold, not touching it. Use --force-hold to override.\n"),
  90. pkg->name);
  91. return true;
  92. }
  93. void forcibleerr(int forceflag, const char *fmt, ...) {
  94. va_list args;
  95. va_start(args, fmt);
  96. if (forceflag) {
  97. warning(_("overriding problem because --force enabled:"));
  98. fputc(' ', stderr);
  99. vfprintf(stderr, fmt, args);
  100. fputc('\n',stderr);
  101. } else {
  102. ohshitv(fmt, args);
  103. }
  104. va_end(args);
  105. }