From 8ec1588722809a35a7d149bff10de56424e2658a Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Wed, 25 Nov 2020 17:58:50 -0800 Subject: src: initial commit of jio WIP source This is a very quick and dirty experimental hack written in some sort of bastard continuation-passing style in C w/io_uring using journal-file introspection and manipulation duty as an excuse for its existence. Consider this unfinished prototype quality code. --- src/machid.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/machid.c (limited to 'src/machid.c') diff --git a/src/machid.c b/src/machid.c new file mode 100644 index 0000000..721a4ee --- /dev/null +++ b/src/machid.c @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2020 - Vito Caputo - + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "machid.h" +#include "readfile.h" + +/* Implements iou-based machine-id retrieval. + * + * this is basically copy & paste from bootid.c, + * which suggests this should just be readfile.c + */ + + +#define MACHID_PATH "/etc/machine-id" + + +/* call user-supplied closure now that buf is populated */ +THUNK_DEFINE_STATIC(have_machid, iou_t *, iou, char *, buf, size_t *, size, char **, res_ptr, thunk_t *, closure) +{ + assert(iou); + assert(closure); + + /* FIXME: I'm just assuming it's a proper nl-terminated machid for now, null terminate it */ + buf[*size - 1] = '\0'; + + *res_ptr = strdup(buf); + if (!*res_ptr) + return -ENOMEM; + + return thunk_dispatch(closure); +} + + +/* get a machid via iou, scheduling closure once gotten */ +/* returns < 0 on error, 0 on successful queueing of operation */ +THUNK_DEFINE(machid_get, iou_t *, iou, char **, res_ptr, thunk_t *, closure) +{ + thunk_t *machid_thunk; + struct { + char buf[4096]; + size_t len; + } *buf; + + machid_thunk = THUNK_ALLOC(have_machid, (void **)&buf, sizeof(*buf)); + buf->len = sizeof(buf->buf); + THUNK_INIT(have_machid(machid_thunk, iou, buf->buf, &buf->len, res_ptr, closure)); + + return readfile(iou, MACHID_PATH, buf->buf, &buf->len, machid_thunk); +} -- cgit v1.2.3