Artifact e26478679fd545fee450f985858bddbf77a36545ab25dd732f5ec795426cb78b:
- File
src/main.c
— 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: 5535) [annotate] [blame] [check-ins using]
#include "bench.h" #include "commands.h" #include "conf.h" #include "install.h" #include "platform.h" #include "remote.h" #include "stamp.h" #include "store.h" #include <errno.h> #include <string.h> #include <unistd.h> static Conf conf; static int usage(void) { say(STDERR_FILENO, "usage: suit check FILE\n" " suit store open|status|update|repair NAME\n" " suit plan | apply | status | off | run\n" " suit why NAME\n" " suit machine [NAME]\n" " suit roots [add|rm FOLDER]\n" " suit projects [scan]\n" " suit project set FOLDER KEY | unset FOLDER\n" " suit compare\n" " suit lint NAME\n" " suit commit NAME -m TEXT [--confirm-deletions]\n" " suit tend [NAME]\n" " suit clone NAME URL\n" " suit back NAME\n" " suit remote NAME [URL|--none]\n" " suit login NAME USER (the secret on standard input)\n" " suit logout NAME\n" " suit sync NAME\n" " suit stamp PATH...\n" " suit run\n" " suit install [--print] | uninstall\n" " suit status [--line]\n" " suit bench [-n N] [-e EMPTY_PROGRAM] [-t MICROSECONDS] [-m KIB]\n"); return 2; } static int cmd_check(const char *path) { ConfError err; if (!conf_load(&conf, path, &err)) { say(STDERR_FILENO, "%s:%d: %s\n", path, err.line, err.msg); return 2; } if (!conf_dump(&conf, STDOUT_FILENO)) { say(STDERR_FILENO, "suit: cannot write the dump: %s\n", strerror(errno)); return 1; } return 0; } static int cmd_store(int argc, char **argv) { if (argc != 4) return usage(); const char *verb = argv[2]; if (strcmp(verb, "open") == 0) return store_open(argv[3]); if (strcmp(verb, "status") == 0) return store_status(argv[3]); if (strcmp(verb, "update") == 0) return store_update(argv[3]); if (strcmp(verb, "repair") == 0) return store_repair(argv[3]); return usage(); } static int cmd_roots_args(int argc, char **argv) { if (argc == 2) return cmd_roots(nullptr, nullptr); bool verb = argc == 4 && (strcmp(argv[2], "add") == 0 || strcmp(argv[2], "rm") == 0); return verb ? cmd_roots(argv[2], argv[3]) : usage(); } static int cmd_project_args(int argc, char **argv) { if (argc == 5 && strcmp(argv[2], "set") == 0) return cmd_project(argv[3], argv[4]); if (argc == 4 && strcmp(argv[2], "unset") == 0) return cmd_project(argv[3], nullptr); return usage(); } static int cmd_commit(int argc, char **argv) { bool confirm = argc == 6 && strcmp(argv[5], "--confirm-deletions") == 0; if (argc < 5 || argc > 6 || strcmp(argv[3], "-m") != 0 || (argc == 6 && !confirm)) return usage(); return store_commit(argv[2], argv[4], confirm); } int main(int argc, char **argv) { if (argc < 2) return usage(); const char *cmd = argv[1]; if (strcmp(cmd, "run") == 0) return argc == 2 ? cmd_run() : usage(); if (strcmp(cmd, "compare") == 0) return argc == 2 ? stamp_check(true) : usage(); if (strcmp(cmd, "plan") == 0) return argc == 2 ? cmd_plan() : usage(); if (strcmp(cmd, "apply") == 0) return argc == 2 ? cmd_apply() : usage(); if (strcmp(cmd, "status") == 0) { if (argc == 2) return cmd_status(); return argc == 3 && strcmp(argv[2], "--line") == 0 ? cmd_status_line() : usage(); } if (strcmp(cmd, "install") == 0) { if (argc == 2) return cmd_install(false); return argc == 3 && strcmp(argv[2], "--print") == 0 ? cmd_install(true) : usage(); } if (strcmp(cmd, "uninstall") == 0) return argc == 2 ? cmd_uninstall() : usage(); if (strcmp(cmd, "why") == 0) return argc == 3 ? cmd_why(argv[2]) : usage(); if (strcmp(cmd, "off") == 0) return argc == 2 ? cmd_off() : usage(); if (strcmp(cmd, "machine") == 0) return argc <= 3 ? cmd_machine(argc == 3 ? argv[2] : nullptr) : usage(); if (strcmp(cmd, "roots") == 0) return cmd_roots_args(argc, argv); if (strcmp(cmd, "projects") == 0) { if (argc == 2) return cmd_projects(false); return argc == 3 && strcmp(argv[2], "scan") == 0 ? cmd_projects(true) : usage(); } if (strcmp(cmd, "project") == 0) return cmd_project_args(argc, argv); if (strcmp(cmd, "check") == 0) return argc == 3 ? cmd_check(argv[2]) : usage(); if (strcmp(cmd, "stamp") == 0) return argc >= 3 ? stamp_write(argc - 2, argv + 2) : usage(); if (strcmp(cmd, "store") == 0) return cmd_store(argc, argv); if (strcmp(cmd, "back") == 0) return argc == 3 ? store_back(argv[2]) : usage(); if (strcmp(cmd, "lint") == 0) return argc == 3 ? store_lint(argv[2]) : usage(); if (strcmp(cmd, "remote") == 0) return argc == 3 || argc == 4 ? cmd_remote(argv[2], argc == 4 ? argv[3] : nullptr) : usage(); if (strcmp(cmd, "login") == 0) return argc == 4 ? cmd_login(argv[2], argv[3]) : usage(); if (strcmp(cmd, "logout") == 0) return argc == 3 ? cmd_logout(argv[2]) : usage(); if (strcmp(cmd, "sync") == 0) return argc == 3 ? store_sync(argv[2]) : usage(); if (strcmp(cmd, "tend") == 0) return argc == 2 ? store_tend_all() : argc == 3 ? store_tend(argv[2]) : usage(); if (strcmp(cmd, "clone") == 0) return argc == 4 ? store_clone(argv[2], argv[3]) : usage(); if (strcmp(cmd, "commit") == 0) return cmd_commit(argc, argv); if (strcmp(cmd, "bench") == 0) return bench_main(argc - 2, argv + 2); return usage(); }