MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / hl_run_hook

Function hl_run_hook

tests/test_cli.c:16042–16077  ·  view source on GitHub ↗

Exit code of `hook-augment` run in a child with HOME = home and * CBM_CACHE_DIR = cache_dir (unset when NULL), or -1 when it did not exit. */

Source from the content-addressed store, hash-verified

16040/* Exit code of `hook-augment` run in a child with HOME = home and
16041 * CBM_CACHE_DIR = cache_dir (unset when NULL), or -1 when it did not exit. */
16042static int hl_run_hook(const char *home, const char *cache_dir) {
16043 static const char payload[] = "{\"hook_event_name\":\"PreToolUse\",\"tool_name\":\"Bash\","
16044 "\"tool_input\":{\"command\":\"ls\"}}";
16045 int fds[2];
16046 if (pipe(fds) != 0) {
16047 return -1;
16048 }
16049 /* Queued before the fork, so no write can meet a reader that has gone. */
16050 ssize_t queued = write(fds[1], payload, sizeof(payload) - 1);
16051 close(fds[1]);
16052 if (queued != (ssize_t)(sizeof(payload) - 1)) {
16053 close(fds[0]);
16054 return -1;
16055 }
16056 fflush(NULL);
16057 pid_t pid = fork();
16058 if (pid == 0) {
16059 dup2(fds[0], STDIN_FILENO);
16060 close(fds[0]);
16061 cbm_setenv("HOME", home, 1);
16062 cbm_unsetenv("USERPROFILE");
16063 cbm_unsetenv("CBM_HOOK_TIMEOUT_LOG");
16064 if (cache_dir) {
16065 cbm_setenv("CBM_CACHE_DIR", cache_dir, 1);
16066 } else {
16067 cbm_unsetenv("CBM_CACHE_DIR");
16068 }
16069 _exit(cbm_cmd_hook_augment(0, NULL));
16070 }
16071 close(fds[0]);
16072 int status = 0;
16073 if (pid < 0 || waitpid(pid, &status, 0) != pid || !WIFEXITED(status)) {
16074 return -1;
16075 }
16076 return WEXITSTATUS(status);
16077}
16078
16079/* A fresh synthetic root with its links resolved. The kernel bounds the
16080 * EXPANDED path, and macOS /tmp is a link to /private/tmp: under the link a

Callers 1

test_cli.cFile · 0.85

Calls 6

cbm_setenvFunction · 0.85
cbm_unsetenvFunction · 0.85
_exitFunction · 0.85
cbm_cmd_hook_augmentFunction · 0.85
writeFunction · 0.50
closeFunction · 0.50

Tested by

no test coverage detected