Skip to content
suit Documentation
Login

Documentation

#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