The following commit has been merged in the master branch:
commit a35f0e37a46b2e3721149a25c36f3352c1cdf881
Author: Guillem Jover <[email protected]>
Date: Thu Mar 11 19:38:12 2010 +0100
libdpkg: Encapsulate triggersdir handling in triglib
The only users of triggersdir and related files are the triglib and
trigdeferred modules, and dbmodify does not have any business in knowing
where the triggersdir is located (besides for conveninence when creating
the pathname). Create instead a new function trig_get_triggersdir() to
generate the triggersdir from an admindir, and use that on each module.
diff --git a/lib/dpkg/dbmodify.c b/lib/dpkg/dbmodify.c
index a642453..a476fa2 100644
--- a/lib/dpkg/dbmodify.c
+++ b/lib/dpkg/dbmodify.c
@@ -44,7 +44,6 @@
#include <dpkg/file.h>
char *statusfile=NULL, *availablefile=NULL;
-char *triggersdir, *triggersfilefile, *triggersnewfilefile;
static enum modstatdb_rw cstatus=-1, cflags=0;
static char *importanttmpfile=NULL;
@@ -134,9 +133,6 @@ static const struct fni {
{ STATUSFILE, &statusfile },
{ AVAILFILE, &availablefile },
{ UPDATESDIR IMPORTANTTMP, &importanttmpfile },
- { TRIGGERSDIR, &triggersdir },
- { TRIGGERSDIR "/File", &triggersfilefile },
- { TRIGGERSDIR "/File.new", &triggersnewfilefile},
{ NULL, NULL }
};
diff --git a/lib/dpkg/dpkg-db.h b/lib/dpkg/dpkg-db.h
index 8c1b7c7..292fb61 100644
--- a/lib/dpkg/dpkg-db.h
+++ b/lib/dpkg/dpkg-db.h
@@ -210,7 +210,6 @@ void modstatdb_shutdown(void);
/* Initialised by modstatdb_init. */
extern char *statusfile, *availablefile;
-extern char *triggersdir, *triggersfilefile, *triggersnewfilefile;
const char *pkgadminfile(struct pkginfo *pkg, const char *whichfile);
@@ -286,6 +285,8 @@ void trig_override_hooks(const struct trig_hooks *hooks);
/*** from triglib.c ***/
+char *trig_get_triggersdir(const char *admindir);
+
void trig_file_activate_byname(const char *trig, struct pkginfo *aw);
void trig_file_activate(struct filenamenode *trig, struct pkginfo *aw);
diff --git a/lib/dpkg/trigdeferred.l b/lib/dpkg/trigdeferred.l
index 9d3ca45..4f410ea 100644
--- a/lib/dpkg/trigdeferred.l
+++ b/lib/dpkg/trigdeferred.l
@@ -87,6 +87,7 @@ static const struct trigdefmeths *trigdef;
/*---------- Deferred file handling ----------*/
+static const char *triggersdir;
static int lock_fd = -1;
static FILE *old_deferred;
static FILE *trig_new_deferred;
@@ -107,6 +108,8 @@ trigdef_update_start(enum trigdef_updateflags uf, const
char *admindir)
struct stat stab;
int r;
+ triggersdir = trig_get_triggersdir(admindir);
+
if (uf & tduf_write) {
constructfn(&fn, admindir, TRIGGERSLOCKFILE);
if (lock_fd == -1) {
diff --git a/lib/dpkg/triglib.c b/lib/dpkg/triglib.c
index c7c6924..6fc49d5 100644
--- a/lib/dpkg/triglib.c
+++ b/lib/dpkg/triglib.c
@@ -27,6 +27,7 @@
#include <assert.h>
#include <errno.h>
+#include <stdlib.h>
#include <unistd.h>
#include <dpkg/i18n.h>
@@ -53,6 +54,28 @@ illegal_triggername(const char *p)
/*========== recording triggers ==========*/
+static char *triggersdir, *triggersfilefile, *triggersnewfilefile;
+
+char *
+trig_get_triggersdir(const char *admindir)
+{
+ struct varbuf path = VARBUF_INIT;
+
+ varbufprintf(&path, "%s/%s", admindir, TRIGGERSDIR);
+
+ return varbuf_detach(&path);
+}
+
+static char *
+trig_get_filename(const char *dir, const char *filename)
+{
+ struct varbuf path = VARBUF_INIT;
+
+ varbufprintf(&path, "%s/%s", dir, filename);
+
+ return varbuf_detach(&path);
+}
+
static struct trig_hooks trigh;
/*---------- noting trigger activation in memory ----------*/
@@ -735,6 +758,15 @@ trig_incorporate(enum modstatdb_rw cstatus, const char
*admindir)
int ur;
enum trigdef_updateflags tduf;
+ free(triggersdir);
+ triggersdir = trig_get_triggersdir(admindir);
+
+ free(triggersfilefile);
+ triggersfilefile = trig_get_filename(triggersdir, "File");
+
+ free(triggersnewfilefile);
+ triggersnewfilefile = trig_get_filename(triggersdir, "File.new");
+
trigdef_set_methods(&tdm_incorp);
trig_file_interests_ensure();
--
dpkg's main repository
--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]