Artifact 23f3a4ec43eaf2b5ba54e1b3ac669bbefbdc9e260946819d28a830b2b6eed7fe:
- File
src/hook.h
— part of check-in
[1165d70f02]
at
2026-11-15 16:50:31
on branch trunk
— Phase 8b: the hook dispatcher runs what is linked into an event's slot
A harness is told once to call suit-run hook EVENT. After that, which programs run for the event is decided by what suit has linked into slots/hook/EVENT: one program, or a folder of programs run one after another in byte order of name. An outfit names them with slot hook/EVENT = PATH or slot hook/EVENT/NAME = PATH. Asking for both forms of the same event is an error at plan time that names both outfits.
The dispatcher lives in suit-run, the small program, because some harnesses run a hook on every tool call. With no slot for the event it exits 0 at once, having read nothing. Otherwise standard input is read once into an unlinked temporary file, at most 16 MiB, and every program gets the same bytes from the start. A program that exits 2 stops the rest and the dispatcher exits 2. Otherwise all run and the result is the first non-zero status; a signal counts as 128 plus its number, and a program that cannot be run as 126. The dispatcher has no timeout of its own and prints nothing on success.
suit hook EVENT calls the same code. suit hooks lists what would run and changes nothing.
The speed budget has a second measurement: suit-run hook with no slot, 0.15 to 0.29 ms over an empty program against the 1 ms limit. The no-change run is unchanged and still passes. Stripped suit-run grew from 35064 to 35512 bytes.
1355 unit checks, 598 shell cases (was 479), 669 store cases, 756 placement cases (was 745) and 378 project cases, under clang, under gcc 16, with no user name set, and under a strict umask, in one run of make gate (35 minutes). 100% coverage in all 25 source files. No suite has fewer cases than at the last check-in. (user: dmestas, size: 1867) [annotate] [blame] [check-ins using]
#ifndef SUIT_HOOK_H #define SUIT_HOOK_H // The hook dispatcher (docs/hooks.md). A harness is told once to run // `suit-run hook EVENT`; which programs that runs is decided by what is linked // at $SUIT_HOME/slots/hook/EVENT: one program, or a folder of them. #include <stddef.h> constexpr size_t HOOK_EVENT_MAX = 64; constexpr int HOOK_PROGRAMS_MAX = 64; constexpr size_t HOOK_INPUT_MAX = 16 * 1024 * 1024; constexpr size_t HOOK_NAME_MAX = 255; constexpr size_t HOOK_PATH_MAX = 4096; constexpr int HOOK_EXIT_USAGE = 64; constexpr int HOOK_EXIT_INPUT = 65; constexpr int HOOK_EXIT_CANNOT = 126; constexpr int HOOK_EXIT_BLOCK = 2; typedef enum { HOOK_ABSENT, HOOK_SINGLE, HOOK_FOLDER, HOOK_FAILED } HookForm; typedef struct { int count; // The entries of a folder in byte order. A single program has one name, "". char names[HOOK_PROGRAMS_MAX][HOOK_NAME_MAX + 1]; } HookSet; // Whether EVENT is a name `suit-run hook` accepts. bool hook_event_ok(const char *event); // What is at the slot of EVENT; SLOT receives its path. HOOK_FAILED after a // message on standard error if the slot cannot be looked at. HookForm hook_probe(const char *event, char *slot, size_t cap); // The programs at SLOT: the one program, or the entries of the folder whose // names do not start with a dot, in byte order. 0, or an exit status after a // message (more than HOOK_PROGRAMS_MAX, or a folder that cannot be read). int hook_programs(const char *event, const char *slot, HookForm form, HookSet *set); // The entries of the folder DIR that do not start with a dot, in byte order, // at most CAP of them. 0; 1 if there are more; -1 if DIR cannot be read. int hook_collect(const char *dir, char (*names)[HOOK_NAME_MAX + 1], int cap, int *count); // Run the programs for EVENT. Returns the exit status of the dispatcher. int hook_dispatch(const char *event); #endif