The new DRC_COUNT will be set when running operation on countable items,
like adding or removing CPUs.
For the migration operation, this doesn't make sense and it is set to 0.
Using a signed integer so we can pass signed values, if needed in the
future.
src/drmgr/common.c | 17 ++++++++++++++---
src/drmgr/dr.h | 3 ++-
src/drmgr/drmig_chrp_pmig.c | 8 ++++----
3 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/src/drmgr/common.c b/src/drmgr/common.c
index 1d1afb94128a..bfec0b9bb966 100644
--- a/src/drmgr/common.c
+++ b/src/drmgr/common.c
@@ -1567,7 +1567,8 @@ enum drc_type to_drc_type(const char *arg)
}
static int run_one_hook(enum drc_type drc_type, enum drmgr_action action,
- enum hook_phase phase, const char *name)
+ enum hook_phase phase, const char *drc_count_str,
+ const char *name)
{
int rc;
pid_t child;
@@ -1613,6 +1614,7 @@ static int run_one_hook(enum drc_type drc_type, enum drmgr_action action,
if (clearenv() ||
setenv("DRC_TYPE", drc_type_str[drc_type], 1) ||
+ setenv("DRC_COUNT", drc_count_str, 1) ||
setenv("ACTION", hook_action_name[action], 1) ||
setenv("PHASE", hook_phase_name[phase], 1)) {
say(ERROR, "Can't set environment variables: %s\n",
@@ -1637,11 +1639,12 @@ static int is_file_or_link(const struct dirent *entry)
* Return 0 if all run script have returned 0 status.
*/
int run_hooks(enum drc_type drc_type, enum drmgr_action action,
- enum hook_phase phase)
+ enum hook_phase phase, int drc_count)
{
int rc = 0, fdd, num, i;
DIR *dir;
struct dirent **entries = NULL;
+ char *drc_count_str;
/* Sanity check */
if (drc_type <= DRC_TYPE_NONE || drc_type >= ARRAY_SIZE(drc_type_str)) {
@@ -1668,6 +1671,12 @@ int run_hooks(enum drc_type drc_type, enum drmgr_action action,
is_file_or_link, versionsort);
closedir(dir);
+ if (asprintf(&drc_count_str, "%d", drc_count) == -1) {
+ say(ERROR, "Can't allocate new string : %s", strerror(errno));
+ free(entries);
+ return -1;
+ }
+
for (i = 0; i < num; i++) {
struct stat st;
struct dirent *entry = entries[i];
@@ -1693,13 +1702,15 @@ int run_hooks(enum drc_type drc_type, enum drmgr_action action,
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, action, phase, name))
+ run_one_hook(drc_type, action, phase, drc_count_str,
+ name))
rc = 1;
free(name);
free(entry);
}
+ free(drc_count_str);
free(entries);
return rc;
}
diff --git a/src/drmgr/dr.h b/src/drmgr/dr.h
index 5556f05252e7..60c31c44b7e3 100644
--- a/src/drmgr/dr.h
+++ b/src/drmgr/dr.h
@@ -135,7 +135,8 @@ void print_dlpar_capabilities(void);
void set_output_level(int);
-int run_hooks(enum drc_type drc_type, enum drmgr_action, enum hook_phase phase);
+int run_hooks(enum drc_type drc_type, enum drmgr_action, enum hook_phase phase,
+ int drc_count);
#define DR_BUF_SZ 256
diff --git a/src/drmgr/drmig_chrp_pmig.c b/src/drmgr/drmig_chrp_pmig.c
index f537d9accd36..ab5cee913ce2 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, usr_action, HOOK_CHECK);
+ rc = run_hooks(drc_type, usr_action, HOOK_CHECK, 0);
if (rc)
- run_hooks(drc_type, usr_action, HOOK_UNDOCHECK);
+ run_hooks(drc_type, usr_action, HOOK_UNDOCHECK, 0);
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, usr_action, HOOK_PRE);
+ run_hooks(drc_type, usr_action, HOOK_PRE, 0);
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, usr_action, HOOK_POST);
+ run_hooks(drc_type, usr_action, HOOK_POST, 0);
return rc;
}
--
2.40.0