summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillem Jover <guillem@debian.org>2018-04-04 03:06:44 +0200
committerGuillem Jover <guillem@debian.org>2018-05-03 02:22:27 +0200
commit2d7566140335d5338e5a98278d4df762936f67f4 (patch)
tree714cb7537c23da829dadc9bd68d2ad2927c17459
parentf1cc66e522a475710aa51a6d164a8cc0eda3cae7 (diff)
downloaddpkg-2d7566140335d5338e5a98278d4df762936f67f4.tar.gz
libdpkg: Use a single struct filenamenode definition
The struct filenamenode hash implementation is lightweight, and once split from the bulk of the on-disk database handling there's no point in reimplementing it, and then redefining the same struct in multiple places, which is rather confusing for the reader, and even for static analyzers. Closes: #746766
-rw-r--r--debian/changelog2
-rw-r--r--lib/dpkg/triglib.c32
-rw-r--r--lib/dpkg/triglib.h3
-rw-r--r--src/trigcmd.c2
-rw-r--r--src/trigproc.c8
5 files changed, 9 insertions, 38 deletions
diff --git a/debian/changelog b/debian/changelog
index 123ef6764..afe1d4ab1 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -51,6 +51,8 @@ dpkg (1.19.1) UNRELEASED; urgency=medium
behavior, but it will make it possible to do a default switch in 1.20.x.
* Warn when using dpkg-divert --add or --remove w/o --rename or --no-rename.
* Warn when using dpkg-divert --rename on a file from an Essential package.
+ * Use a single “struct filenamenode” definition for the entire code base.
+ Closes: #746766
* Architecture support:
- Add support for riscv64 CPU. Closes: #822914
Thanks to Manuel A. Fernandez Montecelo <mafm@debian.org>
diff --git a/lib/dpkg/triglib.c b/lib/dpkg/triglib.c
index a067d1450..395601359 100644
--- a/lib/dpkg/triglib.c
+++ b/lib/dpkg/triglib.c
@@ -821,42 +821,12 @@ trig_incorporate(enum modstatdb_rw cstatus)
/*---------- Default hooks. ----------*/
-struct filenamenode {
- struct filenamenode *next;
- const char *name;
- struct trigfileint *trig_interested;
-};
-
-static struct filenamenode *trigger_files;
-
-static struct filenamenode *
-th_simple_nn_find(const char *name, bool nonew)
-{
- struct filenamenode *search;
-
- for (search = trigger_files; search; search = search->next)
- if (strcmp(search->name, name) == 0)
- return search;
-
- /* Not found. */
- if (nonew)
- return NULL;
-
- search = nfmalloc(sizeof(*search));
- search->name = nfstrsave(name);
- search->trig_interested = NULL;
- search->next = trigger_files;
- trigger_files = search;
-
- return search;
-}
-
TRIGHOOKS_DEFINE_NAMENODE_ACCESSORS
static struct trig_hooks trigh = {
.enqueue_deferred = NULL,
.transitional_activate = NULL,
- .namenode_find = th_simple_nn_find,
+ .namenode_find = th_nn_find,
.namenode_interested = th_nn_interested,
.namenode_name = th_nn_name,
};
diff --git a/lib/dpkg/triglib.h b/lib/dpkg/triglib.h
index 3e63f5cbc..74b33ccb2 100644
--- a/lib/dpkg/triglib.h
+++ b/lib/dpkg/triglib.h
@@ -25,6 +25,7 @@
#include <dpkg/macros.h>
#include <dpkg/dpkg-db.h>
+#include <dpkg/fsys.h>
DPKG_BEGIN_DECLS
@@ -78,6 +79,8 @@ struct trig_hooks {
};
#define TRIGHOOKS_DEFINE_NAMENODE_ACCESSORS \
+ static struct filenamenode *th_nn_find(const char *name, bool nonew) \
+ { return findnamenode(name, nonew ? fnn_nonew : 0); } \
static struct trigfileint **th_nn_interested(struct filenamenode *fnn) \
{ return &fnn->trig_interested; } \
static const char *th_nn_name(struct filenamenode *fnn) \
diff --git a/src/trigcmd.c b/src/trigcmd.c
index 312cd8718..bc0d2f9a2 100644
--- a/src/trigcmd.c
+++ b/src/trigcmd.c
@@ -229,6 +229,8 @@ main(int argc, const char *const *argv)
badusage(_("illegal awaited package name '%.250s': %.250s"),
bypackage, badname);
+ filesdbinit();
+
activate = argv[0];
badname = trig_name_is_illegal(activate);
if (badname)
diff --git a/src/trigproc.c b/src/trigproc.c
index 9c73d4ca6..7b6537bb4 100644
--- a/src/trigproc.c
+++ b/src/trigproc.c
@@ -534,18 +534,12 @@ trig_transitional_activate(enum modstatdb_rw cstatus)
/*========== Hook setup. ==========*/
-static struct filenamenode *
-th_proper_nn_find(const char *name, bool nonew)
-{
- return findnamenode(name, nonew ? fnn_nonew : 0);
-}
-
TRIGHOOKS_DEFINE_NAMENODE_ACCESSORS
static const struct trig_hooks trig_our_hooks = {
.enqueue_deferred = trigproc_enqueue_deferred,
.transitional_activate = trig_transitional_activate,
- .namenode_find = th_proper_nn_find,
+ .namenode_find = th_nn_find,
.namenode_interested = th_nn_interested,
.namenode_name = th_nn_name,
};