Artifact 0d09665ae668eb07a892d2de9a64f0d5d50c4c8053adeb67405430458a10e05e:
- File
src/install.h
— part of check-in
[7ecc8d52ea]
at
2026-11-14 06:52:19
on branch trunk
— Phase 7c-2: suit install sets up the two timers, and status has a one-line form
suit install writes two timers and loads them: one starts suit-run every minute, the other starts suit tend every hour. On macOS they are launchd user agents in ~/Library/LaunchAgents; on Linux, systemd user units. Each file is written with exactly mode 0644 whatever the umask. Running install again with nothing changed writes nothing and loads nothing. suit install --print shows the files and changes nothing. suit uninstall unloads the timers and removes exactly its own files. Neither touches a file that is not one of suit's own names.
Two timers stand in place of the planned single timer with a detached hourly child: the minute run stays inside its speed budget, and each job can be seen and stopped by itself.
The loader (launchctl or systemctl) is started by absolute path, never through a shell. Its path and the platform can be overridden only in the test builds; a test checks the release binary holds neither name.
suit status --line prints one short line for a status bar: suit ok, how many things need you, or not installed. Plain suit status says whether the timers are installed.
Known gaps. If the loader fails, the files stay in place and a second install says already installed without trying to load again; that needs a retry and a line in the attention file. The Linux units are checked as text and as loader arguments on macOS; systemd itself has not run them.
Found by the local gate before this check-in: an analyzer report, tests that needed a user name, and timer files written with the wrong mode under a strict umask.
1269 unit checks, 428 shell cases, 669 store cases, 612 placement cases and 378 project cases, under clang, under gcc 16, with no user name set, and under a strict umask. 100% coverage in all 23 source files. No suite has fewer cases than at the last check-in. (user: dmestas, size: 2171) [annotate] [blame] [check-ins using]
#ifndef SUIT_INSTALL_H #define SUIT_INSTALL_H // The two timers that make suit run by itself (docs/install.md): "run" every // 60 seconds starts suit-run, "tend" every 3600 seconds starts `suit tend`. // Which files hold them depends on the machine: two launchd property lists on // macOS, two systemd service and timer pairs on Linux. The text of each file // comes from the pure functions below, which build on both. #include <stddef.h> #include <sys/types.h> typedef enum { TIMER_RUN, TIMER_TEND } Timer; constexpr unsigned INSTALL_RUN_SECONDS = 60; constexpr unsigned INSTALL_TEND_SECONDS = 3600; // The exit code of `suit install` when the loader refuses the files. constexpr int EXIT_LOADER_FAILED = 3; // The longest path the text builders take, and a buffer that holds any text. constexpr size_t INSTALL_PATH_MAX = 1024; constexpr size_t INSTALL_TEXT_MAX = 24576; typedef struct { const char *suit; // absolute path of suit const char *run; // absolute path of suit-run const char *home; // the folder suit keeps its files in, absolute bool home_set; // SUIT_HOME names it, so the timer must be told } InstallSpec; // Whether every path is absolute, short enough and free of control characters // (a newline would end a line of the file early). bool install_spec_ok(const InstallSpec *s); // The launchd label of timer T. const char *install_label(Timer t); // The text of the launchd property list, or the systemd service or timer // file, of T. Each returns its length, or -1 for a refused SPEC. OUT holds at // least INSTALL_TEXT_MAX bytes. ssize_t install_plist(char *out, size_t cap, const InstallSpec *s, Timer t); ssize_t install_service(char *out, size_t cap, const InstallSpec *s, Timer t); ssize_t install_timer(char *out, size_t cap, const InstallSpec *s, Timer t); // Each returns an exit code and reports on stdout and stderr. int cmd_install(bool print); int cmd_uninstall(void); // One short line for a status bar. int cmd_status_line(void); // Print "timers: installed", "timers: not installed" or "timers: differ ...". // Returns 0, or 1 after saying why it could not tell. int install_print_state(void); #endif