Просмотр исходного кода

libdpkg: Add new trig_override_hooks to avoid exposing trigh

Make trigh static and create an overrider function for it.
Guillem Jover лет назад: 16
Родитель
Сommit
8ff7219457
3 измененных файлов с 11 добавлено и 4 удалено
  1. 2 2
      lib/dpkg/dpkg-db.h
  2. 8 1
      lib/dpkg/triglib.c
  3. 1 1
      src/trigproc.c

+ 2 - 2
lib/dpkg/dpkg-db.h

@@ -276,14 +276,14 @@ struct trig_hooks {
   const char *(*namenode_name)(struct filenamenode *fnn);
 };
 
-extern struct trig_hooks trigh;
-
 #define TRIGHOOKS_DEFINE_NAMENODE_ACCESSORS				 \
   static struct trigfileint **th_nn_interested(struct filenamenode *fnn) \
     { return &fnn->trig_interested; }					 \
   static const char *th_nn_name(struct filenamenode *fnn)		 \
     { return fnn->name; }
 
+void trig_override_hooks(const struct trig_hooks *hooks);
+
 /*** from triglib.c ***/
 
 void trig_file_activate_byname(const char *trig, struct pkginfo *aw);

+ 8 - 1
lib/dpkg/triglib.c

@@ -53,6 +53,8 @@ illegal_triggername(const char *p)
 
 /*========== recording triggers ==========*/
 
+static struct trig_hooks trigh;
+
 /*---------- noting trigger activation in memory ----------*/
 
 /* Called via trig_*activate* et al from:
@@ -799,7 +801,7 @@ th_simple_nn_find(const char *name, int nonew)
 
 TRIGHOOKS_DEFINE_NAMENODE_ACCESSORS
 
-struct trig_hooks trigh = {
+static struct trig_hooks trigh = {
 	.enqueue_deferred = NULL,
 	.transitional_activate = NULL,
 	.namenode_find = th_simple_nn_find,
@@ -807,3 +809,8 @@ struct trig_hooks trigh = {
 	.namenode_name = th_nn_name,
 };
 
+void
+trig_override_hooks(const struct trig_hooks *hooks)
+{
+	trigh = *hooks;
+}

+ 1 - 1
src/trigproc.c

@@ -397,6 +397,6 @@ static const struct trig_hooks trig_our_hooks = {
 void
 trigproc_install_hooks(void)
 {
-	trigh = trig_our_hooks;
+	trig_override_hooks(&trig_our_hooks);
 }