Branch data Line data Source code
1 : : /*
2 : : * dpkg - main program for package management
3 : : * packages.c - common to actions that process packages
4 : : *
5 : : * Copyright © 1994,1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
6 : : * Copyright © 2006-2014 Guillem Jover <guillem@debian.org>
7 : : * Copyright © 2011 Linaro Limited
8 : : * Copyright © 2011 Raphaël Hertzog <hertzog@debian.org>
9 : : *
10 : : * This is free software; you can redistribute it and/or modify
11 : : * it under the terms of the GNU General Public License as published by
12 : : * the Free Software Foundation; either version 2 of the License, or
13 : : * (at your option) any later version.
14 : : *
15 : : * This is distributed in the hope that it will be useful,
16 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 : : * GNU General Public License for more details.
19 : : *
20 : : * You should have received a copy of the GNU General Public License
21 : : * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 : : */
23 : :
24 : : #include <config.h>
25 : : #include <compat.h>
26 : :
27 : : #include <sys/types.h>
28 : : #include <sys/stat.h>
29 : :
30 : : #include <string.h>
31 : : #include <fcntl.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/pkg-list.h>
41 : : #include <dpkg/pkg-queue.h>
42 : : #include <dpkg/string.h>
43 : : #include <dpkg/options.h>
44 : : #include <dpkg/db-ctrl.h>
45 : : #include <dpkg/db-fsys.h>
46 : :
47 : : #include "main.h"
48 : :
49 : : static struct pkginfo *progress_bytrigproc;
50 : : static struct pkg_queue queue = PKG_QUEUE_INIT;
51 : :
52 : : enum dependtry dependtry = DEPEND_TRY_NORMAL;
53 : : int sincenothing = 0;
54 : :
55 : : void
56 : 0 : enqueue_package(struct pkginfo *pkg)
57 : : {
58 : 0 : ensure_package_clientdata(pkg);
59 [ # # ]: 0 : if (pkg->clientdata->enqueued)
60 : 0 : return;
61 : 0 : pkg->clientdata->enqueued = true;
62 : 0 : pkg_queue_push(&queue, pkg);
63 : : }
64 : :
65 : : void
66 : 0 : enqueue_package_mark_seen(struct pkginfo *pkg)
67 : : {
68 : 0 : enqueue_package(pkg);
69 : 0 : pkg->clientdata->cmdline_seen++;
70 : 0 : }
71 : :
72 : : static void
73 : 0 : enqueue_pending(void)
74 : : {
75 : : struct pkg_hash_iter *iter;
76 : : struct pkginfo *pkg;
77 : :
78 : 0 : iter = pkg_hash_iter_new();
79 [ # # ]: 0 : while ((pkg = pkg_hash_iter_next_pkg(iter)) != NULL) {
80 [ # # # # ]: 0 : switch (cipaction->arg_int) {
81 : 0 : case act_configure:
82 [ # # ]: 0 : if (!(pkg->status == PKG_STAT_UNPACKED ||
83 [ # # ]: 0 : pkg->status == PKG_STAT_HALFCONFIGURED ||
84 [ # # ]: 0 : pkg->trigpend_head))
85 : 0 : continue;
86 [ # # ]: 0 : if (pkg->want != PKG_WANT_INSTALL &&
87 [ # # ]: 0 : pkg->want != PKG_WANT_HOLD)
88 : 0 : continue;
89 : 0 : break;
90 : 0 : case act_triggers:
91 [ # # ]: 0 : if (!pkg->trigpend_head)
92 : 0 : continue;
93 [ # # ]: 0 : if (pkg->want != PKG_WANT_INSTALL &&
94 [ # # ]: 0 : pkg->want != PKG_WANT_HOLD)
95 : 0 : continue;
96 : 0 : break;
97 : 0 : case act_remove:
98 : : case act_purge:
99 [ # # ]: 0 : if (pkg->want != PKG_WANT_PURGE) {
100 [ # # ]: 0 : if (pkg->want != PKG_WANT_DEINSTALL)
101 : 0 : continue;
102 [ # # ]: 0 : if (pkg->status == PKG_STAT_CONFIGFILES)
103 : 0 : continue;
104 : : }
105 [ # # ]: 0 : if (pkg->status == PKG_STAT_NOTINSTALLED)
106 : 0 : continue;
107 : 0 : break;
108 : 0 : default:
109 : 0 : internerr("unknown action '%d'", cipaction->arg_int);
110 : : }
111 : 0 : enqueue_package(pkg);
112 : : }
113 : 0 : pkg_hash_iter_free(iter);
114 : 0 : }
115 : :
116 : : static void
117 : 0 : enqueue_specified(const char *const *argv)
118 : : {
119 : : const char *thisarg;
120 : :
121 [ # # ]: 0 : while ((thisarg = *argv++) != NULL) {
122 : : struct pkginfo *pkg;
123 : :
124 : 0 : pkg = dpkg_options_parse_pkgname(cipaction, thisarg);
125 [ # # # # ]: 0 : if (pkg->status == PKG_STAT_NOTINSTALLED &&
126 : 0 : str_match_end(pkg->set->name, DEBEXT)) {
127 : 0 : badusage(_("you must specify packages by their own names, "
128 : : "not by quoting the names of the files they come in"));
129 : : }
130 : 0 : enqueue_package_mark_seen(pkg);
131 : : }
132 : :
133 [ # # ]: 0 : if (cipaction->arg_int == act_configure)
134 : 0 : trigproc_populate_deferred();
135 : 0 : }
136 : :
137 : : int
138 : 0 : packages(const char *const *argv)
139 : : {
140 : 0 : trigproc_install_hooks();
141 : :
142 [ # # # # ]: 0 : modstatdb_open(f_noact ? msdbrw_readonly :
143 : 0 : in_force(FORCE_NON_ROOT) ? msdbrw_write :
144 : : msdbrw_needsuperuser);
145 : 0 : checkpath();
146 : 0 : pkg_infodb_upgrade();
147 : :
148 : 0 : log_message("startup packages %s", cipaction->olong);
149 : :
150 [ # # ]: 0 : if (f_pending) {
151 [ # # ]: 0 : if (*argv)
152 : 0 : badusage(_("--%s --pending does not take any non-option arguments"),cipaction->olong);
153 : :
154 : 0 : enqueue_pending();
155 : : } else {
156 [ # # ]: 0 : if (!*argv)
157 : 0 : badusage(_("--%s (without --pending) needs at least one package name argument"),
158 : 0 : cipaction->olong);
159 : :
160 : 0 : enqueue_specified(argv);
161 : : }
162 : :
163 : 0 : ensure_diversions();
164 : :
165 : 0 : process_queue();
166 : 0 : trigproc_run_deferred();
167 : :
168 : 0 : modstatdb_shutdown();
169 : :
170 : 0 : return 0;
171 : : }
172 : :
173 : 0 : void process_queue(void) {
174 : : struct pkg_list *rundown;
175 : : volatile enum action action_todo;
176 : : jmp_buf ejbuf;
177 : 0 : enum pkg_istobe istobe = PKG_ISTOBE_NORMAL;
178 : :
179 [ # # ]: 0 : if (abort_processing)
180 : 0 : return;
181 : :
182 : 0 : clear_istobes();
183 : :
184 [ # # # ]: 0 : switch (cipaction->arg_int) {
185 : 0 : case act_triggers:
186 : : case act_configure:
187 : : case act_install:
188 : 0 : istobe = PKG_ISTOBE_INSTALLNEW;
189 : 0 : break;
190 : 0 : case act_remove:
191 : : case act_purge:
192 : 0 : istobe = PKG_ISTOBE_REMOVE;
193 : 0 : break;
194 : 0 : default:
195 : 0 : internerr("unknown action '%d'", cipaction->arg_int);
196 : : }
197 [ # # ]: 0 : for (rundown = queue.head; rundown; rundown = rundown->next) {
198 : 0 : ensure_package_clientdata(rundown->pkg);
199 : :
200 : : /* We have processed this package more than once. There are no duplicates
201 : : * as we make sure of that when enqueuing them. */
202 [ # # ]: 0 : if (rundown->pkg->clientdata->cmdline_seen > 1) {
203 [ # # # ]: 0 : switch (cipaction->arg_int) {
204 : 0 : case act_triggers:
205 : : case act_configure: case act_remove: case act_purge:
206 : 0 : printf(_("Package %s listed more than once, only processing once.\n"),
207 : : pkg_name(rundown->pkg, pnaw_nonambig));
208 : 0 : break;
209 : 0 : case act_install:
210 : 0 : printf(_("More than one copy of package %s has been unpacked\n"
211 : : " in this run ! Only configuring it once.\n"),
212 : : pkg_name(rundown->pkg, pnaw_nonambig));
213 : 0 : break;
214 : 0 : default:
215 : 0 : internerr("unknown action '%d'", cipaction->arg_int);
216 : : }
217 : : }
218 : 0 : rundown->pkg->clientdata->istobe = istobe;
219 : : }
220 : :
221 [ # # ]: 0 : while (!pkg_queue_is_empty(&queue)) {
222 : : struct pkginfo *volatile pkg;
223 : :
224 : 0 : pkg = pkg_queue_pop(&queue);
225 [ # # ]: 0 : if (!pkg)
226 : 0 : continue; /* Duplicate, which we removed earlier. */
227 : :
228 : 0 : ensure_package_clientdata(pkg);
229 : 0 : pkg->clientdata->enqueued = false;
230 : :
231 : 0 : action_todo = cipaction->arg_int;
232 : :
233 [ # # ]: 0 : if (sincenothing++ > queue.length * 3 + 2) {
234 : : /* Make sure that even if we have exceeded the queue since not having
235 : : * made any progress, we are not getting stuck trying to progress by
236 : : * trigger processing, w/o jumping into the next dependtry. */
237 : 0 : dependtry++;
238 : 0 : sincenothing = 0;
239 [ # # ]: 0 : if (dependtry >= DEPEND_TRY_LAST)
240 : 0 : internerr("exceeded dependtry %d (sincenothing=%d; queue.length=%d)",
241 : : dependtry, sincenothing, queue.length);
242 [ # # ]: 0 : } else if (sincenothing > queue.length * 2 + 2) {
243 [ # # # # ]: 0 : if (dependtry >= DEPEND_TRY_TRIGGERS &&
244 [ # # ]: 0 : progress_bytrigproc && progress_bytrigproc->trigpend_head) {
245 : 0 : enqueue_package(pkg);
246 : 0 : pkg = progress_bytrigproc;
247 : 0 : progress_bytrigproc = NULL;
248 : 0 : action_todo = act_configure;
249 : : } else {
250 : 0 : dependtry++;
251 : 0 : sincenothing = 0;
252 [ # # ]: 0 : if (dependtry >= DEPEND_TRY_LAST)
253 : 0 : internerr("exceeded dependtry %d (sincenothing=%d, queue.length=%d)",
254 : : dependtry, sincenothing, queue.length);
255 : : }
256 : : }
257 : :
258 : 0 : debug(dbg_general, "process queue pkg %s queue.len %d progress %d, try %d",
259 : : pkg_name(pkg, pnaw_always), queue.length, sincenothing, dependtry);
260 : :
261 [ # # ]: 0 : if (pkg->status > PKG_STAT_INSTALLED)
262 : 0 : internerr("package %s status %d is out-of-bounds",
263 : : pkg_name(pkg, pnaw_always), pkg->status);
264 : :
265 [ # # ]: 0 : if (setjmp(ejbuf)) {
266 : : /* Give up on it from the point of view of other packages, i.e. reset
267 : : * istobe. */
268 : 0 : pkg->clientdata->istobe = PKG_ISTOBE_NORMAL;
269 : :
270 : 0 : pop_error_context(ehflag_bombout);
271 [ # # ]: 0 : if (abort_processing)
272 : 0 : return;
273 : 0 : continue;
274 : : }
275 : 0 : push_error_context_jump(&ejbuf, print_error_perpackage,
276 : 0 : pkg_name(pkg, pnaw_nonambig));
277 : :
278 [ # # # # : 0 : switch (action_todo) {
# ]
279 : 0 : case act_triggers:
280 [ # # ]: 0 : if (!pkg->trigpend_head)
281 : 0 : ohshit(_("package %.250s is not ready for trigger processing\n"
282 : : " (current status '%.250s' with no pending triggers)"),
283 : : pkg_name(pkg, pnaw_nonambig), pkg_status_name(pkg));
284 : : /* Fall through. */
285 : : case act_install:
286 : : /* Don't try to configure pkgs that we've just disappeared. */
287 [ # # ]: 0 : if (pkg->status == PKG_STAT_NOTINSTALLED)
288 : 0 : break;
289 : : /* Fall through. */
290 : : case act_configure:
291 : : /* Do whatever is most needed. */
292 [ # # ]: 0 : if (pkg->trigpend_head)
293 : 0 : trigproc(pkg, TRIGPROC_TRY_QUEUED);
294 : : else
295 : 0 : deferred_configure(pkg);
296 : 0 : break;
297 : 0 : case act_remove: case act_purge:
298 : 0 : deferred_remove(pkg);
299 : 0 : break;
300 : 0 : default:
301 : 0 : internerr("unknown action '%d'", cipaction->arg_int);
302 : : }
303 : 0 : m_output(stdout, _("<standard output>"));
304 : 0 : m_output(stderr, _("<standard error>"));
305 : :
306 : 0 : pop_error_context(ehflag_normaltidy);
307 : : }
308 : :
309 [ # # ]: 0 : if (queue.length)
310 : 0 : internerr("finished package processing with non-empty queue length %d",
311 : : queue.length);
312 : : }
313 : :
314 : : /*** Dependency processing - common to --configure and --remove. ***/
315 : :
316 : : /*
317 : : * The algorithm for deciding what to configure or remove first is as
318 : : * follows:
319 : : *
320 : : * Loop through all packages doing a ‘try 1’ until we've been round and
321 : : * nothing has been done, then do ‘try 2’ and ‘try 3’ likewise.
322 : : *
323 : : * When configuring, in each try we check to see whether all
324 : : * dependencies of this package are done. If so we do it. If some of
325 : : * the dependencies aren't done yet but will be later we defer the
326 : : * package, otherwise it is an error.
327 : : *
328 : : * When removing, in each try we check to see whether there are any
329 : : * packages that would have dependencies missing if we removed this
330 : : * one. If not we remove it now. If some of these packages are
331 : : * themselves scheduled for removal we defer the package until they
332 : : * have been done.
333 : : *
334 : : * The criteria for satisfying a dependency vary with the various
335 : : * tries. In try 1 we treat the dependencies as absolute. In try 2 we
336 : : * check break any cycles in the dependency graph involving the package
337 : : * we are trying to process before trying to process the package
338 : : * normally. In try 3 (which should only be reached if
339 : : * --force-depends-version is set) we ignore version number clauses in
340 : : * Depends lines. In try 4 (only reached if --force-depends is set) we
341 : : * say "ok" regardless.
342 : : *
343 : : * If we are configuring and one of the packages we depend on is
344 : : * awaiting configuration but wasn't specified in the argument list we
345 : : * will add it to the argument list if --configure-any is specified.
346 : : * In this case we note this as having "done something" so that we
347 : : * don't needlessly escalate to higher levels of dependency checking
348 : : * and breaking.
349 : : */
350 : :
351 : : enum found_status {
352 : : FOUND_NONE = 0,
353 : : FOUND_DEFER = 1,
354 : : FOUND_FORCED = 2,
355 : : FOUND_OK = 3,
356 : : };
357 : :
358 : : static enum found_status
359 : 0 : found_forced_on(enum dependtry dependtry_forced)
360 : : {
361 [ # # ]: 0 : if (dependtry >= dependtry_forced)
362 : 0 : return FOUND_FORCED;
363 : : else
364 : 0 : return FOUND_DEFER;
365 : : }
366 : :
367 : : /*
368 : : * Return values:
369 : : * 0: cannot be satisfied.
370 : : * 1: defer: may be satisfied later, when other packages are better or
371 : : * at higher dependtry due to --force
372 : : * will set *fixbytrig to package whose trigger processing would help
373 : : * if applicable (and leave it alone otherwise).
374 : : * 2: not satisfied but forcing
375 : : * (*interestingwarnings >= 0 on exit? caller is to print oemsgs).
376 : : * 3: satisfied now.
377 : : */
378 : : static enum found_status
379 : 0 : deppossi_ok_found(struct pkginfo *possdependee, struct pkginfo *requiredby,
380 : : struct pkginfo *removing, struct deppossi *provider,
381 : : struct pkginfo **fixbytrig,
382 : : bool *matched, struct deppossi *checkversion,
383 : : int *interestingwarnings, struct varbuf *oemsgs)
384 : : {
385 : : enum found_status thisf;
386 : :
387 [ # # ]: 0 : if (ignore_depends(possdependee)) {
388 : 0 : debug(dbg_depcondetail," ignoring depended package so ok and found");
389 : 0 : return FOUND_OK;
390 : : }
391 : 0 : thisf = FOUND_NONE;
392 [ # # ]: 0 : if (possdependee == removing) {
393 [ # # ]: 0 : if (provider) {
394 : 0 : varbuf_printf(oemsgs,
395 : 0 : _(" Package %s which provides %s is to be removed.\n"),
396 : : pkg_name(possdependee, pnaw_nonambig),
397 : 0 : provider->ed->name);
398 : : } else {
399 : 0 : varbuf_printf(oemsgs, _(" Package %s is to be removed.\n"),
400 : : pkg_name(possdependee, pnaw_nonambig));
401 : : }
402 : :
403 : 0 : *matched = true;
404 : 0 : debug(dbg_depcondetail," removing possdependee, returning %d",thisf);
405 : 0 : return thisf;
406 : : }
407 [ # # ]: 0 : switch (possdependee->status) {
408 : 0 : case PKG_STAT_UNPACKED:
409 : : case PKG_STAT_HALFCONFIGURED:
410 : : case PKG_STAT_TRIGGERSAWAITED:
411 : : case PKG_STAT_TRIGGERSPENDING:
412 : : case PKG_STAT_INSTALLED:
413 [ # # ]: 0 : if (checkversion) {
414 [ # # ]: 0 : if (provider) {
415 : 0 : debug(dbg_depcondetail, " checking package %s provided by pkg %s",
416 : 0 : checkversion->ed->name, pkg_name(possdependee, pnaw_always));
417 [ # # ]: 0 : if (!pkg_virtual_deppossi_satisfied(checkversion, provider)) {
418 : 0 : varbuf_printf(oemsgs,
419 : 0 : _(" Version of %s on system, provided by %s, is %s.\n"),
420 : 0 : checkversion->ed->name,
421 : : pkg_name(possdependee, pnaw_always),
422 : 0 : versiondescribe(&provider->version, vdew_nonambig));
423 [ # # ]: 0 : if (in_force(FORCE_DEPENDS_VERSION))
424 : 0 : thisf = found_forced_on(DEPEND_TRY_FORCE_DEPENDS_VERSION);
425 : 0 : debug(dbg_depcondetail, " bad version");
426 : 0 : goto unsuitable;
427 : : }
428 : : } else {
429 : 0 : debug(dbg_depcondetail, " checking non-provided pkg %s",
430 : : pkg_name(possdependee, pnaw_always));
431 [ # # ]: 0 : if (!versionsatisfied(&possdependee->installed, checkversion)) {
432 : 0 : varbuf_printf(oemsgs, _(" Version of %s on system is %s.\n"),
433 : : pkg_name(possdependee, pnaw_nonambig),
434 : 0 : versiondescribe(&possdependee->installed.version,
435 : : vdew_nonambig));
436 [ # # ]: 0 : if (in_force(FORCE_DEPENDS_VERSION))
437 : 0 : thisf = found_forced_on(DEPEND_TRY_FORCE_DEPENDS_VERSION);
438 : 0 : debug(dbg_depcondetail, " bad version");
439 : 0 : goto unsuitable;
440 : : }
441 : : }
442 : : }
443 [ # # ]: 0 : if (possdependee->status == PKG_STAT_INSTALLED ||
444 [ # # ]: 0 : possdependee->status == PKG_STAT_TRIGGERSPENDING) {
445 : 0 : debug(dbg_depcondetail," is installed, ok and found");
446 : 0 : return FOUND_OK;
447 : : }
448 [ # # ]: 0 : if (possdependee->status == PKG_STAT_TRIGGERSAWAITED) {
449 [ # # ]: 0 : if (possdependee->trigaw.head == NULL)
450 : 0 : internerr("package %s in state %s, has no awaited triggers",
451 : : pkg_name(possdependee, pnaw_always),
452 : : pkg_status_name(possdependee));
453 : :
454 [ # # ]: 0 : if (removing ||
455 [ # # ]: 0 : !(f_triggers ||
456 [ # # ]: 0 : (possdependee->clientdata &&
457 [ # # ]: 0 : possdependee->clientdata->istobe == PKG_ISTOBE_INSTALLNEW))) {
458 [ # # ]: 0 : if (provider) {
459 : 0 : varbuf_printf(oemsgs,
460 : 0 : _(" Package %s which provides %s awaits trigger processing.\n"),
461 : : pkg_name(possdependee, pnaw_nonambig),
462 : 0 : provider->ed->name);
463 : : } else {
464 : 0 : varbuf_printf(oemsgs,
465 : 0 : _(" Package %s awaits trigger processing.\n"),
466 : : pkg_name(possdependee, pnaw_nonambig));
467 : : }
468 : 0 : debug(dbg_depcondetail, " triggers-awaited, no fixbytrig");
469 : 0 : goto unsuitable;
470 : : }
471 : : /* We don't check the status of trigaw.head->pend here, just in case
472 : : * we get into the pathological situation where Triggers-Awaited but
473 : : * the named package doesn't actually have any pending triggers. In
474 : : * that case we queue the non-pending package for trigger processing
475 : : * anyway, and that trigger processing will be a noop except for
476 : : * sorting out all of the packages which name it in Triggers-Awaited.
477 : : *
478 : : * (This situation can only arise if modstatdb_note success in
479 : : * clearing the triggers-pending status of the pending package
480 : : * but then fails to go on to update the awaiters.) */
481 : 0 : *fixbytrig = possdependee->trigaw.head->pend;
482 : 0 : debug(dbg_depcondetail,
483 : : " triggers-awaited, fixbytrig '%s', defer",
484 : : pkg_name(*fixbytrig, pnaw_always));
485 : 0 : return FOUND_DEFER;
486 : : }
487 [ # # ]: 0 : if (possdependee->clientdata &&
488 [ # # ]: 0 : possdependee->clientdata->istobe == PKG_ISTOBE_INSTALLNEW) {
489 : 0 : debug(dbg_depcondetail," unpacked/halfconfigured, defer");
490 : 0 : return FOUND_DEFER;
491 [ # # # # ]: 0 : } else if (!removing && in_force(FORCE_CONFIGURE_ANY) &&
492 [ # # ]: 0 : !skip_due_to_hold(possdependee) &&
493 [ # # ]: 0 : !(possdependee->status == PKG_STAT_HALFCONFIGURED)) {
494 : 0 : notice(_("also configuring '%s' (required by '%s')"),
495 : : pkg_name(possdependee, pnaw_nonambig),
496 : : pkg_name(requiredby, pnaw_nonambig));
497 : 0 : enqueue_package(possdependee);
498 : 0 : sincenothing = 0;
499 : 0 : return FOUND_DEFER;
500 : : } else {
501 [ # # ]: 0 : if (provider) {
502 : 0 : varbuf_printf(oemsgs,
503 : 0 : _(" Package %s which provides %s is not configured yet.\n"),
504 : : pkg_name(possdependee, pnaw_nonambig),
505 : 0 : provider->ed->name);
506 : : } else {
507 : 0 : varbuf_printf(oemsgs, _(" Package %s is not configured yet.\n"),
508 : : pkg_name(possdependee, pnaw_nonambig));
509 : : }
510 : :
511 : 0 : debug(dbg_depcondetail, " not configured/able");
512 : 0 : goto unsuitable;
513 : : }
514 : :
515 : 0 : default:
516 [ # # ]: 0 : if (provider) {
517 : 0 : varbuf_printf(oemsgs,
518 : 0 : _(" Package %s which provides %s is not installed.\n"),
519 : : pkg_name(possdependee, pnaw_nonambig),
520 : 0 : provider->ed->name);
521 : : } else {
522 : 0 : varbuf_printf(oemsgs, _(" Package %s is not installed.\n"),
523 : : pkg_name(possdependee, pnaw_nonambig));
524 : : }
525 : :
526 : 0 : debug(dbg_depcondetail, " not installed");
527 : 0 : goto unsuitable;
528 : : }
529 : :
530 : 0 : unsuitable:
531 : 0 : debug(dbg_depcondetail, " returning %d", thisf);
532 : 0 : (*interestingwarnings)++;
533 : :
534 : 0 : return thisf;
535 : : }
536 : :
537 : : static void
538 : 0 : breaks_check_one(struct varbuf *aemsgs, enum dep_check *ok,
539 : : struct deppossi *breaks, struct pkginfo *broken,
540 : : struct pkginfo *breaker, struct deppossi *virtbroken)
541 : : {
542 : 0 : struct varbuf depmsg = VARBUF_INIT;
543 : :
544 [ # # ]: 0 : debug(dbg_depcondetail, " checking breaker %s virtbroken %s",
545 : : pkg_name(breaker, pnaw_always),
546 : 0 : virtbroken ? virtbroken->ed->name : "<none>");
547 : :
548 [ # # ]: 0 : if (breaker->status == PKG_STAT_NOTINSTALLED ||
549 [ # # ]: 0 : breaker->status == PKG_STAT_CONFIGFILES)
550 : 0 : return;
551 [ # # ]: 0 : if (broken == breaker) return;
552 [ # # ]: 0 : if (!versionsatisfied(&broken->installed, breaks)) return;
553 : : /* The test below can only trigger if dep_breaks start having
554 : : * arch qualifiers different from “any”. */
555 [ # # ]: 0 : if (!archsatisfied(&broken->installed, breaks))
556 : 0 : return;
557 [ # # ]: 0 : if (ignore_depends(breaker)) return;
558 [ # # # # ]: 0 : if (virtbroken && ignore_depends(&virtbroken->ed->pkg))
559 : 0 : return;
560 [ # # # # ]: 0 : if (virtbroken && !pkg_virtual_deppossi_satisfied(breaks, virtbroken))
561 : 0 : return;
562 : :
563 : 0 : varbufdependency(&depmsg, breaks->up);
564 : 0 : varbuf_printf(aemsgs, _(" %s (%s) breaks %s and is %s.\n"),
565 : : pkg_name(breaker, pnaw_nonambig),
566 : 0 : versiondescribe(&breaker->installed.version, vdew_nonambig),
567 : 0 : varbuf_str(&depmsg), gettext(statusstrings[breaker->status]));
568 : 0 : varbuf_destroy(&depmsg);
569 : :
570 [ # # ]: 0 : if (virtbroken) {
571 : 0 : varbuf_printf(aemsgs, _(" %s (%s) provides %s.\n"),
572 : : pkg_name(broken, pnaw_nonambig),
573 : 0 : versiondescribe(&broken->installed.version, vdew_nonambig),
574 : 0 : virtbroken->ed->name);
575 [ # # ]: 0 : } else if (breaks->verrel != DPKG_RELATION_NONE) {
576 : 0 : varbuf_printf(aemsgs, _(" Version of %s to be configured is %s.\n"),
577 : : pkg_name(broken, pnaw_nonambig),
578 : 0 : versiondescribe(&broken->installed.version, vdew_nonambig));
579 [ # # ]: 0 : if (in_force(FORCE_DEPENDS_VERSION))
580 : 0 : return;
581 : : }
582 [ # # ]: 0 : if (force_breaks(breaks)) return;
583 : 0 : *ok = DEP_CHECK_HALT;
584 : : }
585 : :
586 : : static void
587 : 0 : breaks_check_target(struct varbuf *aemsgs, enum dep_check *ok,
588 : : struct pkginfo *broken, struct pkgset *target,
589 : : struct deppossi *virtbroken)
590 : : {
591 : : struct deppossi *possi;
592 : :
593 [ # # ]: 0 : for (possi = target->depended.installed; possi; possi = possi->rev_next) {
594 [ # # ]: 0 : if (possi->up->type != dep_breaks) continue;
595 : 0 : breaks_check_one(aemsgs, ok, possi, broken, possi->up->up, virtbroken);
596 : : }
597 : 0 : }
598 : :
599 : : enum dep_check
600 : 0 : breakses_ok(struct pkginfo *pkg, struct varbuf *aemsgs)
601 : : {
602 : : struct dependency *dep;
603 : : struct deppossi *virtbroken;
604 : 0 : enum dep_check ok = DEP_CHECK_OK;
605 : :
606 : 0 : debug(dbg_depcon, " checking Breaks");
607 : :
608 : 0 : breaks_check_target(aemsgs, &ok, pkg, pkg->set, NULL);
609 : :
610 [ # # ]: 0 : for (dep= pkg->installed.depends; dep; dep= dep->next) {
611 [ # # ]: 0 : if (dep->type != dep_provides) continue;
612 : 0 : virtbroken = dep->list;
613 : 0 : debug(dbg_depcondetail, " checking virtbroken %s", virtbroken->ed->name);
614 : 0 : breaks_check_target(aemsgs, &ok, pkg, virtbroken->ed, virtbroken);
615 : : }
616 : 0 : return ok;
617 : : }
618 : :
619 : : /*
620 : : * Checks [Pre]-Depends only.
621 : : */
622 : : enum dep_check
623 : 0 : dependencies_ok(struct pkginfo *pkg, struct pkginfo *removing,
624 : : struct varbuf *aemsgs)
625 : : {
626 : : /* Valid values: 2 = ok, 1 = defer, 0 = halt. */
627 : : enum dep_check ok;
628 : : /* Valid values: 0 = none, 1 = defer, 2 = withwarning, 3 = ok. */
629 : : enum found_status found, thisf;
630 : : int interestingwarnings;
631 : : bool matched, anycannotfixbytrig;
632 : 0 : struct varbuf oemsgs = VARBUF_INIT;
633 : : struct dependency *dep;
634 : : struct deppossi *possi, *provider;
635 : : struct pkginfo *possfixbytrig, *canfixbytrig;
636 : :
637 : 0 : ok = DEP_CHECK_OK;
638 [ # # ]: 0 : debug(dbg_depcon,"checking dependencies of %s (- %s)",
639 : : pkg_name(pkg, pnaw_always),
640 : 0 : removing ? pkg_name(removing, pnaw_always) : "<none>");
641 : :
642 : 0 : anycannotfixbytrig = false;
643 : 0 : canfixbytrig = NULL;
644 [ # # ]: 0 : for (dep= pkg->installed.depends; dep; dep= dep->next) {
645 [ # # # # ]: 0 : if (dep->type != dep_depends && dep->type != dep_predepends) continue;
646 : 0 : debug(dbg_depcondetail," checking group ...");
647 : 0 : matched = false;
648 : 0 : interestingwarnings = 0;
649 : 0 : varbuf_reset(&oemsgs);
650 : 0 : found = FOUND_NONE;
651 : 0 : possfixbytrig = NULL;
652 [ # # # # ]: 0 : for (possi = dep->list; found != FOUND_OK && possi; possi = possi->next) {
653 : : struct deppossi_pkg_iterator *possi_iter;
654 : : struct pkginfo *pkg_pos;
655 : :
656 : 0 : debug(dbg_depcondetail," checking possibility -> %s",possi->ed->name);
657 [ # # ]: 0 : if (possi->cyclebreak) {
658 : 0 : debug(dbg_depcondetail," break cycle so ok and found");
659 : 0 : found = FOUND_OK;
660 : 0 : break;
661 : : }
662 : :
663 : 0 : thisf = FOUND_NONE;
664 : 0 : possi_iter = deppossi_pkg_iter_new(possi, wpb_installed);
665 [ # # ]: 0 : while ((pkg_pos = deppossi_pkg_iter_next(possi_iter))) {
666 : 0 : thisf = deppossi_ok_found(pkg_pos, pkg, removing, NULL,
667 : : &possfixbytrig, &matched, possi,
668 : : &interestingwarnings, &oemsgs);
669 [ # # ]: 0 : if (thisf > found)
670 : 0 : found = thisf;
671 [ # # ]: 0 : if (found == FOUND_OK)
672 : 0 : break;
673 : : }
674 : 0 : deppossi_pkg_iter_free(possi_iter);
675 : :
676 [ # # ]: 0 : if (found != FOUND_OK) {
677 : 0 : for (provider = possi->ed->depended.installed;
678 [ # # # # ]: 0 : found != FOUND_OK && provider;
679 : 0 : provider = provider->rev_next) {
680 [ # # ]: 0 : if (provider->up->type != dep_provides)
681 : 0 : continue;
682 : 0 : debug(dbg_depcondetail, " checking provider %s",
683 : 0 : pkg_name(provider->up->up, pnaw_always));
684 [ # # ]: 0 : if (!deparchsatisfied(&provider->up->up->installed, provider->arch,
685 : : possi)) {
686 : 0 : debug(dbg_depcondetail, " provider does not satisfy arch");
687 : 0 : continue;
688 : : }
689 : 0 : thisf = deppossi_ok_found(provider->up->up, pkg, removing, provider,
690 : : &possfixbytrig, &matched, possi,
691 : : &interestingwarnings, &oemsgs);
692 [ # # # # : 0 : if (thisf == FOUND_DEFER && provider->up->up == pkg && !removing) {
# # ]
693 : : /* IOW, if the pkg satisfies its own dep (via a provide), then
694 : : * we let it pass, even if it isn't configured yet (as we're
695 : : * installing it). */
696 : 0 : thisf = FOUND_OK;
697 : : }
698 [ # # ]: 0 : if (thisf > found)
699 : 0 : found = thisf;
700 : : }
701 : : }
702 : 0 : debug(dbg_depcondetail," found %d",found);
703 [ # # ]: 0 : if (thisf > found) found= thisf;
704 : : }
705 [ # # ]: 0 : if (in_force(FORCE_DEPENDS)) {
706 : 0 : thisf = found_forced_on(DEPEND_TRY_FORCE_DEPENDS);
707 [ # # ]: 0 : if (thisf > found) {
708 : 0 : found = thisf;
709 : 0 : debug(dbg_depcondetail, " rescued by force-depends, found %d", found);
710 : : }
711 : : }
712 : 0 : debug(dbg_depcondetail, " found %d matched %d possfixbytrig %s",
713 : : found, matched,
714 [ # # ]: 0 : possfixbytrig ? pkg_name(possfixbytrig, pnaw_always) : "-");
715 [ # # # # ]: 0 : if (removing && !matched) continue;
716 [ # # # # : 0 : switch (found) {
# ]
717 : 0 : case FOUND_NONE:
718 : 0 : anycannotfixbytrig = true;
719 : 0 : ok = DEP_CHECK_HALT;
720 : : /* Fall through. */
721 : 0 : case FOUND_FORCED:
722 : 0 : varbuf_add_str(aemsgs, " ");
723 : 0 : varbuf_add_pkgbin_name(aemsgs, pkg, &pkg->installed, pnaw_nonambig);
724 : 0 : varbuf_add_str(aemsgs, _(" depends on "));
725 : 0 : varbufdependency(aemsgs, dep);
726 [ # # ]: 0 : if (interestingwarnings) {
727 : : /* Don't print the line about the package to be removed if
728 : : * that's the only line. */
729 : 0 : varbuf_add_str(aemsgs, _("; however:\n"));
730 : 0 : varbuf_add_varbuf(aemsgs, &oemsgs);
731 : : } else {
732 : 0 : varbuf_add_str(aemsgs, ".\n");
733 : : }
734 : 0 : break;
735 : 0 : case FOUND_DEFER:
736 [ # # ]: 0 : if (possfixbytrig)
737 : 0 : canfixbytrig = possfixbytrig;
738 : : else
739 : 0 : anycannotfixbytrig = true;
740 [ # # ]: 0 : if (ok > DEP_CHECK_DEFER)
741 : 0 : ok = DEP_CHECK_DEFER;
742 : 0 : break;
743 : 0 : case FOUND_OK:
744 : 0 : break;
745 : 0 : default:
746 : 0 : internerr("unknown value for found '%d'", found);
747 : : }
748 : : }
749 [ # # ]: 0 : if (ok == DEP_CHECK_HALT &&
750 [ # # # # ]: 0 : (pkg->clientdata && pkg->clientdata->istobe == PKG_ISTOBE_REMOVE))
751 : 0 : ok = DEP_CHECK_DEFER;
752 [ # # # # ]: 0 : if (!anycannotfixbytrig && canfixbytrig)
753 : 0 : progress_bytrigproc = canfixbytrig;
754 : :
755 : 0 : varbuf_destroy(&oemsgs);
756 : 0 : debug(dbg_depcon, "ok %d msgs >>%s<<", ok, varbuf_str(aemsgs));
757 : :
758 : 0 : return ok;
759 : : }
|