From bfd93a1c163673bad2e510867f8f6b9ff069775c Mon Sep 17 00:00:00 2001 From: Chloe M Date: Sat, 15 Aug 2026 21:58:17 -0500 Subject: initial commit Signed-off-by: Chloe M --- core/hook.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 core/hook.c (limited to 'core/hook.c') diff --git a/core/hook.c b/core/hook.c new file mode 100644 index 0000000..b915901 --- /dev/null +++ b/core/hook.c @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2026, Chloe M., et al. + * Provided under the BSD-3 clause. + */ + +#include +#include +#include "bop/hook.h" + +/* Shell we use by default */ +#define DEFAULT_SHELL_PATH "/bin/sh" + +/* + * Execute the shell for a specific shell script + * + * @script_path: Path of shell script + */ +static void +exec_shell_for(const char *script_path) +{ + if (script_path == NULL) { + return; + } + + execl(DEFAULT_SHELL_PATH, DEFAULT_SHELL_PATH, script_path, NULL); +} + +/* + * Run a shell hook with POSIX sh + * + * XXX: Maybe support '#!/bin/xxx'? + */ +int +bop_shell_hook(const char *hook_path) +{ + pid_t child; + int status; + + if (hook_path == NULL) { + return -1; + } + + child = fork(); + if (child == 0) { + exec_shell_for(hook_path); + } else { + waitpid(child, &status, 0); + } + + return 0; +} -- cgit v1.2.3