Skip to content
suit Artifact [0d09665ae6]
Login

Artifact [0d09665ae6]

Artifact 0d09665ae668eb07a892d2de9a64f0d5d50c4c8053adeb67405430458a10e05e:


#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