[lxc-devel] [lxc/master] Centralize hook names
Rachid-Koucha on Github
lxc-bot at linuxcontainers.org
Wed Jun 12 06:37:24 UTC 2019
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 449 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190611/8c36b1b8/attachment.bin>
-------------- next part --------------
From 3ea957c616fd91276f527be04db4f46b1d3ec083 Mon Sep 17 00:00:00 2001
From: Rachid Koucha <47061324+Rachid-Koucha at users.noreply.github.com>
Date: Wed, 12 Jun 2019 08:36:40 +0200
Subject: [PATCH] Centralize hook names
The hook string names must not be repeated in the source code to facilitate future changes
Signed-off-by: Rachid Koucha <rachid.koucha at gmail.com>
---
src/lxc/conf.c | 31 ++++++++-----------------------
1 file changed, 8 insertions(+), 23 deletions(-)
diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index a729005298..d7d9ad902c 100644
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -3754,29 +3754,14 @@ int run_lxc_hooks(const char *name, char *hookname, struct lxc_conf *conf,
char *argv[])
{
struct lxc_list *it;
- int which = -1;
-
- if (strcmp(hookname, "pre-start") == 0)
- which = LXCHOOK_PRESTART;
- else if (strcmp(hookname, "start-host") == 0)
- which = LXCHOOK_START_HOST;
- else if (strcmp(hookname, "pre-mount") == 0)
- which = LXCHOOK_PREMOUNT;
- else if (strcmp(hookname, "mount") == 0)
- which = LXCHOOK_MOUNT;
- else if (strcmp(hookname, "autodev") == 0)
- which = LXCHOOK_AUTODEV;
- else if (strcmp(hookname, "start") == 0)
- which = LXCHOOK_START;
- else if (strcmp(hookname, "stop") == 0)
- which = LXCHOOK_STOP;
- else if (strcmp(hookname, "post-stop") == 0)
- which = LXCHOOK_POSTSTOP;
- else if (strcmp(hookname, "clone") == 0)
- which = LXCHOOK_CLONE;
- else if (strcmp(hookname, "destroy") == 0)
- which = LXCHOOK_DESTROY;
- else
+ int which;
+
+ for (which = 0; which < NUM_LXC_HOOKS; which ++) {
+ if (strcmp(hookname, lxchook_names[which]) == 0)
+ break;
+ }
+
+ if (which >= NUM_LXC_HOOKS)
return -1;
lxc_list_for_each (it, &conf->hooks[which]) {
More information about the lxc-devel
mailing list