dpkg (1.18.25) stretch; urgency=medium
[dpkg] / doc / triggers.txt
CommitLineData
1479465f
GJ
1TRIGGERS
2========
3
4Introduction
5------------
6
7A dpkg trigger is a facility that allows events caused by one package
8but of interest to another package to be recorded and aggregated, and
9processed later by the interested package. This feature simplifies
10various registration and system-update tasks and reduces duplication
11of processing.
12
13(NB: Triggers are intended for events that occur during package
14installation, not events that occur in general operation.)
15
16
17Concepts
18--------
19
20Each trigger is named, and at any time zero or more packages may be
21interested in it.
22
23We currently envisage three kinds of triggers:
24 * Explicit triggers. These can be activated by any program
25 by running dpkg-trigger (at any time, but ideally from a maintainer
26 script).
27 * File triggers. These are activated automatically by dpkg
28 when a matching file is installed, upgraded or removed as part
29 of a package. They may also be explicitly activated by running
30 dpkg-trigger.
31 * Future kinds of special triggers, which are activated by magic code
32 in dpkg itself. Currently none are defined besides file triggers.
33
34A trigger is always activated by a particular package.
35
36Trigger names contain only printing 7-bit ascii characters (no
37whitespace). Each trigger kind has a distinct subset of the trigger
38name space so that the kind can be determined from the name. After we
39run out of straightforward syntaxes, we will use <kind>:<details>.
40
41When a trigger is activated, it becomes pending for every package
42which is interested in the trigger at that time. Each package has a
43list of zero or more pending triggers. Repeated activation of the
44same trigger has no additional effect. Note that in general a trigger
45will not be processed immediately when it is activated; processing is
46deferred until it is convenient (as described below).
47
48At a trigger activation, the interested packages(s) are added to the
49triggering package's list of triggers-awaited packages (unless the
50trigger has been configured to not require it); the triggering
51package is said to await the trigger processing.
52
53A package which has pending triggers, or which awaits triggers, is not
54considered properly installed. There are two new dpkg status values,
55‘triggers-pending’ and ‘triggers-awaited’, which lie between
56‘config-failed’ and ‘installed’.
57
58
59Details - Overview table
60------------------------
61
62 Status Pending Awaited Satisfies Remedy
63 triggers triggers Depends
64
65 unpacked never maybe No postinst configure
66 c.-failed never maybe No postinst configure (when requested)
67 t.-awaited yes always No postinst triggered + fix awaited pkg(s)
68 t.-awaited no always No fix awaited package(s)
69 t.-pending always never Yes postinst triggered
70 installed never never Yes n/a
71
72Packages in t-awaited and t-pending demand satisfaction of their
73dependencies just like packages in installed.
74
75
76Details - triggering package
77----------------------------
78
79When a package T activates a trigger in which a package I is
80interested, I is added to the list of packages whose trigger
81processing is awaited by T. Zero or more packages I may be added as a
82result of any particular trigger activation, depending on how many
83packages were interested. (If T chooses, explicit trigger activation
84using dpkg-trigger of I by T need not make T become triggers-awaited
85in this way.)
86
87A package which awaits trigger processing but would otherwise be
88‘installed’ or ‘triggers-pending’ is considered to be in state
89‘triggers-awaited’. Packages in ‘triggers-awaited’ do not satisfy
90Depends dependencies.
91
92Every triggered package I in T's list of awaited packages either has a
93nonempty list of pending triggers, or is in ‘config-failed’ or worse.
94When I enters ‘installed’ (or ‘config-files’ or ‘not-installed’), the
95entry in T's list of awaited packages is removed so that T may, if it
96no longer awaits any packages, become ‘installed’ or ‘triggers-pending’.
97
98Packages in ‘config-files’ or ‘not-installed’ do not await triggers.
99
100
101Details - triggered package
102---------------------------
103
104When one of the triggers in which a package is interested is
105activated, the triggered package has the trigger added to its list of
106pending triggers. Packages with a nonempty list of pending triggers
107which would otherwise be in state ‘installed’ are in state
108‘triggers-pending’ instead, so if the package was previously
109‘installed’ it becomes ‘triggers-pending’.
110
111If a package has nonempty lists both of pending and awaited triggers,
112then it is in ‘triggers-awaited’. Nevertheless efforts will still be
113made to process its triggers so as to make the list of pending
114triggers empty.
115
116To restore a package in state ‘triggers-pending’ to ‘installed’, or to
117process pending triggers of a package with both pending and awaited
118triggers, dpkg will run the postinst script:
119 postinst triggered "<trigger-name> <trigger-name> ..."
120
121This will be attempted for each relevant package at the end of each
122dpkg run; so, normally, in the same dpkg run as the event which made
123the package go to ‘triggers-pending’. This leaves packages in
124reasonable states by default.
125
126If the “postinst triggered” run fails the package goes to
127‘config-failed’, so that the trigger processing will not be attempted
128again until explicitly requested.
129
130
131
132 v
133 ┌────────────┐
134 │ unpacked │
135 └─────┬──────┘
136
137
138 (automatic)│ ┌───────────────┐
139 │ │ config-failed │
140 │ └─────┬─────────┘
141 │ │ ^
142 │ │ │
143 ├──────<─────┘ │ ┌──────────────────────────────────┐
144 │ (user request) │ │ triggers-pending │
145 postinst │ │ │ or │
146 "configure" │ │ │ triggers-awaited w/ some pending │
147 │ │ └────────────┬─────────────────────┘
148 │ │ │ ^
149 ├────────>───────┤ postinst │ │
150 │ error │ "triggered" │ │
151 │ │ (automatic) │ │
152 │ │ │ │ trigger(s)
153 │ │ │ │ activated
154 │ └────────<─────────┤ │
155 │ error │ │
156 │ │ │
157 v v │
158 ┌──────────────────────────────────────────────┴────┐
159 │ installed or triggers-awaited w/ none pending │
160 └───────────────────────────────────────────────────┘
161
162Packages in ‘config-failed’ or worse are never considered to have
163lists of pending triggers. A package whose postinst is being run
164can however acquire pending triggers during that run (ie, a package
165can trigger itself).
166
167This means that if a triggering package T awaits trigger processing by
168an interested package I, and I goes to ‘config-failed’ or worse (eg,
169during unpack for upgrade), then when I is reconfigured (goes to
170‘installed’) or removed, T will no longer await processing by I, so
171that T may automatically go from ‘triggers-awaited’ to ‘installed’.
172
173Or to put it another way, triggered actions are considered irrelevant
174if the interested package I is not configured. When I's postinst is
175called with ‘configure’, it must do whatever actions are necessary to
176deal with any trigger activations which might have occurred while it
177was not configured, just as if the package was being configured for
178the first time.
179
180Trigger processing should be idempotent. The list of triggers being
181processed is provided to the postinst only so that it can optimize
182away redundant processing.
183
184In that case, where an interested package has more than one trigger
185and wants to process them differently, the list of triggers can be can
186be examined in a shell script like this:
187 case " $2 " in
188 *" trigger-name-a "*) process-trigger-a ;;
189 esac
190Generally each trigger name should be tested for separately, as the
191postinst will often be called for several triggers at once.
192
193Note that if a package both activates triggers in other packages, and
194is interested in triggers of its own, its postinst may run for trigger
195processing before the postinst(s) of the package(s) it has triggered.
196
197
198Timing guarantees, races, etc.
199------------------------------
200
201Activating a trigger will not have any immediate effect, although
202putative resulting status changes will show up in dpkg --status etc.
203(Putative because the actual status changes may depend on the state of
204trigger interests when dpkg processes the trigger activation into
205the status database, rather than that when dpkg --status is run.)
206
207A package is only guaranteed to become notified of a trigger
208activation if it is continuously interested in the trigger, and never
209in ‘config-failed’ or worse, during the period from when the trigger
210is activated until dpkg runs the package postinst (either due to
211--configure --pending, or at the end of the relevant run, as described
212above). Subsequent to activation and before notification, the
213interested package will not be considered in state ‘installed’, so
214long as the package remains interested, and the triggering package
215will not be considered ‘installed’.
216
217If the package is not in state ‘installed’, ‘triggers-pending’ or
218‘triggers-awaited’ then pending triggers are not accumulated.
219However, if such a package (between ‘half-installed’ and
220‘config-failed’ inclusive) declares some trigger interests then the
221triggering packages *will* await their configuration (which implies
222completion of any necessary trigger processing) or removal.
223
224It is not defined in what order triggers will run. dpkg will make
225some effort to minimize redundant work in the case where many packages
226have postinst trigger processing activating another package's triggers
227(for example, by processing triggers in fifo order during a single
228dpkg run). Cycles in the triggering graph are prohibited and will
229eventually, perhaps after some looping, be detected by dpkg and cause
230trigger processing to fail; when this happens one of the packages
231involved will be put in state ‘config-failed’ so that the trigger loop
232will not be reattempted. See “Cycle detection” below.
233
234
235Explicit triggers
236-----------------
237
238Explicit triggers have names with the same syntax as package names,
239*but* should *not* normally be named identically to a package.
240
241When choosing an explicit trigger name it is usually good to include a
242relevant package name or some other useful identifier to help make the
243trigger name unique. On the other hand, explicit triggers should
244generally not be renamed just because the interested or triggering
245packages' names change.
246
247Explicit trigger names form part of the interface between packages.
248Therefore in case of wider use of any trigger the name and purpose
249should be discussed in the usual way and documented in the appropriate
250packaging guidelines (eg, in the distribution policy).
251
252
253File triggers
254-------------
255
256File triggers have names of the form
257 /path/to/directory/or/file
258and are activated when the specified filesystem object, or any object
259under the specified subdirectory, is created, updated or deleted by
260dpkg during package unpack or removal. The pathname must be absolute.
261
262File triggers should not generally be used without mutual consent.
263The use of a file trigger, and the name of the trigger used, should be
264stated in the distribution policy, so that a package which creates a
265relevant file in a maintainer script can activate the trigger explicitly.
266
267File triggers must definitely not be used as an escalation tool in
268disagreements between different packages as to the desired contents of
269the filesystem. Trigger activation due to a particular file should
270not generally modify that file again.
271
272Configuration files (whether dpkg-handled conffiles or not), or any
273other files which are modified at times other than package management,
274should not rely on file triggers detecting all modifications; dpkg
275triggers are not a general mechanism for filesystem monitoring.
276
277If there are or might be directory symlinks which result in packages
278referring to files by different names, then to be sure of activation
279all of the paths which might be included in packages should be listed.
280The path specified by the interested package is matched against the
281path included in the triggering package, not against the truename of
282the file as installed. Only textually identical filenames (or
283filenames where the interest is a directory prefix of the installed
284file) are guaranteed to match.
285
286A file trigger is guaranteed to be activated before the file in
287question is modified by dpkg; on the other hand, a file trigger might
288be activated even though no file was actually modified. Changes made
289by dpkg to the link count of a file, or to solely the inode number
290(ie, if dpkg atomically replaces it with another identical file), are
291not guaranteed to cause trigger activation.
292
293Because of the restriction on trigger names, it is not possible to
294declare a file trigger for a directory whose name contains whitespace,
295i18n characters, etc. Such a trigger should not be necessary.
296
297
298Package declarations regarding triggers
299---------------------------------------
300
301See deb-triggers(5).
302
303Support future extension of the trigger name syntax with additional
304dpkg-generated triggers is as follows: a package which is interested
305in any unsupported trigger kinds cannot be configured (since such a
306package cannot be guaranteed to have these triggers properly activated
307by dpkg). Therefore no package can be interested in any unsupported
308trigger kinds and they can be freely activated (both by ‘activate’ and
309by dpkg-trigger). dpkg-deb will be changed to warn about unrecognized
310trigger names syntaxes and unrecognized trigger control directives.
311
312
313New command line interfaces to dpkg tools
314-----------------------------------------
315
316See dpkg(1).
317
318Here is a summary of the behaviours:
319
320 Command line Trigproc Trigproc Configure
321 these any triggered
322 ----------------------+---------------+---------------+-----------------
323 --unpack no usually[1] none
324 --remove n/a usually[1] none
325 --install n/a usually[1] these
326 --configure -a any needed usually[1] any needed
327 --configure <some> if needed usually[1] must, or trigproc
328 --triggers-only -a any needed usually[1] none
329 --triggers-only <some> must usually not[1] none
330
331 [1] can be specified explicitly by --triggers or --no-triggers
332
333
334See dpkg-trigger(1).
335
336A trigger may be activated explicitly with:
337 dpkg-trigger [--by-package <package>] <name-of-trigger>
338 dpkg-trigger --no-await <name-of-trigger>
339
340There will be no output to stdout, and none to stderr unless
341dpkg-trigger is unable to make a record of the trigger activation.
342
343NB that in the case of a file trigger the name of the trigger is
344needed, not the name of a file which would match the trigger.
345
346
347apt and aptitude
348----------------
349
350These must be taught about the new ‘triggers-awaited’ and
351‘triggers-pending’ states. Packages in these states should be treated
352roughly like those in ‘unpacked’: the remedy is to run dpkg
353--configure.
354
355Normally apt and aptitude will not see packages in ‘triggers-pending’
356since dpkg will generally attempt to run the triggers thus leaving the
357package in ‘config-failed’ or ‘installed’.
358
359Note that automatic package management tools which call dpkg (like apt
360and aptitude) should not attempt to configure individual packages in
361state ‘triggers-pending’ (or indeed ‘triggers-awaited’) with dpkg
362--triggers-only <package>... or dpkg --no-triggers --configure <package>...,
363or similar approaches. This might defeat dpkg's trigger cycle detection.
364
365A package management tool which will run dpkg --configure --pending at
366the end may use --no-triggers on its other dpkg runs. This would be
367more efficient as it allows more aggressive deferral (and hence more
368unification) of trigger processing.
369
370
371Error handling
372--------------
373
374Packages should be written so that they DO NOT BREAK just because
375their pending triggers have not yet been run. It is allowed for the
376functionality relating to the unprocessed trigger to fail (ie, the
377package which is awaiting the trigger processing may be broken), but
378the remainder of the interested package must work normally.
379
380For example, a package which uses file triggers to register addons
381must cope with (a) an addon being dropped into the filesystem but not
382yet registered and (b) an addon being removed but not yet
383deregistered. In both of these cases the package's main functionality
384must continue to work normally; failure of the addon in question is
385expected, warning messages are tolerable, but complete failure of the
386whole package, or failures of other addons, are not acceptable.
387
388dpkg cannot ensure that triggers are run in a timely enough manner for
389pathological error behaviours to be tolerable.
390
391
392Where a trigger script finds bad data provided by a triggering
393package, it should generally report to stderr the problem with the bad
394data and exit nonzero, leaving the interested package in config-failed
395and the triggering package in triggers-awaited and thus signalling the
396problem to the user.
397
398Alternatively, in some situations it may be more desirable to allow
399the interested package to be configured even though it can only
400provide partial service. In this case clear information will have to
401be given in appropriate places about the missing functionality, and a
402record should be made of the cause of the errors. This option is
403recommended for situations where the coupling between the interested
404and triggering package is particularly loose; an example of such a
405loose coupling would be Python modules.
406
407
408
409WORKED EXAMPLE - SCROLLKEEPER
410=============================
411
412Currently, every Gnome program which comes with some help installs the
413help files in /usr/share/gnome/help and then in the postinst runs
414scrollkeeper-update. scrollkeeper-update reads, parses and rewrites
415some large xml files in /var/lib/scrollkeeper; currently this
416occurs at every relevant package installation, upgrade or removal.
417
418When triggers are available, this will work as follows:
419
420 * gnome-foobar will ship its «omf» file in /usr/share/omf as
421 normal, but will not contain any special machinery to invoke
422 scrollkeeper.
423
424 * scrollkeeper will in its triggers control file say:
425 interest /usr/share/omf
426 and in its postinst say:
427 scrollkeeper-update-now -q
428
429 dpkg will arrange that this is run once at the end of each run
430 where any documentation was updated.
431
432 Note that it is not necessary to execute this only on particular
433 postinst "$1" values; however, at the time of writing, scrollkeeper
434 does this:
435
436 if [ "$1" = "configure" ]; then
437 printf "Rebuilding the database. This may take some time.\n"
438 scrollkeeper-rebuilddb -q
439 fi
440
441 and to retain this behaviour, something along the following lines
442 would be sensible:
443
444 if [ "$1" = "configure" ]; then
445 printf "Rebuilding the database. This may take some time.\n"
446 scrollkeeper-rebuilddb -q
447 else
448 printf "Updating GNOME help database.\n"
449 scrollkeeper-update-now -q
450 fi
451
452 * dh_scrollkeeper will only adjust the DTD declarations and no longer
453 edit maintainer scripts.
454
455
456Full implementation of the transition plan defined below, for
457scrollkeeper, goes like this:
458
459 1. Update scrollkeeper:
460 - Add a ‘triggers’ control archive file containing
461 interest /usr/share/omf
462 - Make the postinst modifications as described above.
463 - Rename scrollkeeper-update to scrollkeeper-update-now
464 - Provide a new wrapper script as scrollkeeper-update:
465 #!/bin/sh
466 set -e
467 if type dpkg-trigger >/dev/null 2>&1 && \
468 dpkg-trigger /usr/share/omf; then
469 exit 0
470 fi
471 exec scrollkeeper-update-now "$@"
472
473 2. In gnome-policy chapter 2, “Use of scrollkeeper”,
474 - delete the requirement that the package must depend on
475 scrollkeeper
476 - delete the requirement that the package must invoke
477 scrollkeeper in the postinst and postrm
478 - instead say:
479
480 OMF files should be installed under /usr/share/omf in the
481 usual way. A dpkg trigger is used to arrange to update the
482 scrollkeeper documentation index automatically and no special
483 care need be taken in packages which supply OMFs.
484
485 If an OMF file is placed, modified or removed other than as
486 a file installed in the ordinary way by dpkg, the dpkg file
487 trigger «/usr/share/omf» should be activated; see the dpkg
488 triggers specification for details.
489
490 Existing packages which Depend on scrollkeeper (>= 3.8)
491 because of dh_scrollkeeper or explicit calls to
492 scrollkeeper-update should be modified not to Depend on
493 scrollkeeper.
494
495 3. Update debhelper's dh_scrollkeeper not to edit maintainer
496 scripts. One of dh_scrollkeeper or lintian should be changed to
497 issue a warning for packages with scrollkeeper (>= 3.8) in the
498 Depends control file line.
499
500 4. Remove the spurious dependencies on scrollkeeper, at our leisure.
501 As a bonus, after this is complete it will be possible to remove
502 scrollkeeper while keeping all of the documentation-supplying
503 gnome packages installed.
504
505 5. If there are any packages which do by hand what dh_scrollkeeper
506 does, change them not to call scrollkeeper-update and drop
507 their dependency on scrollkeeper.
508
509This is not 100% in keeping with the full transition plan defined
510below: if a new gnome package is used with an old scrollkeeper, there
511is some possibility that the help will not properly be available.
512
513Unfortunately, dh_scrollkeeper doesn't generate the scrollkeeper
514dependency in the control file, which makes it excessively hard to get
515the dependency up to date. The bad consequences of the inaccurate
516dependencies are less severe than the contortions which would be
517required to deal with the problem.
518
519
520TRANSITION PLAN
521===============
522
523
524Old dpkg to new dpkg
525--------------------
526
527The first time a trigger-supporting dpkg is run on any system, it will
528activate all triggers in which anyone is interested, immediately.
529
530These trigger activations will not be processed in the same dpkg run,
531to avoid unexpectedly processing triggers while attempting an
532unrelated operation. dpkg --configure --pending (and not other dpkg
533operations) will run the triggers, and the dpkg postinst will warn the
534user about the need to run it (if this deferred triggers condition
535exists). (Any triggers activated or reactivated *after* this
536mass-activation will be processed in the normal way.)
537
538To use this correctly:
539 * Packages which are interested in triggers, or which want to
540 explicitly activate triggers, should Depend on the
541 triggers-supporting version of dpkg.
542 * Update instructions and tools should arrange to run
543 dpkg --configure --pending
544 after the install; this will process the pending triggers.
545
546dpkg's prerm will check for attempts to downgrade while triggers are
547pending and refuse. (Since the new dpkg would be installed but then
548refuse to read the status file.) In case this is necessary a separate
549tool will be provided which will:
550 * Put all packages with any pending triggers into state
551 ‘config-failed’ and remove the list of pending triggers.
552 * Remove the list of awaited triggers from every package. This
553 may cause packages to go from ‘triggers-awaited’ to ‘installed’
554 which is not 100% accurate but the best that can be done.
555 * Remove /var/lib/dpkg/triggers (to put the situation to that which
556 we would have seen if the trigger-supporting dpkg had never been
557 installed).
558
559
560Higher-level programs
561---------------------
562
563The new dpkg will declare versioned Conflicts against apt and aptitude
564and other critical package management tools which will be broken by
565the new Status field values. Therefore, the new higher-level tools
566will have to be deployed first.
567
568The new dpkg will declare versioned Breaks against any known
569noncritical package management tools which will be broken by the new
570Status field value.
571
572
573Transition hints for existing packages
574--------------------------------------
575
576When a central (consumer) package defines a directory where other leaf
577(producer) packages may place files and/or directories, and currently
578the producer packages are required to run an «update-consumer» script
579in their postinst:
580 1. In the relevant policy, define a trigger name which is the name of
581 the directory where the individual files are placed by producer
582 packages.
583 2. Update the consumer package:
584 * Declare an interest in the trigger.
585 * Edit «update-consumer» so that if it is called without --real
586 it does the following:
587 if type dpkg-trigger >/dev/null 2>&1 && \
588 dpkg-trigger name-of-trigger; then
589 exit 0
590 fi
591 If this fails to cause «update-consumer» to exit, it should do
592 its normal update processing. Alternatively, if it is more
593 convenient, «update-consumer» could be renamed and supplanted with
594 a wrapper script which conditionally runs the real
595 «update-consumer».
596 * In the postinst, arrange for the new ‘triggered’ invocation to
597 run «update-consumer --real». The consumer package's postinst
598 will already run «update-consumer» during configuration, and this
599 should be retained and supplemented with the --real option (or
600 changed to call the real script rather than the wrapper).
601 3. Update the producer packages:
602 * In the postinst, remove the call to «update-consumer».
603 * Change the dependency on consumer to be versioned, specifying a
604 trigger-interested consumer.
605 This can be done at our leisure. Ideally for loosely coupled
606 packages this would be done only in the release after the one
607 containing the triggers-interested consumer, to facilitate partial
608 upgrades and backports.
609 4. After all producer packages have been updated according to step 3,
610 «update-consumer» has become an interface internal to the consumer
611 and need no longer be kept stable. If un-updated producers are
612 still of interest, incompatible changes to «update-consumer» imply
613 a versioned Breaks against the old producers.
614(See also “Transition plan”, below.)
615
616If there are several consumer packages all of which are interested in
617the features provided by producer packages, the current arrangements
618usually involve an additional central switchboard package (eg,
619emacsen-common). In this case:
620
621 -- NOTE - this part of the transition plan is still a proof of
622 concept and we might yet improve on it
623
624 1. Define the trigger name.
625 2. Update the switchboard to have any new functionality needed by the
626 consumers in step 3 (2nd bullet).
627 3. Update the consumer packages:
628 * Declare an interest in the trigger.
629 * In the postinst, arrange for the new ‘trigger’ invocation to run
630 the compilation/registration process. This may involve scanning
631 for new or removed producers, and may involve new common
632 functionality from the switchboard (in which case a versioned
633 Depends is needed).
634 * The old interface allowing the switchboard to run
635 compilation/registration should be preserved, including
636 calls to the switchboard to register this consumer.
637 4. When all consumers have been updated, update the switchboard:
638 * Make the registration scripts called by producers try to
639 activate the trigger and if that succeeds quit without
640 doing any work (as for bullet 2 in the simple case above).
641 * Versioned Breaks, against the old (pre-step-3) consumers.
642 5. After the switchboard has been updated, producers can be updated:
643 * Remove the calls to the switchboard registration/compilation
644 functions.
645 * Change the dependency on the switchboard to a versioned one,
646 specifying the one which Breaks old consumers. Alternatively,
647 it may be the case that the switchboard is no longer needed (or
648 not needed for this producer), in which case the dependency on
649 the switchboard can be removed in favour of an appropriate
650 versioned Breaks (probably, identical to that in the new
651 switchboard).
652 6. After all the producers have been updated, the cruft in the
653 consumers can go away:
654 * Remove the calls to the switchboard's registration system.
655 * Versioned Breaks against old switchboards, or versioned Depends
656 on new switchboards, depending on whether the switchboard is
657 still needed for other common functionality.
658 7. After all of the producers and consumers have been updated, the
659 cruft in the switchboard can go away:
660 * Remove the switchboard's registration system (but not obviously
661 the common functionality from step 3, discussed above).
662 * Versioned Breaks against pre-step-6 consumers and pre-step-5
663 producers.
664
665
666DISCUSSION
667==========
668
669The activation of a trigger does not record details of the activating
670event. For example, file triggers do not inform the package of the
671filename. In the future this might be added as an additional feature,
672but there are some problems with this.
673
674
675Broken producer packages, and error reporting
676---------------------------------------------
677
678Often trigger processing will involve a central package registering,
679compiling or generally parsing some data provided by a leaf package.
680
681If the central package finds problems with the leaf package data it is
682usually more correct for only the individual leaf package to be
683recorded as not properly installed. There is not currently any way to
684do this and there are no plans to provide one.
685
686The naive approach of giving the postinst a list of the triggering
687packages does not work because this information is not recorded in the
688right way (it might suffer from lacunae); enhancing the bookkeeping
689for this to work would be possible but it is far better simply to make
690the system more idempotent. See above for the recommended approach.
691
692
693
694
695INTERNALS
696=========
697
698On-disk state
699-------------
700
701A single file /var/lib/dpkg/triggers/File lists all of the filename
702trigger interests in the form
703 /path/to/directory/or/file package
704
705For each explicit trigger in which any package is interested,
706a file /var/lib/dpkg/triggers/<name-of-trigger> is a list of
707the interested packages, one per line.
708
709These interest files are not updated to remove a package just because
710a state change causes it not to be interested in any triggers any more
711- they are updated when we remove or unpack.
712
713For each package which has pending triggers, the status file contains
714a Triggers-Pending field which contains the space-separated names of
715the pending triggers. For each package which awaits triggers the
716status file contains a Triggers-Awaited field which contains the
717*package* names of the packages whose trigger processing is awaited.
718See “Details - Overview table” above for the invariants which relate
719Triggers-Pending, Triggers-Awaited, and Status.
720
721During dpkg's execution, /var/lib/dpkg/triggers/Unincorp is a list of
722the triggers which have been requested by dpkg-trigger but not yet
723incorporated in the status file. Each line is a trigger name followed
724by one or more triggering package names. The triggering package name
725"-" is used to indicate one or more package(s) which did not need to
726await the trigger.
727
728/var/lib/dpkg/triggers/Lock is the fcntl lockfile for the trigger
729system. Processes hang onto this lock only briefly: dpkg-trigger
730to add new activations, or dpkg to incorporate activations (and
731perhaps when it updates interests). Therefore this lock is always
732acquired with F_GETLKW so as to serialize rather than fail on
733contention.
734
735
736Processing
737----------
738
739dpkg-trigger updates triggers/Unincorp, and does not read or write the
740status file or take out the dpkg status lock. dpkg (and dpkg-query)
741reads triggers/Unincorp after reading /var/lib/dpkg/status, and after
742running a maintainer script. If the status database is opened for
743writing then the data from Unincorp is moved to updates as
744Triggers-Pending and Triggers-Awaited entries and corresponding Status
745changes.
746
747This means that dpkg is guaranteed to reincorporate pending trigger
748information into the status file only 1. when a maintainer script has
749finished, or 2. when dpkg starts up with a view to performing some
750operation.
751
752When a package is unpacked or removed, its triggers control file will
753be parsed and /var/lib/dpkg/triggers/* updated accordingly.
754
755Triggers are run as part of configuration. dpkg will try to first
756configure all packages which do not depend on packages which are
757awaiting triggers, and then run triggers one package at a time in the
758hope of making useful progress. (This will involve a new ‘dependtry’
759level in configure.c's algorithm.) The only constraint on the
760ordering of postinsts is only the normal Depends constraint, so the
761usual Depends cycle breaking will function properly. See “Cycle
762detection” below regarding cycles in the “A triggers B” relation.
763
764
765Processing - Transitional
766-------------------------
767
768The case where a triggers-supporting dpkg is run for the first time is
769detected by the absence of /var/lib/dpkg/triggers/Unincorp. When the
770triggers-supporting dpkg starts up without this it will set each
771package's list of pending triggers equal to its interests (obviously
772only for packages which are in ‘installed’ or ‘triggers-pending’).
773This may result in a package going from ‘installed’ to
774‘triggers-pending’ but it will not create the directory at this time.
775Packages marked as triggers-pending in this way will not be scheduled
776for trigger processing in this dpkg run.
777
778dpkg will also at this time create /var/lib/dpkg/triggers if
779necessary, triggers/File, triggers/Unincorp, and the per-trigger
780package lists in /var/lib/dpkg/triggers/<trigger-name>, so that future
781trigger activations will be processed properly.
782
783Only dpkg may create /var/lib/dpkg/triggers and only when it is
784holding the overall dpkg status lock.
785
786dpkg and/or dpkg-deb will be made to reject packages containing
787Triggers-Pending and Triggers-Awaited control file fields, to prevent
788accidents.
789
790
791Cycle detection
792---------------
793
794In addition to dependency cycles, triggers raise the possibility of
795mutually triggering packages - a cycle detectable only dynamically,
796which we will call a “trigger cycle”.
797
798Trigger cycles are detected using the usual hare-and-tortoise
799approach. Each time after dpkg runs a postinst for triggers, dpkg
800records the set of pending triggers (ie, the set of activated <pending
801package, trigger name> tuples). If the hare set is a superset of the
802tortoise set, a cycle has been found.
803
804For guaranteed termination, it would be sufficient to declare a cycle
805only when the two sets are identical, but because of the requirement
806to make progress we can cut this short. Formally, there is supposed
807to be a complete ordering of pending trigger sets satisfying the
808condition that any set of pending triggers is (strictly) greater than
809all its (strict) subsets. Trigger processing is supposed to
810monotonically decrease the set in this ordering. (The set elements
811are <package, trigger name> tuples.)
812
813(See “Processing” above for discussion of dependency cycles.)