58
/*========== recording triggers ==========*/
58
/*========== Recording triggers. ==========*/
60
60
static char *triggersdir, *triggersfilefile, *triggersnewfilefile;
63
trig_get_triggersdir(const char *admindir)
65
struct varbuf path = VARBUF_INIT;
67
varbufprintf(&path, "%s/%s", admindir, TRIGGERSDIR);
69
return varbuf_detach(&path);
73
63
trig_get_filename(const char *dir, const char *filename)
75
struct varbuf path = VARBUF_INIT;
77
varbufprintf(&path, "%s/%s", dir, filename);
79
return varbuf_detach(&path);
67
m_asprintf(&path, "%s/%s", dir, filename);
82
72
static struct trig_hooks trigh;
84
/*---------- noting trigger activation in memory ----------*/
74
/*---------- Noting trigger activation in memory. ----------*/
86
/* Called via trig_*activate* et al from:
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
94
85
* recorded (how would we know?) and (b) we don't enqueue them for
95
86
* deferred processing in this run.
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.)
103
/* aw might be NULL, and trig is not copied! */
105
99
trig_record_activation(struct pkginfo *pend, struct pkginfo *aw, const char *trig)
107
101
if (pend->status < stat_triggersawaited)
108
/* Not interested then. */
102
return; /* Not interested then. */
111
104
if (trig_note_pend(pend, trig))
112
105
modstatdb_note_ifwrite(pend);
125
/* NB that this is also called from fields.c where *pend is a temporary! */
119
* Note: This is also called from fields.c where *pend is a temporary!
121
* trig is not copied!
127
trig_note_pend_core(struct pkginfo *pend, const char *trig /*not copied!*/)
124
trig_note_pend_core(struct pkginfo *pend, const char *trig)
129
126
struct trigpend *tp;
143
/* Returns: true for done, false for already noted. */
141
* trig is not copied!
143
* @retval true For done.
144
* @retval false For already noted.
145
trig_note_pend(struct pkginfo *pend, const char *trig /*not copied!*/)
147
trig_note_pend(struct pkginfo *pend, const char *trig)
147
149
if (!trig_note_pend_core(pend, trig))
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()! */
159
* Note: This is called also from fields.c where *aw is a temporary
160
* but pend is from pkg_db_find()!
162
* @retval true For done.
163
* @retval false For already noted.
160
166
trig_note_aw(struct pkginfo *pend, struct pkginfo *aw)
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.
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.
272
278
return &tki_file;
275
if (!illegal_packagename(name, NULL) && !strchr(name, '_'))
281
if (!pkg_name_is_illegal(name, NULL) && !strchr(name, '_'))
276
282
return &tki_explicit;
279
285
return &tki_unknown;
282
/* Calling sequence is:
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
325
332
.interest_change = trk_unknown_interest_change,
328
/*---------- explicit triggers ----------*/
335
/*---------- Explicit triggers. ----------*/
330
337
static FILE *trk_explicit_f;
331
338
static struct varbuf trk_explicit_fn;
346
353
trk_explicit_activate_done();
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);
353
360
trk_explicit_f = fopen(trk_explicit_fn.buf, "r");
354
361
if (!trk_explicit_f) {
386
393
trk_explicit_fn.buf);
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);
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);
405
413
trk_explicit_start(trig);
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);
410
417
nf = fopen(newfn.buf, "w");
449
456
.interest_change = trk_explicit_interest_change,
452
/*---------- file triggers ----------*/
459
/*---------- File triggers. ----------*/
455
462
struct trigfileint *head, *tail;
464
471
static int filetriggers_edited = -1;
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
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.
580
588
ohshit(_("syntax error in file triggers file `%.250s'"),
581
589
triggersfilefile);
583
if ((emsg = illegal_packagename(space, NULL)))
592
emsg = pkg_name_is_illegal(space, NULL);
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);
590
600
pop_cleanup(ehflag_normaltidy);
639
649
.interest_change = trk_file_interest_change,
642
/*---------- trigger control info file ----------*/
652
/*---------- Trigger control info file. ----------*/
645
655
trig_cicb_interest_change(const char *trig, struct pkginfo *pkg, int signum)
679
689
const char *emsg;
681
emsg = illegal_triggername(trig);
691
emsg = trig_name_is_illegal(trig);
683
693
ohshit(_("triggers ci file `%.250s' contains illegal trigger "
684
694
"syntax in trigger name `%.250s': %.250s"),
698
708
f = fopen(file, "r");
700
710
if (errno == ENOENT)
701
/* No file is just like an empty one. */
711
return; /* No file is just like an empty one. */
703
712
ohshite(_("unable to open triggers ci file `%.250s'"), file);
705
714
push_cleanup(cu_closefile, ~0, NULL, 0, 1, f);
731
pop_cleanup(ehflag_normaltidy); /* fclose */
740
pop_cleanup(ehflag_normaltidy); /* fclose() */
734
/*---------- Unincorp file incorporation ----------*/
743
/*---------- Unincorp file incorporation. ----------*/
737
746
tdm_incorp_trig_begin(const char *trig)
743
752
tdm_incorp_package(const char *awname)
745
struct pkginfo *aw = strcmp(awname, "-") ? findpackage(awname) : NULL;
754
struct pkginfo *aw = strcmp(awname, "-") ? pkg_db_find(awname) : NULL;
747
756
dtki->activate_awaiter(aw);
763
trig_incorporate(enum modstatdb_rw cstatus, const char *admindir)
772
trig_incorporate(enum modstatdb_rw cstatus)
774
enum trigdef_update_status ur;
766
775
enum trigdef_updateflags tduf;
768
777
free(triggersdir);
769
triggersdir = trig_get_triggersdir(admindir);
778
triggersdir = dpkg_db_get_path(TRIGGERSDIR);
771
780
free(triggersfilefile);
772
781
triggersfilefile = trig_get_filename(triggersdir, "File");
784
793
tduf |= tduf_writeifenoent;
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);
797
ur = trigdef_update_start(tduf, admindir);
806
ur = trigdef_update_start(tduf);
809
case tdus_error_empty_deferred:
811
case tdus_error_no_dir:
812
case tdus_error_no_deferred:
804
813
if (!trigh.transitional_activate)
806
815
/* Fall through. */
816
case tdus_no_deferred:
808
817
trigh.transitional_activate(cstatus);
811
820
/* Read and incorporate triggers. */