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@gmail.com>
This commit is contained in:
Rachid Koucha 2019-06-12 08:36:40 +02:00 committed by GitHub
parent 16512e0c36
commit 3ea957c616
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3754,29 +3754,14 @@ int run_lxc_hooks(const char *name, char *hookname, struct lxc_conf *conf,
char *argv[]) char *argv[])
{ {
struct lxc_list *it; struct lxc_list *it;
int which = -1; int which;
if (strcmp(hookname, "pre-start") == 0) for (which = 0; which < NUM_LXC_HOOKS; which ++) {
which = LXCHOOK_PRESTART; if (strcmp(hookname, lxchook_names[which]) == 0)
else if (strcmp(hookname, "start-host") == 0) break;
which = LXCHOOK_START_HOST; }
else if (strcmp(hookname, "pre-mount") == 0)
which = LXCHOOK_PREMOUNT; if (which >= NUM_LXC_HOOKS)
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
return -1; return -1;
lxc_list_for_each (it, &conf->hooks[which]) { lxc_list_for_each (it, &conf->hooks[which]) {