Branch data Line data Source code
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 : :
22 : : #include <config.h>
23 : : #include <compat.h>
24 : :
25 : : #include <sys/types.h>
26 : : #include <sys/stat.h>
27 : : #include <sys/wait.h>
28 : :
29 : : #include <errno.h>
30 : : #include <limits.h>
31 : : #include <string.h>
32 : : #include <dirent.h>
33 : : #include <unistd.h>
34 : : #include <stdlib.h>
35 : : #include <stdio.h>
36 : :
37 : : #include <dpkg/i18n.h>
38 : : #include <dpkg/dpkg.h>
39 : : #include <dpkg/dpkg-db.h>
40 : : #include <dpkg/options.h>
41 : :
42 : : #include "main.h"
43 : :
44 : : bool abort_processing = false;
45 : :
46 : : static int nerrs = 0;
47 : :
48 : : struct error_report {
49 : : struct error_report *next;
50 : : char *what;
51 : : };
52 : :
53 : : static struct error_report *reports = NULL;
54 : : static struct error_report **lastreport= &reports;
55 : : static struct error_report emergency;
56 : :
57 : : static void
58 : 0 : enqueue_error_report(const char *arg)
59 : : {
60 : : struct error_report *nr;
61 : :
62 : 0 : nr = malloc(sizeof(*nr));
63 [ # # ]: 0 : if (!nr) {
64 : 0 : notice(_("failed to allocate memory for new entry in list of failed packages: %s"),
65 : 0 : strerror(errno));
66 : 0 : abort_processing = true;
67 : 0 : nr= &emergency;
68 : : }
69 : 0 : nr->what = m_strdup(arg);
70 : 0 : nr->next = NULL;
71 : 0 : *lastreport= nr;
72 : 0 : lastreport= &nr->next;
73 : :
74 [ # # ]: 0 : if (++nerrs < errabort)
75 : 0 : return;
76 : 0 : notice(_("too many errors, stopping"));
77 : 0 : abort_processing = true;
78 : : }
79 : :
80 : : void
81 : 0 : print_error_perpackage(const char *emsg, const void *data)
82 : : {
83 : 0 : const char *pkgname = data;
84 : :
85 : 0 : notice(_("error processing package %s (--%s):\n %s"),
86 : 0 : pkgname, cipaction->olong, emsg);
87 : :
88 : 0 : statusfd_send("status: %s : %s : %s", pkgname, "error", emsg);
89 : :
90 : 0 : enqueue_error_report(pkgname);
91 : 0 : }
92 : :
93 : : void
94 : 0 : print_error_perarchive(const char *emsg, const void *data)
95 : : {
96 : 0 : const char *filename = data;
97 : :
98 : 0 : notice(_("error processing archive %s (--%s):\n %s"),
99 : 0 : filename, cipaction->olong, emsg);
100 : :
101 : 0 : statusfd_send("status: %s : %s : %s", filename, "error", emsg);
102 : :
103 : 0 : enqueue_error_report(filename);
104 : 0 : }
105 : :
106 : : int
107 : 48 : reportbroken_retexitstatus(int ret)
108 : : {
109 [ - + ]: 48 : if (reports) {
110 : 0 : fputs(_("Errors were encountered while processing:\n"),stderr);
111 [ # # ]: 0 : while (reports) {
112 : 0 : fprintf(stderr," %s\n",reports->what);
113 : 0 : free(reports->what);
114 : 0 : reports= reports->next;
115 : : }
116 : : }
117 [ - + ]: 48 : if (abort_processing) {
118 : 0 : fputs(_("Processing was halted because there were too many errors.\n"),stderr);
119 : : }
120 [ + - ]: 48 : return nerrs ? 1 : ret;
121 : : }
122 : :
123 : : bool
124 : 0 : skip_due_to_hold(struct pkginfo *pkg)
125 : : {
126 [ # # ]: 0 : if (pkg->want != PKG_WANT_HOLD)
127 : 0 : return false;
128 [ # # ]: 0 : if (in_force(FORCE_HOLD)) {
129 : 0 : notice(_("package %s was on hold, processing it anyway as you requested"),
130 : : pkg_name(pkg, pnaw_nonambig));
131 : 0 : return false;
132 : : }
133 : 0 : printf(_("Package %s is on hold, not touching it. Use --force-hold to override.\n"),
134 : : pkg_name(pkg, pnaw_nonambig));
135 : 0 : return true;
136 : : }
137 : :
|