diff --git a/include/util.h b/include/util.h index cda081cf7..93749b39a 100644 --- a/include/util.h +++ b/include/util.h @@ -323,5 +323,6 @@ static inline int read_img_str(int fd, char **pstr, int size) extern void *shmalloc(size_t bytes); extern void shfree_last(void *ptr); +extern int run_scripts(char *action); #endif /* UTIL_H_ */ diff --git a/util.c b/util.c index 0e047a19c..e45952702 100644 --- a/util.c +++ b/util.c @@ -387,3 +387,20 @@ void shfree_last(void *ptr) sh_bytes_left += sh_last_size; sh_last_size = 0; } + +int run_scripts(char *action) +{ + struct script *script; + int ret = 0; + + if (setenv("CRTOOLS_SCRIPT_ACTION", action, 1)) { + pr_perror("Can't set CRTOOL_SCRIPT_ACTION=%s\n", action); + return -1; + } + + list_for_each_entry(script, &opts.scripts, node) + ret |= system(script->path); + + unsetenv("CRTOOLS_SCRIPT_ACTION"); + return ret; +}