[PATCH 2/4] drmgr: Add action parameter to the hook mechanism

2 views
Skip to first unread message

Laurent Dufour

<ldufour@linux.ibm.com>
unread,
Mar 7, 2023, 8:22:19 AM3/7/23
to powerpc-utils-devel@googlegroups.com, tyreld@linux.ibm.com, nathanl@linux.ibm.com
The user action is now exported to the hook ran by drmgr.
It is exported in the environment variable ACTION.

Signed-off-by: Laurent Dufour <ldu...@linux.ibm.com>
---
src/drmgr/common.c | 10 ++++++----
src/drmgr/dr.h | 2 +-
src/drmgr/drmig_chrp_pmig.c | 8 ++++----
3 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/src/drmgr/common.c b/src/drmgr/common.c
index b80d01e5c75f..e7cc2dd08f17 100644
--- a/src/drmgr/common.c
+++ b/src/drmgr/common.c
@@ -1566,8 +1566,8 @@ enum drc_type to_drc_type(const char *arg)
return DRC_TYPE_NONE;
}

-static int run_one_hook(enum drc_type drc_type, enum hook_phase phase,
- const char *name)
+static int run_one_hook(enum drc_type drc_type, enum drmgr_action action,
+ enum hook_phase phase, const char *name)
{
int rc;
pid_t child;
@@ -1613,6 +1613,7 @@ static int run_one_hook(enum drc_type drc_type, enum hook_phase phase,

if (clearenv() ||
setenv("DRC_TYPE", drc_type_str[drc_type], 1) ||
+ setenv("ACTION", hook_action_name[action], 1) ||
setenv("PHASE", hook_phase_name[phase], 1)) {
say(ERROR, "Can't set environment variables: %s\n",
strerror(errno));
@@ -1635,7 +1636,8 @@ static int is_file_or_link(const struct dirent *entry)
* Run all executable hooks found in a given directory.
* Return 0 if all run script have returned 0 status.
*/
-int run_hooks(enum drc_type drc_type, enum hook_phase phase)
+int run_hooks(enum drc_type drc_type, enum drmgr_action action,
+ enum hook_phase phase)
{
int rc = 0, fdd, num, i;
DIR *dir;
@@ -1691,7 +1693,7 @@ int run_hooks(enum drc_type drc_type, enum hook_phase phase)
say(WARN, "Can't stat file %s: %s\n",
name, strerror(errno));
else if (S_ISREG(st.st_mode) && (st.st_mode & S_IXUSR) &&
- run_one_hook(drc_type, phase, name))
+ run_one_hook(drc_type, action, phase, name))
rc = 1;

free(name);
diff --git a/src/drmgr/dr.h b/src/drmgr/dr.h
index 5526c29a9460..5556f05252e7 100644
--- a/src/drmgr/dr.h
+++ b/src/drmgr/dr.h
@@ -135,7 +135,7 @@ void print_dlpar_capabilities(void);

void set_output_level(int);

-int run_hooks(enum drc_type drc_type, enum hook_phase phase);
+int run_hooks(enum drc_type drc_type, enum drmgr_action, enum hook_phase phase);

#define DR_BUF_SZ 256

diff --git a/src/drmgr/drmig_chrp_pmig.c b/src/drmgr/drmig_chrp_pmig.c
index f169fa500316..f537d9accd36 100644
--- a/src/drmgr/drmig_chrp_pmig.c
+++ b/src/drmgr/drmig_chrp_pmig.c
@@ -709,9 +709,9 @@ int drmig_chrp_pmig(void)
}

if (usr_action == MIGRATE && (strcmp(usr_p_option, "check") == 0)) {
- rc = run_hooks(drc_type, HOOK_CHECK);
+ rc = run_hooks(drc_type, usr_action, HOOK_CHECK);
if (rc)
- run_hooks(drc_type, HOOK_UNDOCHECK);
+ run_hooks(drc_type, usr_action, HOOK_UNDOCHECK);
return rc;
}

@@ -736,7 +736,7 @@ int drmig_chrp_pmig(void)
/* Now do the actual migration */
do {
if (usr_action == MIGRATE)
- run_hooks(drc_type, HOOK_PRE);
+ run_hooks(drc_type, usr_action, HOOK_PRE);

if (usr_action == MIGRATE)
rc = do_migration(stream_val);
@@ -758,6 +758,6 @@ int drmig_chrp_pmig(void)

/* Post hook is called even if the migration has failed */
if (usr_action == MIGRATE)
- run_hooks(drc_type, HOOK_POST);
+ run_hooks(drc_type, usr_action, HOOK_POST);
return rc;
}
--
2.39.2

Reply all
Reply to author
Forward
0 new messages