errors.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * dpkg - main program for package management
  3. * main.c - main program
  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
  9. * published by the Free Software Foundation; either version 2,
  10. * or (at your option) any later version.
  11. *
  12. * This is distributed in the hope that it will be useful, but
  13. * 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
  18. * License along with dpkg; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #include <config.h>
  22. #include <compat.h>
  23. #include <dpkg-i18n.h>
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include <stdlib.h>
  27. #include <signal.h>
  28. #include <sys/stat.h>
  29. #include <sys/types.h>
  30. #include <sys/wait.h>
  31. #include <errno.h>
  32. #include <unistd.h>
  33. #include <dirent.h>
  34. #include <limits.h>
  35. #include <ctype.h>
  36. #include <dpkg.h>
  37. #include <dpkg-db.h>
  38. #include <myopt.h>
  39. #include "main.h"
  40. int abort_processing = 0;
  41. static int nerrs = 0;
  42. struct error_report {
  43. struct error_report *next;
  44. const char *what;
  45. };
  46. static struct error_report *reports = NULL;
  47. static struct error_report **lastreport= &reports;
  48. static struct error_report emergency;
  49. void print_error_perpackage(const char *emsg, const char *arg) {
  50. struct error_report *nr;
  51. fprintf(stderr, _("%s: error processing %s (--%s):\n %s\n"),
  52. DPKG, arg, cipaction->olong, emsg);
  53. statusfd_send("status: %s : %s : %s", arg, "error", emsg);
  54. nr= malloc(sizeof(struct error_report));
  55. if (!nr) {
  56. perror(_("dpkg: failed to allocate memory for new entry in list of failed packages."));
  57. abort_processing = 1;
  58. nr= &emergency;
  59. }
  60. nr->what= arg;
  61. nr->next = NULL;
  62. *lastreport= nr;
  63. lastreport= &nr->next;
  64. if (nerrs++ < errabort) return;
  65. fprintf(stderr, _("dpkg: too many errors, stopping\n"));
  66. abort_processing = 1;
  67. }
  68. int reportbroken_retexitstatus(void) {
  69. if (reports) {
  70. fputs(_("Errors were encountered while processing:\n"),stderr);
  71. while (reports) {
  72. fprintf(stderr," %s\n",reports->what);
  73. reports= reports->next;
  74. }
  75. }
  76. if (abort_processing) {
  77. fputs(_("Processing was halted because there were too many errors.\n"),stderr);
  78. }
  79. return nerrs ? 1 : 0;
  80. }
  81. int skip_due_to_hold(struct pkginfo *pkg) {
  82. if (pkg->want != want_hold) return 0;
  83. if (fc_hold) {
  84. fprintf(stderr, _("Package %s was on hold, processing it anyway as you request\n"),
  85. pkg->name);
  86. return 0;
  87. }
  88. printf(_("Package %s is on hold, not touching it. Use --force-hold to override.\n"),
  89. pkg->name);
  90. return 1;
  91. }
  92. void forcibleerr(int forceflag, const char *fmt, ...) {
  93. va_list al;
  94. va_start(al,fmt);
  95. if (forceflag) {
  96. warning(_("overriding problem because --force enabled:"));
  97. fputc(' ', stderr);
  98. vfprintf(stderr,fmt,al);
  99. fputc('\n',stderr);
  100. } else {
  101. ohshitv(fmt,al);
  102. }
  103. va_end(al);
  104. }