internals.sgml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. <!doctype debiandoc system [
  2. <!entity % manuals-version-def system "manuals-version">
  3. %manuals-version-def;
  4. ]>
  5. <debiandoc><book>
  6. <titlepag>
  7. <title>dpkg Internals Manual</title>
  8. <author>
  9. <name>Klee Dienes</name>
  10. <email>klee@mit.edu</email>
  11. </author>
  12. <version>Version &manuals-version; (dpkg &dpkg-version;)</version>
  13. <abstract>
  14. This manual describes the internal structure of the <prgn>dpkg</prgn> package
  15. management system.
  16. </abstract>
  17. <copyright>
  18. <copyrightsummary>
  19. Copyright &copy;1997 Klee Dienes &lt;klee@mit.edu&gt;
  20. </copyrightsummary>
  21. <p>
  22. This manual is free software; you may redistribute it and/or modify it
  23. under the terms of the GNU General Public License as published by the
  24. Free Software Foundation; either version 2, or (at your option) any
  25. later version.
  26. <p>
  27. This is distributed in the hope that it will be useful, but
  28. <em>without any warranty</em>; without even the implied warranty of
  29. merchantability or fitness for a particular purpose. See the GNU
  30. General Public License for more details.
  31. <p>
  32. You should have received a copy of the GNU General Public License with
  33. your Debian system, in <file>/usr/share/common-licenses/GPL</file>, or
  34. with the <prgn>dpkg</prgn> source package as the file <file>COPYING</file>. If
  35. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  36. Cambridge, MA 02139, USA.
  37. </copyright>
  38. </titlepag>
  39. <toc detail="sect">
  40. <chapt id=build>
  41. <heading>Build Notes</heading>
  42. <sect id=automake>
  43. <heading>Automake</heading>
  44. <p>
  45. This section by Tom Lees &lt;tom@lpsg.demon.co.uk&gt; on Tue, 4 Mar 1997
  46. 21:34:57 +0000, with subsequent modifications by Klee Dienes &lt;klee@debian.org&gt;
  47. <p>
  48. This chapter contains general notes about the conversion to
  49. <prgn>automake</prgn>. If you plan on doing anything with <prgn>dpkg</prgn>, you
  50. should probably read all of this file first. You have been warned.
  51. <p>
  52. Automake has several significant advantages, including:
  53. <list>
  54. <item>it supports emacs lisp properly
  55. <item>It supports libtool properly
  56. <item>it includes the aclocal utility
  57. </list>
  58. <p>
  59. The <prgn>aclocal</prgn> utility is a very useful program which will automatically
  60. build an <file>aclocal.m4</file> file from the <file>configure.in</file> file to include the
  61. appropriate macros.
  62. <p>
  63. This doesn't affect anything other than rebuilding the <file>Makefile.in</file> files
  64. from the sources.
  65. <p>
  66. Probably the main difference which is noticable is that instead of
  67. using proprietary directory names, it now supports <em>configure
  68. --sharedstatedir</em>, and <em>configure --localstatedir</em>. To set these
  69. to the Debian defaults, you should use <em>./configure
  70. --localstatedir=/etc --sharedstatedir=/var/lib</em>.
  71. <p>
  72. I have also customized the canonicalizing macros found in
  73. <em>autoconf</em> to include the old way of finding the <prgn>dpkg</prgn>
  74. ``architecture'', i.e. to be a bit more smart. Instead of it trying to
  75. determine the architecture only, I changed it to use the `host',
  76. `build', and `target' system types. The target CPU type is checked
  77. against the archtable to find the architecture on which dpkg will run.
  78. <p>
  79. It uses <em>gcc --print-libgcc-file-name</em> to find out the build
  80. architecture if possible (used later to determine ELF or <em>a.out</em>
  81. format), and also uses <em>dpkg --print-architecture</em> if possible to
  82. modify the <em>cpu</em> field before it passes on the target alias to
  83. config.sub. If you want to specify the architecture, you should now
  84. use "--target=", rather than <em>--with-arch</em>, which was essentially
  85. a hack anyway. The old <em/--with-arch/ is still there, but it is
  86. somewhat less functional. I have also moved the
  87. <em/DPKG_CACHED_/ macros into dpkg.m4 to make configure.in a bit
  88. more readable.
  89. <p>
  90. I also converted to libtool (which can be found in the Debian
  91. distribution now). Essentially, this means that all the dpkg tools can
  92. be compiled against a shared <em>libdpkg</em> without much hassle (in
  93. fact, it is the default). You do not need to install libtool to use
  94. this feature (it works like autoconf), and generally, it should not be
  95. needed much at all.
  96. <p>
  97. The new <em>dist</em> targets will build a distribution including all
  98. files built by the <prgn>debiandoc2html</prgn>, <prgn>debiandoc2ps</prgn>, etc.,
  99. which are included in the distribution so that people may build <prgn>dpkg</prgn>
  100. without these (especially useful to porters).
  101. <p>
  102. A target <em/make debian/ has been added, which will build the
  103. Debian files from a working directory (does a <em/make dist/
  104. first). Now all we need is a modified dpkg-source so that the
  105. <file/dpkg-1.4.0.8.tar.gz/ GNU-distribution file can be used as part
  106. of the Debian distribution. I'm working on this, but it doesn't work
  107. too well at the moment (find it in examples).
  108. <p>
  109. I removed the <em/make portable/ target - it doesn't do anything useful.
  110. <p>
  111. I have added <em/make uninstall/ targets to aid non-Debian users who simply
  112. want to try out certain Debian packages, and the "dist" targets are also
  113. useful to build a "distribution" of the dpkg tool. Note that since automake
  114. automatically includes dependencies into the Makefiles in a distribution,
  115. if you want to modify the C files, it would be advisable to get and install
  116. automake, and then re-run it in the base dpkg distribution directory, so that
  117. automatic dependency generation will be switched back on, and any
  118. dependencies which change will be taken account of. The "make maintainer-clean"
  119. targets will remove all files which any of the following utilities create:
  120. <list>
  121. <item>automake
  122. <item>autoconf
  123. <item>aclocal
  124. <item>autoheader
  125. <item>gettextize
  126. <item>libtoolize
  127. </list>
  128. <p>
  129. If you want to modify any of the sources, I recommend that you do the following
  130. first (after having installed the appropriate utilities, of course):-
  131. <list>
  132. <item>
  133. make maintainer-clean
  134. <item>
  135. aclocal
  136. <item>
  137. autoheader
  138. <item>
  139. autoconf
  140. <item>
  141. gettextize
  142. <item>
  143. libtoolize (do not let automake run this, as it will cause it not to
  144. include the libtool files in the dist targets)
  145. <item>
  146. for i in COPYING INSTALL; do ln -s /usr/share/automake/$i .; done
  147. <item>
  148. automake
  149. </list>
  150. <p>
  151. I have also incorporated the patches originally made by Galen
  152. Hazelwood to internationalize dpkg using GNU gettext - see the file
  153. "NOTES.intl" for more information about this.
  154. <p>
  155. Other minor changes are:
  156. <list>
  157. <item>
  158. The version number is now determined from debian/changelog, not from
  159. the directory name.
  160. <item>
  161. Creation of version.h now handled from configure script, not Makefile.
  162. <item>
  163. include/dpkg.h is now generated from include/dpkg.h.in by a sed
  164. script, inserting the appropriate directory definitions - so now it
  165. supports changing the dpkg directories (can install in /usr/local)
  166. <item>
  167. Updated the COPYING (1 very minor change) and INSTALL files to those
  168. distributed with automake-1.1l
  169. <item>
  170. Since the shared libdpkg is now installed, I also made
  171. include/Makefile install dpkg.h and dpkg-db.h into /usr/include by
  172. default
  173. </list>
  174. Questions:
  175. <list>
  176. <item>
  177. Should I use <em/localstatedir/ and <em/sharedstatedir/ instead of
  178. <em/sysconfdir/ and <em/datadir/?
  179. </list>
  180. </sect>
  181. <sect id=i18n>
  182. <heading>Internationalization</heading>
  183. <p>
  184. This section by Galen Hazelwood.
  185. <p>
  186. Dpkg is, to say the least, generous in its error reporting. The vast
  187. majority of the output strings are error messages of one kind or another.
  188. And if you feel that you've stumbled into the Department of Redundancy
  189. Department, you would be absolutely correct. Many of the error messages
  190. in dpkg.pot are duplicates, used at different points in the program.
  191. <p>
  192. To avoid swamping the translators completely, I made some executive decisions
  193. on what kinds of strings to translate. All the strings sent to debug() are
  194. left alone, on the grounds that these are for dpkg developers, and not for
  195. the general public. Most interal error messages were very cryptic, and
  196. would probably confuse the translators when seen just sitting there in
  197. the dpkg.pot file, and are also left alone. (I did mark some of the more
  198. verbose ones for translation.)
  199. <p>
  200. If others disagree with me about the necessity of translating these strings,
  201. it's easy enough to just go through and mark them later.
  202. <p>
  203. I added the startup gettext code to the main routine in dselect, which was
  204. necessary as many of the strings in lib are translated. Dselect is otherwise
  205. unchanged.
  206. <p>
  207. Changes:
  208. <list>
  209. <item>
  210. The files in intl and po were taken from gettext 0.10.26, by way of
  211. the gettextize program. I altered the makefiles to remove the VERSION
  212. symbol, which is only used in targets which dpkg does not support.
  213. <item>
  214. aclocal.m4 was stolen from the textutils package, configure.in was
  215. altered to use these new tests, symbols were added to acconfig.h, and
  216. the two new directories were added to Makefile.in.
  217. <item>
  218. The dpkg, dpkg-deb, md5sum, split, and dselect Makefiles now look for
  219. headers in ../intl, and try to link with whatever i18n libraries
  220. configure finds. They also now define LOCALEDIR in CFLAGS.
  221. <item>
  222. include/dpkg.h has the necessary NLS boilerplate, and the only file
  223. which dosen't include this (md5sum/md5sum.c) had it added directly.
  224. <item>
  225. The most intrusive change is due to a disagreement between xgettext
  226. and the dpkg coding style. Although xgettext understands string
  227. constant concatenation, it can't handle the case where preprocessor
  228. symbols are used as well. The dpkg code uses this a lot, especially
  229. in cases like this:
  230. <example>
  231. ohshite("error reading from " BACKEND " pipe");
  232. </example>
  233. where BACKEND is defined as "dpkg-deb". Because xgettext can't handle
  234. this, I have changed this usage in all cases to something like:
  235. <example>
  236. ohshite(_("error reading from dpkg-deb pipe");
  237. </example>
  238. This isn't very kind to Ian, I know. But what can I do?
  239. </list>
  240. </sect>
  241. </chapt>
  242. <chapt id=code>
  243. <heading>Code Internals</heading>
  244. <sect id=defs>
  245. <heading>Structure Definitons</heading>
  246. <sect1 id=versionrevision>
  247. <heading>versionrevision</heading>
  248. <p>
  249. <example>
  250. struct versionrevision {
  251. unsigned long epoch;
  252. char *version;
  253. char *revision;
  254. };
  255. </example>
  256. <p>
  257. The <tt/versionrevision/ structure is used to store a Debian version specification
  258. </sect1>
  259. </sect>
  260. <sect id=functions>
  261. <heading>Functions</heading>
  262. <sect1 id=parsing>
  263. <heading>Parsing translation tables</heading>
  264. <p>
  265. Each of these tables is used to associate a set of strings with a
  266. corresponding set of integers.
  267. Current tables are:
  268. <p>
  269. <example>
  270. const struct namevalue booleaninfos[];
  271. </example>
  272. <p>
  273. Maps boolean strings (<em/"yes"/,<em/"no"/) to their binary values.
  274. <sect2>
  275. <heading>priorityinfos[]</heading>
  276. <p>
  277. <example>
  278. const struct namevalue priorityinfos[];
  279. </example>
  280. <p>
  281. Maps priority strings to and from values of
  282. type <em/enum pkgpriority/.
  283. Current priority values are:
  284. <list>
  285. <item><em/required/ - required
  286. <item><em/important/ - important
  287. <item><em/standard/ - standard
  288. <item><em/recommended/ - recommended
  289. <item><em/optional/ - optional
  290. <item><em/extra/ - extra
  291. <item><em/contrib/ - contrib
  292. <item><em/other/ - other
  293. <item><em/unknown/ - unknown
  294. <item><em/base/ -
  295. This is obsolete, but is accepted as an alias for <em/required/.
  296. </item>
  297. </list>
  298. </sect2>
  299. <sect2>
  300. <heading>statusinfos[]</heading>
  301. <p>
  302. <example>
  303. const struct namevalue statusinfos[];
  304. </example>
  305. Maps package status strings to values of type <em/enum ???/.
  306. Package status strings are:
  307. "not-installed" "unpacked" "half-configured" "installed"
  308. "half-installed" "config-files" "postinst-failed" "removal-failed"
  309. </sect2>
  310. <sect2>
  311. <heading>eflaginfos[]</heading>
  312. <p>
  313. <example>
  314. const struct namevalue eflaginfos[];
  315. </example>
  316. </sect2>
  317. <sect2>
  318. <heading>wantinfos[]</heading>
  319. <p>
  320. <example>
  321. const struct namevalue wantinfos[];
  322. </example>
  323. </sect2>
  324. <sect2>
  325. <heading>nicknames[]</heading>
  326. <p>
  327. <example>
  328. const struct nickname nicknames[];
  329. </example>
  330. Maps obsolete control fields to their current versions.
  331. </sect2>
  332. </sect1>
  333. <sect1 id=parsef>
  334. <heading>Parsing functions</heading>
  335. <sect2>
  336. <heading>parseerr()</heading>
  337. <p>
  338. <example>
  339. void parseerr
  340. (FILE *file, const char *filename, int lno,
  341. FILE *warnto, int *warncount, const struct pkginfo *pigp,
  342. int warnonly, const char *fmt, ...);
  343. </example>
  344. Report an error parsing a control data stream. Checks <var/file/ for
  345. error status on <var/file/, printing an error message to stderr and
  346. exiting with error status if an error is present on the stream.
  347. Formats the variable arguments according to the <em/printf/-style
  348. string in <var/fmt/, preceding the result with <var/filename/,
  349. <var/lno/, and <var/pigp/ (if not NULL). If <var/warnonly/ is 0,
  350. writes the result to stderr and exits with error status. Otherwise,
  351. increments <var/warncount/ and returns normally.
  352. </sect2>
  353. <sect2>
  354. <heading>illegal_packagename()</heading>
  355. <p>
  356. <em>
  357. const char *illegal_packagename
  358. (const char *p, const char **ep)
  359. </em>
  360. Checks the package name at <var/p/ for proper syntax. Returns NULL in
  361. case of success, setting <var/*ep/ to point after the last character
  362. in the package name, including any trailing whitespace (as defined by
  363. isspace()). In case of error, returns the error message as a pointer
  364. to a static buffer.
  365. </sect2>
  366. <sect2>
  367. <heading>informativeversion()</heading>
  368. <p>
  369. <em>
  370. int informativeversion(const struct versionrevision *version)
  371. </em>
  372. <p>
  373. Returns true if and only if the <em/versionrevision/ is non-empty;
  374. otherwise returns false.
  375. </sect2>
  376. <sect2>
  377. <heading>varbufversion()</heading>
  378. <p>
  379. <example>
  380. void varbufversion
  381. (struct varbuf *vb,
  382. const struct versionrevision *version,
  383. enum versiondisplayepochwhen vdew);
  384. </example>
  385. Writes a human-readable representation of <var/version/ to <var/vb/.
  386. Possible values of <var/vdew/:
  387. <list>
  388. <item><tt/vdew_never/ - never include epoch
  389. <item><tt/vdew_nonambig/ - include epoch string if non-zero
  390. <item><tt/vdew_always/ - always include epoch string
  391. </list>
  392. </sect2>
  393. <sect2>
  394. <heading>versiondescribe()</heading>
  395. <p>
  396. <example>
  397. const char *versiondescribe
  398. (const struct versionrevision *version,
  399. enum versiondisplayepochwhen vdew);
  400. </example>
  401. <p>
  402. Return a human-readable representation of <var/version/ as a pointer
  403. to a static buffer. If the version structure is empty, return
  404. <em/"&lt;none&gt;"/. Static buffers are allocated from a set of 10
  405. in round-robin fashion (they will be re-used after 10 successive calls
  406. to <em/versiondescribe/).
  407. </sect2>
  408. <sect2>
  409. <heading>parseversion()</heading>
  410. <p>
  411. <example>
  412. const char *parseversion
  413. (struct versionrevision *rversion, const char *string);
  414. </example>
  415. <p>
  416. Parse the contents of <var/string/ into <var/rversion/. If
  417. successful, returns NULL, otherwise returns a pointer to a static
  418. error string.
  419. </sect2>
  420. <sect2>
  421. <heading>parsemustfield()</heading>
  422. <p>
  423. <example>
  424. void parsemustfield
  425. (FILE *file, const char *filename, int lno,
  426. FILE *warnto, int *warncount,
  427. const struct pkginfo *pigp, int warnonly,
  428. char **value, const char *what);
  429. </example>
  430. </sect2>
  431. <sect2>
  432. <heading>skip_slash_dotslash()</heading>
  433. <p>
  434. <example>
  435. const char *skip_slash_dotslash (const char *p);
  436. </example>
  437. </sect2>
  438. <sect2>
  439. <heading>convert_string()</heading>
  440. <p>
  441. <example>
  442. static int convert_string
  443. (const char *filename, int lno, const char *what, int otherwise,
  444. FILE *warnto, int *warncount, const struct pkginfo *pigp,
  445. const char *startp, const struct namevalue *nvip,
  446. const char **endpp)
  447. </example>
  448. </sect2>
  449. </sect1>
  450. </sect>
  451. </chapt>
  452. </book></debiandoc>