[Reproducible-commits] [dpkg] 21/63: dpkg: Add a new struct invoke_list to store invoke hooks
Jérémy Bobbio
lunar at moszumanska.debian.org
Fri Mar 4 17:44:42 UTC 2016
This is an automated email from the git hooks/post-receive script.
lunar pushed a commit to branch pu/buildinfo
in repository dpkg.
commit 9c6738c3fed06c9e8a81b8118d79789c25df6594
Author: Guillem Jover <guillem at debian.org>
Date: Tue Feb 16 09:27:40 2016 +0100
dpkg: Add a new struct invoke_list to store invoke hooks
This gets rid of the pointer to pointer to pointer handling, by
simplifying and structuring things a bit.
---
src/main.c | 35 ++++++++++++++++-------------------
src/main.h | 4 ++++
2 files changed, 20 insertions(+), 19 deletions(-)
diff --git a/src/main.c b/src/main.c
index 0ff04f1..cd4211b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -426,17 +426,14 @@ is_invoke_action(enum action action)
}
}
-struct invoke_hook *pre_invoke_hooks = NULL;
-struct invoke_hook **pre_invoke_hooks_tail = &pre_invoke_hooks;
-struct invoke_hook *post_invoke_hooks = NULL;
-struct invoke_hook **post_invoke_hooks_tail = &post_invoke_hooks;
-struct invoke_hook *status_loggers = NULL;
-struct invoke_hook **status_loggers_tail = &status_loggers;
+struct invoke_list pre_invoke_hooks = { .head = NULL, .tail = &pre_invoke_hooks.head };
+struct invoke_list post_invoke_hooks = { .head = NULL, .tail = &post_invoke_hooks.head };
+struct invoke_list status_loggers = { .head = NULL, .tail = &status_loggers.head };
static void
set_invoke_hook(const struct cmdinfo *cip, const char *value)
{
- struct invoke_hook ***hook_tail = cip->arg_ptr;
+ struct invoke_list *hook_list = cip->arg_ptr;
struct invoke_hook *hook_new;
hook_new = nfmalloc(sizeof(struct invoke_hook));
@@ -444,18 +441,18 @@ set_invoke_hook(const struct cmdinfo *cip, const char *value)
hook_new->next = NULL;
/* Add the new hook at the tail of the list to preserve the order. */
- **hook_tail = hook_new;
- *hook_tail = &hook_new->next;
+ *hook_list->tail = hook_new;
+ hook_list->tail = &hook_new->next;
}
static void
-run_invoke_hooks(const char *action, struct invoke_hook *hook_head)
+run_invoke_hooks(const char *action, struct invoke_list *hook_list)
{
struct invoke_hook *hook;
setenv("DPKG_HOOK_ACTION", action, 1);
- for (hook = hook_head; hook; hook = hook->next) {
+ for (hook = hook_list->head; hook; hook = hook->next) {
int status;
/* XXX: As an optimization, use exec instead if no shell metachar are
@@ -494,11 +491,11 @@ run_logger(struct invoke_hook *hook, const char *name)
}
static void
-run_status_loggers(struct invoke_hook *hook_head)
+run_status_loggers(struct invoke_list *hook_list)
{
struct invoke_hook *hook;
- for (hook = hook_head; hook; hook = hook->next) {
+ for (hook = hook_list->head; hook; hook = hook->next) {
int fd;
fd = run_logger(hook, _("status logger"));
@@ -698,12 +695,12 @@ static const struct cmdinfo cmdinfos[]= {
ACTION( "command-fd", 'c', act_commandfd, commandfd ),
*/
- { "pre-invoke", 0, 1, NULL, NULL, set_invoke_hook, 0, &pre_invoke_hooks_tail },
- { "post-invoke", 0, 1, NULL, NULL, set_invoke_hook, 0, &post_invoke_hooks_tail },
+ { "pre-invoke", 0, 1, NULL, NULL, set_invoke_hook, 0, &pre_invoke_hooks },
+ { "post-invoke", 0, 1, NULL, NULL, set_invoke_hook, 0, &post_invoke_hooks },
{ "path-exclude", 0, 1, NULL, NULL, set_filter, 0 },
{ "path-include", 0, 1, NULL, NULL, set_filter, 1 },
{ "verify-format", 0, 1, NULL, NULL, set_verify_format },
- { "status-logger", 0, 1, NULL, NULL, set_invoke_hook, 0, &status_loggers_tail },
+ { "status-logger", 0, 1, NULL, NULL, set_invoke_hook, 0, &status_loggers },
{ "status-fd", 0, 1, NULL, NULL, set_pipe, 0 },
{ "log", 0, 1, NULL, &log_file, NULL, 0 },
{ "pending", 'a', 0, &f_pending, NULL, NULL, 1 },
@@ -884,8 +881,8 @@ int main(int argc, const char *const *argv) {
f_triggers = (cipaction->arg_int == act_triggers && *argv) ? -1 : 1;
if (is_invoke_action(cipaction->arg_int)) {
- run_invoke_hooks(cipaction->olong, pre_invoke_hooks);
- run_status_loggers(status_loggers);
+ run_invoke_hooks(cipaction->olong, &pre_invoke_hooks);
+ run_status_loggers(&status_loggers);
}
filesdbinit();
@@ -893,7 +890,7 @@ int main(int argc, const char *const *argv) {
ret = cipaction->action(argv);
if (is_invoke_action(cipaction->arg_int))
- run_invoke_hooks(cipaction->olong, post_invoke_hooks);
+ run_invoke_hooks(cipaction->olong, &post_invoke_hooks);
dpkg_program_done();
diff --git a/src/main.h b/src/main.h
index 021d611..cc8dfa7 100644
--- a/src/main.h
+++ b/src/main.h
@@ -153,6 +153,10 @@ struct invoke_hook {
const char *command;
};
+struct invoke_list {
+ struct invoke_hook *head, **tail;
+};
+
/* from archives.c */
int archivefiles(const char *const *argv);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/dpkg.git
More information about the Reproducible-commits
mailing list