triggers.txt 36 KB

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