Beispiel #1
0
static int
run_do(void)
{
    static const char *etc_path = "/etc/machine-id",
    *run_path = "/run/machine-id";
    char id[33];
    int r;

    r = sol_util_read_file(etc_path, "%32s", id);
    if (r < 0) {
        /* We can only tolerate the file not existing or being
         * malformed on /etc/, otherwise it's got more serious
         * problems and it's better to fail */
        if (r != -ENOENT && r != EOF)
            goto err;
    } else {
        r = validate_machine_id(id);
        /* return if OK here */
        SOL_INT_CHECK(r, == 0, 0);
    }

    r = sol_util_uuid_gen(false, false, id);
    SOL_INT_CHECK_GOTO(r, < 0, err);

    if (write_machine_id(etc_path, id) >= 0)
        goto end;

    /* fallback to /run/ */
    r = write_machine_id(run_path, id);
    SOL_INT_CHECK_GOTO(r, < 0, err);

end:
    sol_platform_linux_micro_inform_service_state
        (name, SOL_PLATFORM_SERVICE_STATE_ACTIVE);
    done = true;
    return 0;

err:
    sol_platform_linux_micro_inform_service_state
        (name, SOL_PLATFORM_SERVICE_STATE_FAILED);

    return r;
}
Beispiel #2
0
static int
parse_kcmdline_pin(void)
{
    char buf[4096] = {};
    const char *p, *start, *end;
    int err, pin = -1;

    err = sol_util_read_file("/proc/cmdline", "%4095[^\n]", buf);
    if (err < 1)
        return err;

    start = buf;
    end = start + strlen(buf);
    for (p = start; pin < 0 && p < end; p++) {
        if (isblank(*p) && start < p) {
            pin = parse_kcmdline_pin_entry(start, p - start);
            start = p + 1;
        }
    }
    if (pin < 0 && start < end)
        pin = parse_kcmdline_pin_entry(start, end - start);
    return pin;
}
Beispiel #3
0
static int
_kcmdline_load(void)
{
    char buf[4096] = {};
    const char *p, *end, *start;
    int err;

    err = sol_util_read_file("/proc/cmdline", "%4095[^\n]", buf);
    if (err < 1)
        return err;

    start = buf;
    end = start + strlen(buf);
    for (p = start; p < end; p++) {
        if (isblank(*p) && start < p) {
            _kcmdline_parse_entry(start, p - start);
            start = p + 1;
        }
    }
    if (start < end)
        _kcmdline_parse_entry(start, end - start);

    return 0;
}