omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / src / omega_clean_clone.h
| 1 | #ifndef OMEGA_CLEAN_CLONE_H |
| 2 | #define OMEGA_CLEAN_CLONE_H |
| 3 | |
| 4 | #include <stdbool.h> |
| 5 | #include <stddef.h> |
| 6 | |
| 7 | /* Process and file helpers for the M18 and M19 clean-clone gates (omega#526, #565). |
| 8 | * |
| 9 | * No shell anywhere: every child program is started with fork + execvp and an |
| 10 | * argument vector, and trees are removed with nftw + unlink/rmdir. A path is |
| 11 | * never pasted into a command string, so a quote or shell metacharacter in |
| 12 | * TMPDIR, PHYSICS_DIR or a clone path cannot change what runs. |
| 13 | * |
| 14 | * Fail closed: a path outside the plain charset (letters, digits, / . _ + -) |
| 15 | * is refused before anything runs, because it is also handed to make as |
| 16 | * PHYSICS_DIR=<path> and make expands '$' in variable values. */ |
| 17 | |
| 18 | /* True when every byte of s is in [A-Za-z0-9/._+-] and s is non-empty. */ |
| 19 | bool omega_cc_path_is_plain(const char *s); |
| 20 | |
| 21 | /* Run prog (looked up on PATH; callers pass a string literal) with argv in |
| 22 | * directory dir (NULL: the current directory). stdout and stderr go to out_rel, |
| 23 | * a path opened by the child AFTER it changes to dir, so callers pass a fixed |
| 24 | * relative name such as "../qualification.log"; NULL means /dev/null. |
| 25 | * OUT_DIR is removed from the child environment; when in_clean_clone is true |
| 26 | * the child also gets OMEGA_IN_CLEAN_CLONE=1. |
| 27 | * Returns the child's exit code (126: output file could not be opened, 127: |
| 28 | * program could not be started), 128 + signal if it was killed, or -1 if the |
| 29 | * child could not be created. */ |
| 30 | int omega_cc_run(const char *dir, const char *prog, char *const argv[], const char *out_rel, bool in_clean_clone); |
| 31 | |
| 32 | /* Run prog with argv in dir and capture the first line of its stdout (newline |
| 33 | * stripped) into out. stderr goes to /dev/null. Returns true only when the |
| 34 | * program exits 0 and printed a line that fit. */ |
| 35 | bool omega_cc_capture_line(const char *dir, const char *prog, char *const argv[], char *out, size_t out_size); |
| 36 | |
| 37 | /* Remove path and everything under it without following symlinks. |
| 38 | * Refuses an empty path, "/", a relative path, or a path outside the plain |
| 39 | * charset. Returns 0 when the tree is gone (or was never there), -1 otherwise. */ |
| 40 | int omega_cc_remove_tree(const char *path); |
| 41 | |
| 42 | #endif |