~ubuntu-branches/ubuntu/lucid/dpkg/lucid

« back to all changes in this revision

Viewing changes to lib/dpkg/dpkg-db.h

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2009-09-18 13:39:36 UTC
  • mfrom: (1.1.9 sid)
  • Revision ID: james.westby@ubuntu.com-20090918133936-dj8kjtc2qz3yqj7i
Tags: 1.15.4ubuntu1
* Resynchronise with Debian (LP: #427854). Remaining changes:
  Ubuntu-specific adjustments (probably):
  - Use i686 for lpia in cputable and triplettable.
  - Hack Dpkg::Arch to return i686 for lpia.
  - Move various Conflicts to Breaks, since upgrades from stable Ubuntu
    releases support Breaks.

  Miscellaneous bug fixes:
  - Avoid duplicate attempts to [f]close in obscure error situations which
    might conceiveably close wrong fds.
  - Revert change to stop outputting a newline after a postinst is run
    (Debian #392317).
  - Use the two-arg form of open in Dpkg::Control so that "-" can be
    passed to parse stdin as a control file (Debian #465340).

  Launchpad integration:
  - Add Launchpad-Bugs-Fixed handling in a few more places.

  Build options:
  - Point to https://wiki.ubuntu.com/DistCompilerFlags from
    dpkg-buildpackage(1).
  - Set default LDFLAGS to -Wl,-Bsymbolic-functions. (We've already taken
    this hit in Ubuntu.)
  - Implement handling of hardening-wrapper options via DEB_BUILD_OPTIONS.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * libdpkg - Debian packaging suite library routines
 
3
 * dpkg-db.h - declarations for in-core package database management
 
4
 *
 
5
 * Copyright © 1994,1995 Ian Jackson <ian@chiark.greenend.org.uk>
 
6
 * Copyright © 2000,2001 Wichert Akkerman
 
7
 *
 
8
 * This is free software; you can redistribute it and/or modify
 
9
 * it under the terms of the GNU General Public License as
 
10
 * published by the Free Software Foundation; either version 2,
 
11
 * or (at your option) any later version.
 
12
 *
 
13
 * This is distributed in the hope that it will be useful, but
 
14
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 * GNU General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU General Public
 
19
 * License along with dpkg; if not, write to the Free Software
 
20
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
21
 */
 
22
 
 
23
#ifndef DPKG_DB_H
 
24
#define DPKG_DB_H
 
25
 
 
26
#include <dpkg/macros.h>
 
27
#include <dpkg/varbuf.h>
 
28
 
 
29
DPKG_BEGIN_DECLS
 
30
 
 
31
#include <sys/types.h>
 
32
#include <stdio.h>
 
33
 
 
34
struct versionrevision {
 
35
  unsigned long epoch;
 
36
  const char *version;
 
37
  const char *revision;
 
38
};  
 
39
 
 
40
enum deptype {
 
41
  dep_suggests,
 
42
  dep_recommends,
 
43
  dep_depends,
 
44
  dep_predepends,
 
45
  dep_breaks,
 
46
  dep_conflicts,
 
47
  dep_provides,
 
48
  dep_replaces,
 
49
  dep_enhances
 
50
};
 
51
 
 
52
enum depverrel {
 
53
  dvrf_earlier=      0001,
 
54
  dvrf_later=        0002,
 
55
  dvrf_strict=       0010,
 
56
  dvrf_orequal=      0020,
 
57
  dvrf_builtup=      0100,
 
58
  dvr_none=          0200,
 
59
  dvr_earlierequal=  dvrf_builtup | dvrf_earlier | dvrf_orequal,
 
60
  dvr_earlierstrict= dvrf_builtup | dvrf_earlier | dvrf_strict,
 
61
  dvr_laterequal=    dvrf_builtup | dvrf_later   | dvrf_orequal,
 
62
  dvr_laterstrict=   dvrf_builtup | dvrf_later   | dvrf_strict,
 
63
  dvr_exact=         0400
 
64
};
 
65
 
 
66
struct dependency {
 
67
  struct pkginfo *up;
 
68
  struct dependency *next;
 
69
  struct deppossi *list;
 
70
  enum deptype type;
 
71
};
 
72
 
 
73
struct deppossi {
 
74
  struct dependency *up;
 
75
  struct pkginfo *ed;
 
76
  struct deppossi *next, *nextrev, *backrev;
 
77
  struct versionrevision version;
 
78
  enum depverrel verrel;
 
79
  int cyclebreak;
 
80
};
 
81
 
 
82
struct arbitraryfield {
 
83
  struct arbitraryfield *next;
 
84
  const char *name;
 
85
  const char *value;
 
86
};
 
87
 
 
88
struct conffile {
 
89
  struct conffile *next;
 
90
  const char *name;
 
91
  const char *hash;
 
92
  int obsolete;
 
93
};
 
94
 
 
95
struct filedetails {
 
96
  struct filedetails *next;
 
97
  const char *name;
 
98
  const char *msdosname;
 
99
  const char *size;
 
100
  const char *md5sum;
 
101
};
 
102
 
 
103
struct pkginfoperfile { /* pif */
 
104
  int valid;
 
105
  struct dependency *depends;
 
106
  struct deppossi *depended;
 
107
  int essential; /* The `essential' flag, 1=yes, 0=no (absent) */
 
108
  const char *description;
 
109
  const char *maintainer;
 
110
  const char *source;
 
111
  const char *architecture;
 
112
  const char *installedsize;
 
113
  const char *origin;
 
114
  const char *bugs;
 
115
  struct versionrevision version;
 
116
  struct conffile *conffiles;
 
117
  struct arbitraryfield *arbs;
 
118
};
 
119
 
 
120
struct trigpend {
 
121
  /* Node indicates that parent's Triggers-Pending mentions name. */
 
122
  /* NB that these nodes do double duty: after they're removed from
 
123
   * a package's trigpend list, references may be preserved by the
 
124
   * trigger cycle checker (see trigproc.c).
 
125
   */
 
126
  struct trigpend *next;
 
127
  const char *name;
 
128
};
 
129
 
 
130
struct trigaw {
 
131
  /* Node indicates that aw's Triggers-Awaited mentions pend. */
 
132
  struct pkginfo *aw, *pend;
 
133
  struct trigaw *nextsamepend;
 
134
  struct {
 
135
    struct trigaw *next, *back;
 
136
  } sameaw;
 
137
};
 
138
 
 
139
struct perpackagestate; /* dselect and dpkg have different versions of this */
 
140
 
 
141
struct pkginfo { /* pig */
 
142
  struct pkginfo *next;
 
143
  const char *name;
 
144
  enum pkgwant {
 
145
    want_unknown, want_install, want_hold, want_deinstall, want_purge,
 
146
    want_sentinel /* Not allowed except as special sentinel value
 
147
                     in some places */
 
148
  } want;
 
149
  enum pkgeflag {
 
150
    eflag_ok            = 0,
 
151
    eflag_reinstreq     = 1,
 
152
  } eflag; /* Bitmask. */
 
153
  enum pkgstatus {
 
154
    stat_notinstalled,
 
155
    stat_configfiles,
 
156
    stat_halfinstalled,
 
157
    stat_unpacked,
 
158
    stat_halfconfigured,
 
159
    stat_triggersawaited,
 
160
    stat_triggerspending,
 
161
    stat_installed
 
162
  } status;
 
163
  enum pkgpriority {
 
164
    pri_required,
 
165
    pri_important,
 
166
    pri_standard,
 
167
    pri_optional,
 
168
    pri_extra,
 
169
    pri_other, pri_unknown, pri_unset=-1
 
170
  } priority;
 
171
  const char *otherpriority;
 
172
  const char *section;
 
173
  struct versionrevision configversion;
 
174
  struct filedetails *files;
 
175
  struct pkginfoperfile installed;
 
176
  struct pkginfoperfile available;
 
177
  struct perpackagestate *clientdata;
 
178
  enum { white, gray, black } color;  /* used during cycle detection */
 
179
 
 
180
  struct {
 
181
    /* ->aw == this */
 
182
    struct trigaw *head, *tail;
 
183
  } trigaw;
 
184
 
 
185
  /* ->pend == this, non-NULL for us when Triggers-Pending. */
 
186
  struct trigaw *othertrigaw_head;
 
187
  struct trigpend *trigpend_head;
 
188
};
 
189
 
 
190
/*** from lock.c ***/
 
191
 
 
192
void lockdatabase(const char *admindir);
 
193
void unlockdatabase(void);
 
194
 
 
195
/*** from dbmodify.c ***/
 
196
 
 
197
enum modstatdb_rw {
 
198
  /* Those marked with \*s*\ are possible returns from modstatdb_init. */
 
199
  msdbrw_readonly/*s*/, msdbrw_needsuperuserlockonly/*s*/,
 
200
  msdbrw_writeifposs,
 
201
  msdbrw_write/*s*/, msdbrw_needsuperuser,
 
202
  /* Now some optional flags: */
 
203
  msdbrw_flagsmask= ~077,
 
204
  /* flags start at 0100 */
 
205
  msdbrw_noavail= 0100,
 
206
};
 
207
 
 
208
enum modstatdb_rw modstatdb_init(const char *admindir, enum modstatdb_rw reqrwflags);
 
209
void modstatdb_note(struct pkginfo *pkg);
 
210
void modstatdb_note_ifwrite(struct pkginfo *pkg);
 
211
void modstatdb_checkpoint(void);
 
212
void modstatdb_shutdown(void);
 
213
 
 
214
/* Initialised by modstatdb_init. */
 
215
extern char *statusfile, *availablefile;
 
216
extern char *triggersdir, *triggersfilefile, *triggersnewfilefile;
 
217
 
 
218
const char *pkgadminfile(struct pkginfo *pkg, const char *whichfile);
 
219
 
 
220
/*** from trigdeferred.l ***/
 
221
 
 
222
enum trigdef_updateflags {
 
223
  tduf_nolockok =           001,
 
224
  tduf_write =              002,
 
225
  tduf_nolock =             003,
 
226
  /* Should not be set unless _write is. */
 
227
  tduf_writeifempty =       010,
 
228
  tduf_writeifenoent =      020,
 
229
};
 
230
 
 
231
struct trigdefmeths {
 
232
  void (*trig_begin)(const char *trig);
 
233
  void (*package)(const char *awname);
 
234
  void (*trig_end)(void);
 
235
};
 
236
 
 
237
extern const struct trigdefmeths *trigdef;
 
238
extern FILE *trig_new_deferred;
 
239
 
 
240
/* Return values:
 
241
 *  -1  Lock ENOENT with O_CREAT (directory does not exist)
 
242
 *  -2  Unincorp empty, tduf_writeifempty unset
 
243
 *  -3  Unincorp ENOENT, tduf_writeifenoent unset
 
244
 *   1  Unincorp ENOENT, tduf_writeifenoent set   } caller must call
 
245
 *   2  ok                                        }  trigdef_update_done!
 
246
 */
 
247
int trigdef_update_start(enum trigdef_updateflags uf, const char *admindir);
 
248
 
 
249
int trigdef_yylex(void);
 
250
void trigdef_process_done(void);
 
251
 
 
252
/*** hooks for more sophisticated processing in dpkg proper ***/
 
253
 
 
254
/* We do things like this so we can get most of the trigger tracking
 
255
 * in dpkg-query, dselect, and so on, but avoid the transitional
 
256
 * processing and deferred trigproc queue management other than when
 
257
 * we're actually doing real package management work. */
 
258
 
 
259
struct trigfileint {
 
260
  struct pkginfo *pkg;
 
261
  struct filenamenode *fnn;
 
262
  struct trigfileint *samefile_next;
 
263
  struct {
 
264
    struct trigfileint *next, *back;
 
265
  } inoverall;
 
266
};
 
267
 
 
268
struct trig_hooks {
 
269
 /* The first two are normally NULL.
 
270
  * If non-NULL, we're dpkg proper and we might need to invent trigger
 
271
  * activations as the first run of a triggers-supporting dpkg.
 
272
  */
 
273
  void (*enqueue_deferred)(struct pkginfo *pend);
 
274
  void (*transitional_activate)(enum modstatdb_rw cstatus);
 
275
 
 
276
  struct filenamenode *(*namenode_find)(const char *filename, int nonew);
 
277
  struct trigfileint **(*namenode_interested)(struct filenamenode *fnn);
 
278
 
 
279
  /* Returns a pointer from nfmalloc. */
 
280
  const char *(*namenode_name)(struct filenamenode *fnn);
 
281
};
 
282
 
 
283
extern struct trig_hooks trigh;
 
284
 
 
285
#define TRIGHOOKS_DEFINE_NAMENODE_ACCESSORS                              \
 
286
  static struct trigfileint **th_nn_interested(struct filenamenode *fnn) \
 
287
    { return &fnn->trig_interested; }                                    \
 
288
  static const char *th_nn_name(struct filenamenode *fnn)                \
 
289
    { return fnn->name; }
 
290
 
 
291
/*** from triglib.c ***/
 
292
 
 
293
void trig_file_activate_byname(const char *trig, struct pkginfo *aw);
 
294
void trig_file_activate(struct filenamenode *trig, struct pkginfo *aw);
 
295
 
 
296
int trig_note_pend_core(struct pkginfo *pend, const char *trig /*not copied!*/);
 
297
int trig_note_pend(struct pkginfo *pend, const char *trig /*not copied!*/);
 
298
int trig_note_aw(struct pkginfo *pend, struct pkginfo *aw);
 
299
void trig_clear_awaiters(struct pkginfo *notpend);
 
300
 
 
301
void trig_enqueue_awaited_pend(struct pkginfo *pend);
 
302
void trig_fixup_awaiters(enum modstatdb_rw cstatus);
 
303
 
 
304
void trig_file_interests_ensure(void);
 
305
void trig_file_interests_save(void);
 
306
 
 
307
void trig_cicb_interest_delete(const char *trig, void *user);
 
308
void trig_cicb_interest_add(const char *trig, void *user);
 
309
typedef void trig_parse_cicb(const char *trig, void *user);
 
310
void trig_parse_ci(const char *file, trig_parse_cicb *interest,
 
311
                   trig_parse_cicb *activate, void *user);
 
312
 
 
313
/* Called by process_archive. */
 
314
void trig_cicb_statuschange_activate(const char *trig, void *user);
 
315
 
 
316
void trig_incorporate(enum modstatdb_rw cstatus, const char *admindir);
 
317
 
 
318
const char *illegal_triggername(const char *p);
 
319
 
 
320
/*** from database.c ***/
 
321
 
 
322
struct pkginfo *findpackage(const char *name);
 
323
void blankpackage(struct pkginfo *pp);
 
324
void blankpackageperfile(struct pkginfoperfile *pifp);
 
325
void blankversion(struct versionrevision*);
 
326
int informative(struct pkginfo *pkg, struct pkginfoperfile *info);
 
327
int countpackages(void);
 
328
void resetpackages(void);
 
329
 
 
330
struct pkgiterator *iterpkgstart(void);
 
331
struct pkginfo *iterpkgnext(struct pkgiterator*);
 
332
void iterpkgend(struct pkgiterator*);
 
333
 
 
334
void hashreport(FILE*);
 
335
 
 
336
/*** from parse.c ***/
 
337
 
 
338
enum parsedbflags {
 
339
  pdb_recordavailable   =001, /* Store in `available' in-core structures, not `status' */
 
340
  pdb_rejectstatus      =002, /* Throw up an error if `Status' encountered             */
 
341
  pdb_weakclassification=004, /* Ignore priority/section info if we already have any   */
 
342
  pdb_ignorefiles       =010, /* Ignore files info if we already have them             */
 
343
  pdb_ignoreolder       =020  /* Ignore packages with older versions already read      */
 
344
};
 
345
 
 
346
const char *illegal_packagename(const char *p, const char **ep);
 
347
int parsedb(const char *filename, enum parsedbflags, struct pkginfo **donep,
 
348
            FILE *warnto, int *warncount);
 
349
void copy_dependency_links(struct pkginfo *pkg,
 
350
                           struct dependency **updateme,
 
351
                           struct dependency *newdepends,
 
352
                           int available);
 
353
 
 
354
/*** from parsehelp.c ***/
 
355
 
 
356
struct namevalue {
 
357
  const char *name;
 
358
  int value, length;
 
359
};
 
360
 
 
361
extern const struct namevalue booleaninfos[];
 
362
extern const struct namevalue priorityinfos[];
 
363
extern const struct namevalue statusinfos[];
 
364
extern const struct namevalue eflaginfos[];
 
365
extern const struct namevalue wantinfos[];
 
366
 
 
367
int informativeversion(const struct versionrevision *version);
 
368
 
 
369
enum versiondisplayepochwhen { vdew_never, vdew_nonambig, vdew_always };
 
370
void varbufversion(struct varbuf*, const struct versionrevision*,
 
371
                   enum versiondisplayepochwhen);
 
372
const char *parseversion(struct versionrevision *rversion, const char*);
 
373
const char *versiondescribe(const struct versionrevision*,
 
374
                            enum versiondisplayepochwhen);
 
375
 
 
376
/*** from dump.c ***/
 
377
 
 
378
void writerecord(FILE*, const char*,
 
379
                 const struct pkginfo*, const struct pkginfoperfile*);
 
380
 
 
381
void writedb(const char *filename, int available, int mustsync);
 
382
 
 
383
void varbufrecord(struct varbuf*, const struct pkginfo*, const struct pkginfoperfile*);
 
384
void varbufdependency(struct varbuf *vb, struct dependency *dep);
 
385
  /* NB THE VARBUF MUST HAVE BEEN INITIALISED AND WILL NOT BE NULL-TERMINATED */
 
386
 
 
387
/*** from vercmp.c ***/
 
388
 
 
389
int versionsatisfied(struct pkginfoperfile *it, struct deppossi *against);
 
390
int versionsatisfied3(const struct versionrevision *it,
 
391
                      const struct versionrevision *ref,
 
392
                      enum depverrel verrel);
 
393
int versioncompare(const struct versionrevision *version,
 
394
                   const struct versionrevision *refversion);
 
395
int epochsdiffer(const struct versionrevision *a,
 
396
                 const struct versionrevision *b);
 
397
 
 
398
/*** from nfmalloc.c ***/
 
399
void *nfmalloc(size_t);
 
400
char *nfstrsave(const char*);
 
401
char *nfstrnsave(const char*, size_t);
 
402
void nffreeall(void);
 
403
 
 
404
/*** from showpkg.c ***/
 
405
 
 
406
struct lstitem;
 
407
 
 
408
struct lstitem* parseformat(const char* fmt);
 
409
void freeformat(struct lstitem* head);
 
410
void show1package(const struct lstitem* head, struct pkginfo *pkg);
 
411
 
 
412
DPKG_END_DECLS
 
413
 
 
414
#endif /* DPKG_DB_H */