2021-09-26 22:03:26 +03:00
|
|
|
#ifndef HOOK_H
|
|
|
|
#define HOOK_H
|
2021-12-22 06:59:27 +03:00
|
|
|
#include "strvec.h"
|
|
|
|
|
|
|
|
struct run_hooks_opt
|
|
|
|
{
|
|
|
|
/* Environment vars to be set for each hook */
|
|
|
|
struct strvec env;
|
|
|
|
|
|
|
|
/* Args to be passed to each hook */
|
|
|
|
struct strvec args;
|
|
|
|
|
|
|
|
/* Emit an error if the hook is missing */
|
|
|
|
unsigned int error_if_missing:1;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define RUN_HOOKS_OPT_INIT { \
|
|
|
|
.env = STRVEC_INIT, \
|
|
|
|
.args = STRVEC_INIT, \
|
|
|
|
}
|
|
|
|
|
|
|
|
struct hook_cb_data {
|
|
|
|
/* rc reflects the cumulative failure state */
|
|
|
|
int rc;
|
|
|
|
const char *hook_name;
|
|
|
|
const char *hook_path;
|
|
|
|
struct run_hooks_opt *options;
|
|
|
|
};
|
2021-09-26 22:03:26 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns the path to the hook file, or NULL if the hook is missing
|
|
|
|
* or disabled. Note that this points to static storage that will be
|
|
|
|
* overwritten by further calls to find_hook and run_hook_*.
|
|
|
|
*/
|
|
|
|
const char *find_hook(const char *name);
|
|
|
|
|
2021-09-26 22:03:27 +03:00
|
|
|
/**
|
|
|
|
* A boolean version of find_hook()
|
|
|
|
*/
|
|
|
|
int hook_exists(const char *hookname);
|
|
|
|
|
2021-12-22 06:59:27 +03:00
|
|
|
/**
|
|
|
|
* Takes a `hook_name`, resolves it to a path with find_hook(), and
|
|
|
|
* runs the hook for you with the options specified in "struct
|
|
|
|
* run_hooks opt". Will free memory associated with the "struct run_hooks_opt".
|
|
|
|
*
|
|
|
|
* Returns the status code of the run hook, or a negative value on
|
|
|
|
* error().
|
|
|
|
*/
|
|
|
|
int run_hooks_opt(const char *hook_name, struct run_hooks_opt *options);
|
2021-12-22 06:59:28 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A wrapper for run_hooks_opt() which provides a dummy "struct
|
|
|
|
* run_hooks_opt" initialized with "RUN_HOOKS_OPT_INIT".
|
|
|
|
*/
|
|
|
|
int run_hooks(const char *hook_name);
|
2021-09-26 22:03:26 +03:00
|
|
|
#endif
|