errors.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * dpkg - main program for package management
  3. * main.c - main program
  4. *
  5. * Copyright (C) 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 <stdio.h>
  23. #include <string.h>
  24. #include <stdlib.h>
  25. #include <signal.h>
  26. #include <sys/stat.h>
  27. #include <sys/types.h>
  28. #include <sys/wait.h>
  29. #include <errno.h>
  30. #include <unistd.h>
  31. #include <dirent.h>
  32. #include <limits.h>
  33. #include <ctype.h>
  34. #include <dpkg.h>
  35. #include <dpkg-db.h>
  36. #include <myopt.h>
  37. #include "main.h"
  38. int nerrs= 0;
  39. struct error_report {
  40. struct error_report *next;
  41. const char *what;
  42. };
  43. static struct error_report *reports=0;
  44. static struct error_report **lastreport= &reports;
  45. static struct error_report emergency;
  46. extern struct pipef *status_pipes;
  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. if (status_pipes) {
  52. static struct varbuf *status= NULL;
  53. struct pipef *pipef= status_pipes;
  54. int r;
  55. if (status == NULL) {
  56. status = nfmalloc(sizeof(struct varbuf));
  57. varbufinit(status);
  58. } else
  59. varbufreset(status);
  60. r= varbufprintf(status, "status: %s : %s : %s\n", arg, "error",emsg);
  61. while (pipef) {
  62. write(pipef->fd, status->buf, r);
  63. pipef= pipef->next;
  64. }
  65. }
  66. nr= malloc(sizeof(struct error_report));
  67. if (!nr) {
  68. perror(_("dpkg: failed to allocate memory for new entry in list of failed packages."));
  69. onerr_abort++;
  70. nr= &emergency;
  71. }
  72. nr->what= arg;
  73. nr->next= 0;
  74. *lastreport= nr;
  75. lastreport= &nr->next;
  76. if (nerrs++ < errabort) return;
  77. fprintf(stderr, _("dpkg: too many errors, stopping\n"));
  78. onerr_abort++;
  79. }
  80. int reportbroken_retexitstatus(void) {
  81. if (reports) {
  82. fputs(_("Errors were encountered while processing:\n"),stderr);
  83. while (reports) {
  84. fprintf(stderr," %s\n",reports->what);
  85. reports= reports->next;
  86. }
  87. }
  88. if (onerr_abort) {
  89. fputs(_("Processing was halted because there were too many errors.\n"),stderr);
  90. }
  91. return nerrs || onerr_abort ? 1 : 0;
  92. }
  93. int skip_due_to_hold(struct pkginfo *pkg) {
  94. if (pkg->want != want_hold) return 0;
  95. if (fc_hold) {
  96. fprintf(stderr, _("Package %s was on hold, processing it anyway as you request\n"),
  97. pkg->name);
  98. return 0;
  99. }
  100. printf(_("Package %s is on hold, not touching it. Use --force-hold to override.\n"),
  101. pkg->name);
  102. return 1;
  103. }
  104. void forcibleerr(int forceflag, const char *fmt, ...) {
  105. va_list al;
  106. va_start(al,fmt);
  107. if (forceflag) {
  108. fputs(_("dpkg - warning, overriding problem because --force enabled:\n "),stderr);
  109. vfprintf(stderr,fmt,al);
  110. fputc('\n',stderr);
  111. } else {
  112. ohshitv(fmt,al);
  113. }
  114. va_end(al);
  115. }