diff --git a/package/Config.in b/package/Config.in index 9271f68d..00f53e0d 100644 --- a/package/Config.in +++ b/package/Config.in @@ -10,7 +10,6 @@ source "$BR2_EXTERNAL_INFIX_PATH/package/confd/Config.in" source "$BR2_EXTERNAL_INFIX_PATH/package/confd-test-mode/Config.in" source "$BR2_EXTERNAL_INFIX_PATH/package/curios-httpd/Config.in" source "$BR2_EXTERNAL_INFIX_PATH/package/curios-nftables/Config.in" -source "$BR2_EXTERNAL_INFIX_PATH/package/execd/Config.in" source "$BR2_EXTERNAL_INFIX_PATH/package/gencert/Config.in" source "$BR2_EXTERNAL_INFIX_PATH/package/statd/Config.in" source "$BR2_EXTERNAL_INFIX_PATH/package/factory/Config.in" diff --git a/package/execd/Config.in b/package/execd/Config.in deleted file mode 100644 index 5883f17a..00000000 --- a/package/execd/Config.in +++ /dev/null @@ -1,8 +0,0 @@ -config BR2_PACKAGE_EXECD - bool "execd" - select BR2_PACKAGE_LIBUEV - select BR2_PACKAGE_LIBITE - help - Generic job queue executor with retry on route changes. - - https://github.com/kernelkit/infix diff --git a/package/execd/execd.conf b/package/execd/execd.conf deleted file mode 100644 index 0a6e2e6c..00000000 --- a/package/execd/execd.conf +++ /dev/null @@ -1,4 +0,0 @@ -task log:prio:local1.notice,tag:container-flush \ - [S] container flush -- Cleaning up lingering containers -service log:prio:local1.err,tag:container \ - [2345] execd /run/containers/queue -- Container job runner diff --git a/package/execd/execd.hash b/package/execd/execd.hash deleted file mode 100644 index beca753f..00000000 --- a/package/execd/execd.hash +++ /dev/null @@ -1 +0,0 @@ -sha256 fff5e150e496c6bb6035ae388ee13cf2d0df842335e5145a4b902ef6b7892088 LICENSE diff --git a/package/execd/execd.mk b/package/execd/execd.mk deleted file mode 100644 index 9128b44e..00000000 --- a/package/execd/execd.mk +++ /dev/null @@ -1,29 +0,0 @@ -################################################################################ -# -# execd -# -################################################################################ - -EXECD_VERSION = 1.0 -EXECD_SITE_METHOD = local -EXECD_SITE = $(BR2_EXTERNAL_INFIX_PATH)/src/execd -EXECD_LICENSE = ISC -EXECD_LICENSE_FILES = LICENSE -EXECD_REDISTRIBUTE = NO -EXECD_DEPENDENCIES = libuev libite -EXECD_AUTORECONF = YES - -define EXECD_CONF_ENV -CFLAGS="$(INFIX_CFLAGS)" -endef - -EXECD_CONF_OPTS = --prefix= --disable-silent-rules - -define EXECD_INSTALL_EXTRA - cp $(EXECD_PKGDIR)/execd.conf $(FINIT_D)/available/ - ln -sf ../available/execd.conf $(FINIT_D)/enabled/execd.conf - cp $(EXECD_PKGDIR)/tmpfiles.conf $(TARGET_DIR)/lib/tmpfiles.d/execd.conf -endef -EXECD_TARGET_FINALIZE_HOOKS += EXECD_INSTALL_EXTRA - -$(eval $(autotools-package)) diff --git a/package/execd/tmpfiles.conf b/package/execd/tmpfiles.conf deleted file mode 100644 index a49d280e..00000000 --- a/package/execd/tmpfiles.conf +++ /dev/null @@ -1 +0,0 @@ -d /run/containers/queue 0700 - - diff --git a/src/Makefile b/src/Makefile index cd00fc32..0ea92c5e 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,5 +1,5 @@ # Host build of critical components, for Coverity Scan mostly -APPS = bin confd execd factory keyack statd +APPS = bin confd factory keyack statd .PHONY: all all: diff --git a/src/bin/erase.c b/src/bin/erase.c index 1c5e3601..716c310b 100644 --- a/src/bin/erase.c +++ b/src/bin/erase.c @@ -26,10 +26,6 @@ static int do_erase(const char *path) } cfg_adjust(path, NULL, fn, len); - if (access(fn, F_OK)) { - fprintf(stderr, "No such file: %s\n", fn); - return -1; - } } else fn = (char *)path; diff --git a/src/bin/util.c b/src/bin/util.c index 3b212655..0e739b1e 100644 --- a/src/bin/util.c +++ b/src/bin/util.c @@ -14,7 +14,7 @@ static char rawgetch(void) { struct termios saved, c; - char key; + int key; if (tcgetattr(fileno(stdin), &saved) < 0) return -1; @@ -33,7 +33,10 @@ static char rawgetch(void) key = getchar(); tcsetattr(fileno(stdin), TCSANOW, &saved); - return key; + if (key == EOF) + return -1; + + return (char)key; } int yorn(const char *fmt, ...) diff --git a/src/execd/.gitignore b/src/execd/.gitignore deleted file mode 100644 index a946ae2f..00000000 --- a/src/execd/.gitignore +++ /dev/null @@ -1,28 +0,0 @@ -*~ -*.o -execd - -/aclocal.m4 -/autom4te.cache/ -/aux -/clixon.xml -/compile -/config.h -/config.h.in -/config.guess -/config.log -/config.status -/config.sub -/configure -/depcomp -/install-sh -/libtool -/ltmain.sh -/m4 -/missing - -GPATH -GRTAGS -GTAGS -Makefile -Makefile.in diff --git a/src/execd/LICENSE b/src/execd/LICENSE deleted file mode 100644 index 65e3295d..00000000 --- a/src/execd/LICENSE +++ /dev/null @@ -1,14 +0,0 @@ -Copyright (c) 2024 The KernelKit Authors - -Permission to use, copy, modify, and/or distribute this software for any purpose -with or without fee is hereby granted, provided that the above copyright notice -and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH -REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND -FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS -OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER -TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF -THIS SOFTWARE. - diff --git a/src/execd/Makefile.am b/src/execd/Makefile.am deleted file mode 100644 index ae10145c..00000000 --- a/src/execd/Makefile.am +++ /dev/null @@ -1,9 +0,0 @@ -DISTCLEANFILES = *~ *.d -ACLOCAL_AMFLAGS = -I m4 - -sbin_PROGRAMS = execd -execd_SOURCES = execd.c execd.h -execd_CPPFLAGS = -D_GNU_SOURCE -execd_CFLAGS = -W -Wall -Wextra -Wno-unused -execd_CFLAGS = $(libuev_CFLAGS) $(libite_CFLAGS) -execd_LDADD = $(libuev_LIBS) $(libite_LIBS) diff --git a/src/execd/README.md b/src/execd/README.md deleted file mode 100644 index 8354d54b..00000000 --- a/src/execd/README.md +++ /dev/null @@ -1,9 +0,0 @@ -Execute jobs on route changes -============================= - -This is a generic job queue executor for work that needs network access. - -For example creating a Docker container by downloading an image from the -network -- if the download fails `execd` retries the job whenever there -is a route change. - diff --git a/src/execd/autogen.sh b/src/execd/autogen.sh deleted file mode 100755 index 69ad0e18..00000000 --- a/src/execd/autogen.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -autoreconf -W portability -vifm diff --git a/src/execd/check.mk b/src/execd/check.mk deleted file mode 100644 index 18272c55..00000000 --- a/src/execd/check.mk +++ /dev/null @@ -1,5 +0,0 @@ -all: - ./autogen.sh - ./configure - make all - make distclean diff --git a/src/execd/configure.ac b/src/execd/configure.ac deleted file mode 100644 index 0d7c8875..00000000 --- a/src/execd/configure.ac +++ /dev/null @@ -1,65 +0,0 @@ -AC_PREREQ(2.61) -AC_INIT([execd], [1.0.0], [https://github.com/kernelkit/infix/issues]) -AM_INIT_AUTOMAKE(1.11 foreign subdir-objects) -AM_SILENT_RULES(yes) - -AC_CONFIG_FILES([ - Makefile -]) - -AC_PROG_CC -AC_PROG_INSTALL - -# Check for pkg-config first, warn if it's not installed -PKG_PROG_PKG_CONFIG - -PKG_CHECK_MODULES([libuev], [libuev >= 2.4.0]) -PKG_CHECK_MODULES([libite], [libite >= 2.5.0]) - -test "x$prefix" = xNONE && prefix=$ac_default_prefix -test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' - -DATAROOTDIR=`eval echo $datarootdir` -DATAROOTDIR=`eval echo $DATAROOTDIR` -AC_SUBST(DATAROOTDIR) - -LIBDIR=`eval echo $libdir` -LIBDIR=`eval echo $LIBDIR` -AC_SUBST(LIBDIR) - -LOCALSTATEDIR=`eval echo $localstatedir` -LOCALSTATEDIR=`eval echo $LOCALSTATEDIR` -AC_SUBST(LOCALSTATEDIR) - -RUNSTATEDIR=`eval echo $runstatedir` -RUNSTATEDIR=`eval echo $RUNSTATEDIR` -AC_SUBST(RUNSTATEDIR) - -SYSCONFDIR=`eval echo $sysconfdir` -SYSCONFDIR=`eval echo $SYSCONFDIR` -AC_SUBST(SYSCONFDIR) - -AC_OUTPUT - -cat <d_type == DT_DIR) - continue; - - if (should_run(d->d_name, type)) - num += !!run_job(path, d->d_name); - - free(d); - } - - free(namelist); - - return num; -} - -/* - * Call stop/cleanup jobs first, may use same container name or - * resources as replacement container start scripts use. - */ -static void run_queue(const char *path) -{ - int num; - - num = run_dir(path, 'K'); - num += run_dir(path, 'S'); - - if (num) - uev_timer_set(&retry_watcher, retry, 0); -} - -static void signal_cb(uev_t *w, void *arg, int signo) -{ - dbg("signal %d, calling job queue", signo); - run_queue(arg); -} - -static void timer_cb(uev_t *w, void *arg, int _) -{ - dbg("timer, retry job queue"); - run_queue(arg); -} - -static void toggle_debug(uev_t *w, void *arg, int _) -{ - int current = setlogmask(0); - - if (current == logmask) - setlogmask(LOG_UPTO(LOG_DEBUG)); - else - setlogmask(logmask); -} - -static void inotify_cb(uev_t *w, void *arg, int _) -{ - ssize_t bytes; - int num = 0; - - bytes = read(w->fd, buffer, sizeof(buffer)); - if (bytes == -1) { - err("read"); - return; - } - - for (char *p = buffer; p < buffer + bytes;) { - struct inotify_event *event = (struct inotify_event *)p; - char *name = event->name; - - if (event->mask & (IN_CLOSE_WRITE | IN_ATTRIB | IN_MOVED_TO)) { - dbg("Got inotify event %s 0x%04x", name, event->mask); - if (!should_run(name, '*')) - continue; - - num += !!run_job(arg, name); - } - - p += sizeof(struct inotify_event) + event->len; - } - - if (num) - uev_timer_set(&retry_watcher, retry, 0); -} - -static void netlink_cb(uev_t *w, void *arg, int _) -{ - struct iovec iov = { buffer, sizeof(buffer) }; - struct sockaddr_nl addr; - struct msghdr msg = { - &addr, sizeof(addr), - &iov, 1, - NULL, 0, - 0 - }; - ssize_t bytes; - int sd = w->fd; - - dbg("Got netlink event"); - - /* Empty netlink queue, we just want the event */ - while ((bytes = recvmsg(sd, &msg, 0)) > 0) - dbg("Read %ld netlink bytes", bytes); - - dbg("Calling run queue"); - run_queue(arg); -} - -static int usage(const char *arg0, int rc) -{ - printf("Usage:\n" - " %s [-dh] [-l LVL] [-t SEC] QUEUE\n" - "Options:\n" - " -d Log to stderr as well\n" - " -h This help text\n" - " -l LVL Set log level: none, err, warn, notice*, info, debug\n" - " -t SEC Retry timer in seconds [10, 604800], default: %d\n" - "\n" - "Run jobs from QUEUE. Triggers on inotify of new jobs, route changes, and\n" - "retries failing jobs every minute until the queue has been emtied.\n" - "Use SIGHUP to trigger a manual retry.\n" - "Use SIGUSR1 to toggle debug messages at runtime.\n", arg0, RETRY_TIMER); - - return rc; -} - -int main(int argc, char *argv[]) -{ - struct sockaddr_nl sa = { 0 }; - uev_t inotify_watcher; - uev_t netlink_watcher; - uev_t sigusr1_watcher; - uev_t sighup_watcher; - int logopt = LOG_PID; - int wd, sd, fd, c; - char *queue; - uev_ctx_t ctx; - int rc = 0; - - while ((c = getopt(argc, argv, "dhl:t:")) != EOF) { - switch (c) { - case 'd': - logopt |= LOG_PERROR; - break; - case 'h': - return usage(argv[0], 0); - case 'l': - logmask = logmask_from_str(optarg); - if (logmask < 0) { - fprintf(stderr, "Invalid loglevel '%s'\n\n", optarg); - return usage(argv[0], 1); - } - break; - case 't': - retry = atoi(optarg); - if (retry < 10 || retry > 604800) { - fprintf(stderr, "Invalid value %d, accepted [10, 604800]", retry); - return 1; - } - break; - default: - return usage(argv[0], 1); - } - } - - if (optind >= argc) - return usage(argv[0], 1); - - queue = argv[optind]; - retry *= 1000; - - if (access(queue, X_OK)) { - fprintf(stderr, "Cannot find job directory %s, errno %d: %s\n", - queue, errno, strerror(errno)); - return 1; - } - - /* - * We close stdin, while leaving stdout et stderr open so a user - * can redirect output from us to a logger process, or - * similar. - */ - close(STDIN_FILENO); - - /* The logs of this program go to syslog w/ regular daemon facility */ - openlog(NULL, logopt, LOG_DAEMON); - setlogmask(logmask); - - fd = inotify_init1(IN_NONBLOCK); - if (fd == -1) { - err("inotify_init"); - return 1; - } - - wd = inotify_add_watch(fd, queue, IN_CLOSE_WRITE | IN_ATTRIB | IN_MOVED_TO); - if (wd == -1) { - err("inotify_add_watch"); - close(fd); - return 1; - } - - /* Set up netlink socket for route monitoring */ - sd = socket(AF_NETLINK, SOCK_RAW | SOCK_NONBLOCK, NETLINK_ROUTE); - if (sd == -1) { - err("socket"); - close(fd); - return 1; - } - - sa.nl_family = AF_NETLINK; - sa.nl_groups = RTMGRP_IPV4_ROUTE | RTMGRP_IPV6_ROUTE; - if (bind(sd, (struct sockaddr *)&sa, sizeof(sa)) == -1) { - err("bind"); - rc = 1; - goto done; - } - - uev_init(&ctx); - if (uev_signal_init(&ctx, &sighup_watcher, signal_cb, queue, SIGHUP) == -1) { - err("uev_signal_init (sighup)"); - rc = 1; - goto done; - } - - /* Initial delay of 1 sec, lots of other events happening at boot. */ - if (uev_timer_init(&ctx, &retry_watcher, timer_cb, queue, 1000, 0) == -1) { - err("uev_timer_init (1000, %d)", retry); - rc = 1; - goto done; - } - - if (uev_signal_init(&ctx, &sigusr1_watcher, toggle_debug, NULL, SIGUSR1) == -1) { - err("uev_signal_init (sigusr1)"); - rc = 1; - goto done; - } - - if (uev_io_init(&ctx, &inotify_watcher, inotify_cb, queue, fd, UEV_READ) == -1) { - err("uev_io_init (inotify)"); - rc = 1; - goto done; - } - - if (uev_io_init(&ctx, &netlink_watcher, netlink_cb, queue, sd, UEV_READ) == -1) { - err("uev_io_init (netlink)"); - rc = 1; - goto done; - } - - if (uev_run(&ctx, 0) == -1) { - err("uev_run"); - rc = 1; - } - -done: - close(fd); - close(sd); - - return rc; -} diff --git a/src/execd/execd.h b/src/execd/execd.h deleted file mode 100644 index 06ba51bb..00000000 --- a/src/execd/execd.h +++ /dev/null @@ -1,76 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#define SYSLOG_NAMES -#include -#include - -#include -#include - -#include -#include - -#include -#include - -#define err(fmt, args...) syslog(LOG_ERR, fmt ": %s", ##args, strerror(errno)) -#define errx(fmt, args...) syslog(LOG_ERR, fmt, ##args) -#define warn(fmt, args...) syslog(LOG_WARNING, fmt, ": %s", ##args, strerror(errno)) -#define warnx(fmt, args...) syslog(LOG_WARNING, fmt, ##args) -#define log(fmt, args...) syslog(LOG_NOTICE, fmt, ##args) -#define dbg(fmt, args...) syslog(LOG_DEBUG, fmt, ##args) - -/* - * Allow SNN and KNN style jobs, for inotyify_cb() we also allow - * a type '*' just to figure out if a job should be archived in - * the done directory. - */ -static inline int should_run(const char *name, int type) -{ - if (!name || strlen(name) < 3) - return 0; - - if (isdigit(name[1]) && isdigit(name[2])) { - if (type == '*') { - switch (name[0]) { - case 'K': - case 'S': - return 1; - default: - goto done; - } - } - - switch (type) { - case 'K': - case 'S': - break; - default: - return 0; - } - - dbg("name:%s type:'%c' => run:%d", name, type, type == name[0]); - return type == name[0]; - } -done: - errx("unsupported script %s, must follow pattern SNN/KNN", name); - return 0; -} - -static inline int logmask_from_str(const char *str) -{ - const CODE *code; - - for (code = prioritynames; code->c_name; code++) - if (!strcmp(str, code->c_name)) - return LOG_UPTO(code->c_val); - - return -1; -} -