Skip to content
suit Documentation
Login

Documentation

// suit-run: the program a timer starts every minute. It does only the
// no-change compare, which touches no database, so it starts as fast as a
// program with nothing in it. When something differs it replaces itself with
// `suit run`, which does the work. It is built from stamp.c and platform.c
// alone, with no reference to the store.

#include "platform.h"
#include "stamp.h"

#include <errno.h>
#include <string.h>
#include <unistd.h>

constexpr size_t PATH_CAP = 4096;

int main(void)
{
    int rc = stamp_check(false);
    if (rc != EXIT_CHANGED) return rc;

    char suit[PATH_CAP + 8];
    if (!platform_self_path(suit, PATH_CAP)) {
        say(STDERR_FILENO, "suit-run: cannot find the path of this program\n");
        return 1;
    }
    // suit sits beside suit-run.
    char *slash = strrchr(suit, '/');
    ensure(slash != nullptr);
    memcpy(slash + 1, "suit", sizeof "suit");
    char *argv[] = {(char *)"suit", (char *)"run", nullptr};
    (void)sys_execv(suit, argv);
    say(STDERR_FILENO, "suit-run: cannot run %s: %s\n", suit, strerror(errno));
    return 1;
}