~ubuntu-branches/debian/wheezy/dpkg/wheezy

« back to all changes in this revision

Viewing changes to lib/dpkg/triglib.c

  • Committer: Bazaar Package Importer
  • Author(s): Guillem Jover, Guillem Jover, Raphaël Hertzog, Jonathan Nieder, Steve Langasek, Mark Hymers, Updated programs translations, Updated man page translations, Updated scripts translations, Updated dselect translations
  • Date: 2011-04-01 23:56:54 UTC
  • Revision ID: james.westby@ubuntu.com-20110401235654-8y800dtb75skfrh7
Tags: 1.16.0
[ Guillem Jover ]
* Use DPKG_MAINTSCRIPT_PACKAGE environment variable as package name on
  dpkg-divert when no --package or --local options have been specified.
* Do not allow versions starting with non-digit when doing strict parsing,
  warn otherwise.
* Update dpkg(1) to note that --status-fd output does not contain newlines
  in error messages anymore (this was fixed in 1.15.0).
* Add a new --status-logger option to dpkg, similar to --status-fd but
  instead invoke the command ourselves and feed the status information
  to its standard input. Suggested by Raphaël Hertzog.
* Add missing space in update-alternative --set-selections output.
* Add missing options to update-alternative --help output.
* Count “conffile name is duplicated” for dpkg-deb warning count summary.
* Improve and clarify strings for translation. Closes: #604914
* Prefix all fatal error messages with “error: ”.
* Do not check presence of update-rc.d in the PATH in dpkg, as it's not
  a program needed for dpkg correct operation.
* Fix dpkg -GEO options on multiple versions of the same packages.
  Closes: #31141
* Propagate --admindir to programs run from maintainer scritpts.
  Closes: #97076
* Do not fail when trying to remove the root directory. This will only
  happen either on distributions where dpkg is a foreign package manager,
  or on artificial dpkg databases.
* Always warn when parsing any package control data which does not have
  an Architecture field except for status and status log files when
  packages are not-installed or half-installed.
* By default reject installing packages w/o an Architecture field. They
  now need --force-architecture, dpkg will still warn about them though.
* Fix build failure when passing --disable-nls to configure.
* Do not segfault on “dpkg -i --no-act”.
* Add missing semicolon to the vsnprintf() compat declaration.
  Thanks to Robert Millan. Closes: #612203
* On install for Ubuntu adjust the i386 GNU cpu name in cputable.
  Thanks to Colin Watson <cjwatson@ubuntu.com>. Closes: #611741
* Sync the info database directory on unpack instead of the temporary
  control information directory, and print the correct pathname on error
  instead of the last file acted on that directory.
* Document in dpkg-query --help output and man page that --list and --show
  arguments are optional.
* Do not read and write the available file unnecessarily.
  Thanks to Michel Lespinasse <walken@zoy.org>. Closes: #397121
* Fix typo in «dpkg-name --overwrite» argument parsing so that it actually
  works at all. Thanks to Ivan Gagis <igagis@gmail.com>. LP: #728708
* Add armhf support to ostable and triplettable. Closes: #594179
* Set the modification time for unpacked symlinks on supported systems.
* Fix undefined value useage in dpkg-genchanges when adding files w/o a
  matching architecture, because they are not present in debian/control,
  this is most commonly the case due to dpkg-distaddfile.
* Terminate immediately on dpkg-divert rename errors instead of propagating
  up the error codes, this improves error reporting and avoids triggering
  leak detectors. Closes: #620380
* When moving a diverted file across filesystems in dpkg-divert, remove
  the source file.

[ Raphaël Hertzog ]
* Fail properly when debian/source/format is empty. Closes: #600854
* Add new deb-src-control(5) manual page documenting the debian/control
  file contained in source packages.
  - it documents the X[SBC]- prefix. Closes: #476335
  - it documents the VCS-* fields too. Closes: #483119
  Thanks to Oxan van Leeuwen <oxan@oxanvanleeuwen.nl> who wrote it
  as part of the Google Code In program.
* Enhance dpkg-shlibdeps to not fail immediatly when a library is not found.
  Instead continue and fail after all problems have been reported. Thanks
  to Chris Baines <cbaines8@gmail.com> for the patch. Closes: #596841
* Fix dpkg-source to not list Debian packaging files as modified
  upstream files in Format "1.0" when unpacking to a non-standard
  directory.
* Apply patch from Colin Watson to let dpkg-buildflags return -O3
  instead of -O2 when building ppc64 packages on Ubuntu. Closes: #612472
* Add new function get_control_path() to Dpkg::Path, it wraps dpkg-query
  --control-path.
* Update dpkg-shlibdeps to be multiarch-ready:
  - use get_control_path() to find symbols/shlibs files
  - parse correctly the output of dpkg --search
* Small fix to support files >2GB in .deb on 64-bit systems. Closes: #616502
  Thanks to Martin Dorey <mdorey@bluearc.com> for the patch.
* dpkg-source now keeps the file ordering in the autogenerated patch when
  regenerating it. Closes: #606080
  Thanks to Colin Watson for the patch.
* dpkg-source now uses a timestamp retrieved from the filesystem when
  resetting the timestamp of patched files so that a time skew when using
  NFS doesn't introduce any inconsistency. Closes: #613023
  Thanks to Jonathan Nieder <jrnieder@gmail.com> for the patch and the
  diagnosis.
* dpkg-source will now remove quilt's .pc directory when --unapply-patches
  is in use. Closes: #591858
* dpkg-source is now a bit less strict when parsing patches:
  - it accepts seeing the same file twice; Closes: #608829
  - it doesn't match on the English text "No newline at end of file" as it
    might be translated in some cases. Closes: #612465
* Improve parser in Dpkg::Control::Hash to not require an empty line
  before the PGP signature. Closes: #617923
  Thanks to Roger Leigh for the initial patch.
* Fix a regression in dpkg-divert where using --rename led to a failure when
  the rename implies crossing file systems. Thanks to Durk Strooisma for
  spotting it.
* Use the correct mtime when installing a file with statoverrides.
  Regression introduced in 1.16.0. LP: #739179
* Remove duplicate word in german translation of dpkg(1). Closes: #616096
* Strip repeated non-significant spaces before and after newlines
  in Uploaders. Closes: #598922
* Ignore whitespaces after options in headers of changelog entries.
  Closes: #605719
* Fix dpkg-source's regression with empty patches (introduced while fixing
  #613023). Closes: #619541

[ Jonathan Nieder ]
* Remove support for use of synchronous sync(2), due to its pernicious
  side-effects and to ease maintenance.
* Clarify that an up-to-date dpkg only needs to be unpacked for
  dpkg-maintscript-helper to work.

[ Steve Langasek ]
* Add new variables to dpkg-architecture, DEB_HOST_MULTIARCH and
  DEB_BUILD_MULTIARCH, that return the "ideal" GNU triplet for each
  architecture which should be used as the path component for library
  installation.

[ Mark Hymers ]
* Add support for Built-Using field. Closes: #619311

[ Updated programs translations ]
* German (Sven Joachim).
* Portuguese (Miguel Figueiredo).
* Spanish (Javier Fernandez-Sanguino).
* Swedish (Peter Krefting).

[ Updated man page translations ]
* German (Helge Kreutzmann).
* Swedish (Peter Krefting).

[ Updated scripts translations ]
* German (Helge Kreutzmann).
* Swedish (Peter Krefting).

[ Updated dselect translations ]
* Spanish (Javier Fernandez-Sanguino).

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
#include <dpkg/triglib.h>
41
41
 
42
42
const char *
43
 
illegal_triggername(const char *p)
 
43
trig_name_is_illegal(const char *p)
44
44
{
45
45
        int c;
46
46
 
55
55
        return NULL;
56
56
}
57
57
 
58
 
/*========== recording triggers ==========*/
 
58
/*========== Recording triggers. ==========*/
59
59
 
60
60
static char *triggersdir, *triggersfilefile, *triggersnewfilefile;
61
61
 
62
 
char *
63
 
trig_get_triggersdir(const char *admindir)
64
 
{
65
 
        struct varbuf path = VARBUF_INIT;
66
 
 
67
 
        varbufprintf(&path, "%s/%s", admindir, TRIGGERSDIR);
68
 
 
69
 
        return varbuf_detach(&path);
70
 
}
71
 
 
72
62
static char *
73
63
trig_get_filename(const char *dir, const char *filename)
74
64
{
75
 
        struct varbuf path = VARBUF_INIT;
76
 
 
77
 
        varbufprintf(&path, "%s/%s", dir, filename);
78
 
 
79
 
        return varbuf_detach(&path);
 
65
        char *path;
 
66
 
 
67
        m_asprintf(&path, "%s/%s", dir, filename);
 
68
 
 
69
        return path;
80
70
}
81
71
 
82
72
static struct trig_hooks trigh;
83
73
 
84
 
/*---------- noting trigger activation in memory ----------*/
 
74
/*---------- Noting trigger activation in memory. ----------*/
85
75
 
86
 
/* Called via trig_*activate* et al from:
 
76
/*
 
77
 * Called via trig_*activate* et al from:
87
78
 *   - trig_incorporate: reading of Unincorp (explicit trigger activations)
88
 
 *   - various places: processing start (`activate' in triggers ci file)
 
79
 *   - various places: processing start (‘activate’ in triggers ci file)
89
80
 *   - namenodetouse: file triggers during unpack / remove
90
81
 *   - deferred_configure: file triggers during config file processing
91
82
 *
94
85
 * recorded (how would we know?) and (b) we don't enqueue them for
95
86
 * deferred processing in this run.
96
87
 *
97
 
 * We add the trigger to Triggers-Pending first.  This makes it
 
88
 * We add the trigger to Triggers-Pending first. This makes it
98
89
 * harder to get into the state where Triggers-Awaited for aw lists
99
 
 * pend but Triggers-Pending for pend is empty.  (See also the
 
90
 * pend but Triggers-Pending for pend is empty. (See also the
100
91
 * comment in deppossi_ok_found regarding this situation.)
101
92
 */
102
93
 
103
 
/* aw might be NULL, and trig is not copied! */
 
94
/*
 
95
 * aw might be NULL.
 
96
 * trig is not copied!
 
97
 */
104
98
static void
105
99
trig_record_activation(struct pkginfo *pend, struct pkginfo *aw, const char *trig)
106
100
{
107
101
        if (pend->status < stat_triggersawaited)
108
 
                /* Not interested then. */
109
 
                return;
 
102
                return; /* Not interested then. */
110
103
 
111
104
        if (trig_note_pend(pend, trig))
112
105
                modstatdb_note_ifwrite(pend);
122
115
                }
123
116
}
124
117
 
125
 
/* NB that this is also called from fields.c where *pend is a temporary! */
 
118
/*
 
119
 * Note: This is also called from fields.c where *pend is a temporary!
 
120
 *
 
121
 * trig is not copied!
 
122
 */
126
123
bool
127
 
trig_note_pend_core(struct pkginfo *pend, const char *trig /*not copied!*/)
 
124
trig_note_pend_core(struct pkginfo *pend, const char *trig)
128
125
{
129
126
        struct trigpend *tp;
130
127
 
140
137
        return true;
141
138
}
142
139
 
143
 
/* Returns: true for done, false for already noted. */
 
140
/*
 
141
 * trig is not copied!
 
142
 *
 
143
 * @retval true  For done.
 
144
 * @retval false For already noted.
 
145
 */
144
146
bool
145
 
trig_note_pend(struct pkginfo *pend, const char *trig /*not copied!*/)
 
147
trig_note_pend(struct pkginfo *pend, const char *trig)
146
148
{
147
149
        if (!trig_note_pend_core(pend, trig))
148
150
                return false;
153
155
        return true;
154
156
}
155
157
 
156
 
/* Returns: true for done, false for already noted. */
157
 
/* NB that this is called also from fields.c where *aw is a temporary
158
 
 * but pend is from findpackage()! */
 
158
/*
 
159
 * Note: This is called also from fields.c where *aw is a temporary
 
160
 * but pend is from pkg_db_find()!
 
161
 *
 
162
 * @retval true  For done.
 
163
 * @retval false For already noted.
 
164
 */
159
165
bool
160
166
trig_note_aw(struct pkginfo *pend, struct pkginfo *aw)
161
167
{
219
225
 * while in modstatdb_note, and the package in triggers-pending had its
220
226
 * state modified but dpkg could not finish clearing the awaiters.
221
227
 *
222
 
 * XXX: possibly get rid of some of the checks done somewhere else for
 
228
 * XXX: Possibly get rid of some of the checks done somewhere else for
223
229
 *      this condition at run-time.
224
230
 */
225
231
void
238
244
        trig_awaited_pend_head = NULL;
239
245
}
240
246
 
241
 
/*---------- generalised handling of trigger kinds ----------*/
 
247
/*---------- Generalized handling of trigger kinds. ----------*/
242
248
 
243
249
struct trigkindinfo {
244
250
        /* Only for trig_activate_start. */
272
278
                return &tki_file;
273
279
        }
274
280
 
275
 
        if (!illegal_packagename(name, NULL) && !strchr(name, '_'))
 
281
        if (!pkg_name_is_illegal(name, NULL) && !strchr(name, '_'))
276
282
                return &tki_explicit;
277
283
 
278
284
invalid:
279
285
        return &tki_unknown;
280
286
}
281
287
 
282
 
/* Calling sequence is:
 
288
/*
 
289
 * Calling sequence is:
283
290
 *  trig_activate_start(triggername)
284
291
 *  dtki->activate_awaiter(awaiting_package) } zero or more times
285
292
 *  dtki->activate_awaiter(0)                }  in any order
293
300
        dtki->activate_start();
294
301
}
295
302
 
296
 
/*---------- unknown trigger kinds ----------*/
 
303
/*---------- Unknown trigger kinds. ----------*/
297
304
 
298
305
static void
299
306
trk_unknown_activate_start(void)
325
332
        .interest_change = trk_unknown_interest_change,
326
333
};
327
334
 
328
 
/*---------- explicit triggers ----------*/
 
335
/*---------- Explicit triggers. ----------*/
329
336
 
330
337
static FILE *trk_explicit_f;
331
338
static struct varbuf trk_explicit_fn;
345
352
{
346
353
        trk_explicit_activate_done();
347
354
 
348
 
        varbufreset(&trk_explicit_fn);
349
 
        varbufaddstr(&trk_explicit_fn, triggersdir);
350
 
        varbufaddstr(&trk_explicit_fn, trig);
351
 
        varbufaddc(&trk_explicit_fn, 0);
 
355
        varbuf_reset(&trk_explicit_fn);
 
356
        varbuf_add_str(&trk_explicit_fn, triggersdir);
 
357
        varbuf_add_str(&trk_explicit_fn, trig);
 
358
        varbuf_end_str(&trk_explicit_fn);
352
359
 
353
360
        trk_explicit_f = fopen(trk_explicit_fn.buf, "r");
354
361
        if (!trk_explicit_f) {
386
393
                        trk_explicit_fn.buf);
387
394
 
388
395
        while (trk_explicit_fgets(buf, sizeof(buf)) >= 0) {
389
 
                if ((emsg = illegal_packagename(buf, NULL)))
 
396
                emsg = pkg_name_is_illegal(buf, NULL);
 
397
                if (emsg)
390
398
                        ohshit(_("trigger interest file `%.250s' syntax error; "
391
399
                                 "illegal package name `%.250s': %.250s"),
392
400
                               trk_explicit_fn.buf, buf, emsg);
393
 
                pend = findpackage(buf);
 
401
                pend = pkg_db_find(buf);
394
402
                trig_record_activation(pend, aw, trk_explicit_trig);
395
403
        }
396
404
}
403
411
        FILE *nf;
404
412
 
405
413
        trk_explicit_start(trig);
406
 
        varbufreset(&newfn);
407
 
        varbufprintf(&newfn, "%s/%s.new", triggersdir, trig);
408
 
        varbufaddc(&newfn, 0);
 
414
        varbuf_reset(&newfn);
 
415
        varbuf_printf(&newfn, "%s/%s.new", triggersdir, trig);
409
416
 
410
417
        nf = fopen(newfn.buf, "w");
411
418
        if (!nf)
449
456
        .interest_change = trk_explicit_interest_change,
450
457
};
451
458
 
452
 
/*---------- file triggers ----------*/
 
459
/*---------- File triggers. ----------*/
453
460
 
454
461
static struct {
455
462
        struct trigfileint *head, *tail;
457
464
 
458
465
/*
459
466
 * Values:
460
 
 *  -1: not read,
461
 
 *   0: not edited
462
 
 *   1: edited
 
467
 *  -1: Not read.
 
468
 *   0: Not edited.
 
469
 *   1: Edited
463
470
 */
464
471
static int filetriggers_edited = -1;
465
472
 
466
 
/* Called by various people with signum -1 and +1 to mean remove and add
467
 
 * and also by trig_file_interests_ensure with signum +2 meaning add
 
473
/*
 
474
 * Called by various people with signum -1 and +1 to mean remove and add
 
475
 * and also by trig_file_interests_ensure() with signum +2 meaning add
468
476
 * but die if already present.
469
477
 */
470
478
static void
485
493
                if (tfi->pkg == pkg)
486
494
                        goto found;
487
495
 
488
 
        /* not found */
 
496
        /* Not found. */
489
497
        if (signum < 0)
490
498
                return;
491
499
 
505
513
        if (signum > 0)
506
514
                return;
507
515
 
508
 
        /* remove it: */
 
516
        /* Remove it: */
509
517
        *search = tfi->samefile_next;
510
518
        LIST_UNLINK_PART(filetriggers, tfi, inoverall.);
511
519
edited:
580
588
                        ohshit(_("syntax error in file triggers file `%.250s'"),
581
589
                               triggersfilefile);
582
590
                *space++ = '\0';
583
 
                if ((emsg = illegal_packagename(space, NULL)))
 
591
 
 
592
                emsg = pkg_name_is_illegal(space, NULL);
 
593
                if (emsg)
584
594
                        ohshit(_("file triggers record mentions illegal "
585
595
                                 "package name `%.250s' (for interest in file "
586
596
                                 "`%.250s'): %.250s"), space, linebuf, emsg);
587
 
                pkg = findpackage(space);
 
597
                pkg = pkg_db_find(space);
588
598
                trk_file_interest_change(linebuf, pkg, +2);
589
599
        }
590
600
        pop_cleanup(ehflag_normaltidy);
639
649
        .interest_change = trk_file_interest_change,
640
650
};
641
651
 
642
 
/*---------- trigger control info file ----------*/
 
652
/*---------- Trigger control info file. ----------*/
643
653
 
644
654
static void
645
655
trig_cicb_interest_change(const char *trig, struct pkginfo *pkg, int signum)
678
688
{
679
689
        const char *emsg;
680
690
 
681
 
        emsg = illegal_triggername(trig);
 
691
        emsg = trig_name_is_illegal(trig);
682
692
        if (emsg)
683
693
                ohshit(_("triggers ci file `%.250s' contains illegal trigger "
684
694
                         "syntax in trigger name `%.250s': %.250s"),
698
708
        f = fopen(file, "r");
699
709
        if (!f) {
700
710
                if (errno == ENOENT)
701
 
                        /* No file is just like an empty one. */
702
 
                        return;
 
711
                        return; /* No file is just like an empty one. */
703
712
                ohshite(_("unable to open triggers ci file `%.250s'"), file);
704
713
        }
705
714
        push_cleanup(cu_closefile, ~0, NULL, 0, 1, f);
728
737
                               cmd);
729
738
                }
730
739
        }
731
 
        pop_cleanup(ehflag_normaltidy); /* fclose */
 
740
        pop_cleanup(ehflag_normaltidy); /* fclose() */
732
741
}
733
742
 
734
 
/*---------- Unincorp file incorporation ----------*/
 
743
/*---------- Unincorp file incorporation. ----------*/
735
744
 
736
745
static void
737
746
tdm_incorp_trig_begin(const char *trig)
742
751
static void
743
752
tdm_incorp_package(const char *awname)
744
753
{
745
 
        struct pkginfo *aw = strcmp(awname, "-") ? findpackage(awname) : NULL;
 
754
        struct pkginfo *aw = strcmp(awname, "-") ? pkg_db_find(awname) : NULL;
746
755
 
747
756
        dtki->activate_awaiter(aw);
748
757
}
760
769
};
761
770
 
762
771
void
763
 
trig_incorporate(enum modstatdb_rw cstatus, const char *admindir)
 
772
trig_incorporate(enum modstatdb_rw cstatus)
764
773
{
765
 
        int ur;
 
774
        enum trigdef_update_status ur;
766
775
        enum trigdef_updateflags tduf;
767
776
 
768
777
        free(triggersdir);
769
 
        triggersdir = trig_get_triggersdir(admindir);
 
778
        triggersdir = dpkg_db_get_path(TRIGGERSDIR);
770
779
 
771
780
        free(triggersfilefile);
772
781
        triggersfilefile = trig_get_filename(triggersdir, "File");
784
793
                        tduf |= tduf_writeifenoent;
785
794
        }
786
795
 
787
 
        ur = trigdef_update_start(tduf, admindir);
788
 
        if (ur == -1 && cstatus >= msdbrw_write) {
 
796
        ur = trigdef_update_start(tduf);
 
797
        if (ur == tdus_error_no_dir && cstatus >= msdbrw_write) {
789
798
                if (mkdir(triggersdir, 0755)) {
790
799
                        if (errno != EEXIST)
791
800
                                ohshite(_("unable to create triggers state"
794
803
                        ohshite(_("unable to set ownership of triggers state"
795
804
                                  " directory `%.250s'"), triggersdir);
796
805
                }
797
 
                ur = trigdef_update_start(tduf, admindir);
 
806
                ur = trigdef_update_start(tduf);
798
807
        }
799
808
        switch (ur) {
800
 
        case -2:
 
809
        case tdus_error_empty_deferred:
801
810
                return;
802
 
        case -1:
803
 
        case -3:
 
811
        case tdus_error_no_dir:
 
812
        case tdus_error_no_deferred:
804
813
                if (!trigh.transitional_activate)
805
814
                        return;
806
815
        /* Fall through. */
807
 
        case 1:
 
816
        case tdus_no_deferred:
808
817
                trigh.transitional_activate(cstatus);
809
818
                break;
810
 
        case 2:
 
819
        case tdus_ok:
811
820
                /* Read and incorporate triggers. */
812
821
                trigdef_parse();
813
822
                break;
819
828
        trigdef_process_done();
820
829
}
821
830
 
822
 
/*---------- default hooks ----------*/
 
831
/*---------- Default hooks. ----------*/
823
832
 
824
833
struct filenamenode {
825
834
        struct filenamenode *next;
837
846
        for (search = trigger_files; search; search = search->next)
838
847
                if (!strcmp(search->name, name))
839
848
                        return search;
 
849
 
840
850
        /* Not found. */
841
851
        if (nonew)
842
852
                return NULL;