Compare commits

..
Author SHA1 Message Date
Jacques de Laval 50c99762f1 Add run target for running Finit as a stand alone unprivileged process
It could be very useful, during development, to be able to run Finit on a
host system without having to provision a full VM. We have all the building
blocks for easily containerizing Finit - in the test framework - so adding
a "run" target that does the orchestration makes sense.

Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-03-05 01:39:42 +01:00
Jacques de Laval 067043b298 test: Use STDOUT of parent process instead of a pipe as tty for finit
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-03-05 01:24:31 +01:00
Joachim Wiberg 439699ef52 configure: improve --with-sysconfig help text slightly
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-03 07:06:17 +01:00
Joachim Wiberg f20936dae0 configure: slight reorder; first enable -> then disable options
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-03 07:05:55 +01:00
Joachim Wiberg d5bea7eeeb Re-concatenate string arguments to commands, ugly patch
This is quite possibly the ugliest pieces of code in this project.

It is a quick fix to the problem with strtok() to split up the cmd into
cmd + args[].  Without it wordexp() will later get very cranky about
trying to expand `"Partial` strings from commands like this:

    /sbin/udhcpc-wrapper.sh -f -S -V "myOS v9.99" -t 8 -T 5 -A 10 -R -p \
        /var/run/udhcpc-vlan1.pid -i vlan1 -x hostname:myos-12-34-50 -o \
	-O 1 -O 3 -O 6 -O 7 -O 12 -O 15 -O 42 -O 121 -a

Yes really.

It's an obviously far from perfect solution.  One might even start to
question why we have an args[64[64] per svc_t and not just a cmd + arg?

Well, there's a lot of improvement potential here, let's talk!

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-02 22:33:41 +01:00
Joachim Wiberg 5da0a460fe initctl: fix runlevel and start/stop/restart segfault regression
Introduced in e2f6ac0.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-02 20:31:34 +01:00
Joachim Wiberg 63033d7dcf Drop developer debug message
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-02 20:23:43 +01:00
Joachim Wiberg 2857dafaf4 plugins: pidfile: Fall back to /run if _PATH_VARRUN doesn't exist
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-02 20:22:56 +01:00
Joachim Wiberg 8355c37285 initctl: fix edit command fallback handling
If mg doesn't exist, command doesn't evaluate the second argument (vi),
so we need to use `... || command -v vi` instead.  Found during demo,
because why not.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-01 17:36:06 +01:00
Joachim Wiberg dc49b523d1 initctl: fix cond segfault, regression introduced in e2f6ac0
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-01 11:13:02 +01:00
Magnus Malm bf863673c8 Update list of contributors
Signed-off-by: Magnus Malm <magnusmalm@gmail.com>
2021-03-01 09:26:31 +01:00
13 changed files with 89 additions and 26 deletions
+1
View File
@@ -6,6 +6,7 @@ Major Contributors:
* Mattias Walström <mattias.walstrom@westermo.se>
* Jonas Johansson <jonas.johansson@westermo.se>
* Jacques de Laval <jacques@de-laval.se>
* Magnus Malm <magnusmalm@gmail.com>
Original Author(s):
* Claudio Matsuoka <cmatsuoka@gmail.com>
+16
View File
@@ -29,3 +29,19 @@ release: distcheck
printf "$$file.md5\t"; cat ../$$file.md5 | cut -f1 -d' '; \
printf "$$file.sha256\t"; cat ../$$file.sha256 | cut -f1 -d' '; \
done
run:
srcdir=@srcdir@/test \
top_builddir=@top_builddir@ \
TENV_ROOT=$(tenv_root) \
@srcdir@/test/setup-root.sh
mkdir -p $(dir $(tenv_root)/@FINIT_CONF@)
echo 'tty [12345] @console linux noclear nologin' > $(tenv_root)/@FINIT_CONF@
-TENV_ROOT=$(tenv_root) \
TESTENV_PATH=@sbindir@:/bin \
FINIT_RCSD=@FINIT_RCSD@ \
test/tenv/start.sh finit
run : tenv_root ?= @abs_top_builddir@/run-rootfs
+6 -3
View File
@@ -89,11 +89,11 @@ AC_ARG_ENABLE(contrib,
enable_all_plugins=auto
AC_PLUGIN([alsa-utils], [no], [Save and restore ALSA sound settings using alsactl])
AC_PLUGIN([dbus], [no], [Setup and start system message bus, D-Bus])
AC_PLUGIN([hotplug], [yes], [Setup and start udev or mdev hotplug daemon])
AC_PLUGIN([modules-load], [no], [Scans /etc/modules-load.d for modules to load])
AC_PLUGIN([resolvconf], [no], [Setup necessary files for resolvconf])
AC_PLUGIN([x11-common], [no], [Console setup (for X)])
AC_PLUGIN([netlink], [yes], [Basic netlink plugin for IFUP/IFDN and GW events. Can be replaced with externally built plugin that links with libnl or similar.])
AC_PLUGIN([hotplug], [yes], [Setup and start udev or mdev hotplug daemon])
# Check for extra arguments or packages
AC_ARG_WITH(heading,
@@ -113,7 +113,7 @@ AC_ARG_WITH(rc-local,
[rclocal=$withval], [rclocal=yes])
AC_ARG_WITH(sysconfig,
AS_HELP_STRING([--with-sysconfig=DIR], [System environment, default /etc/default & /etc/conf.d]),
AS_HELP_STRING([--with-sysconfig=DIR], [System environment directory, sourced by .conf files, default /etc/default & /etc/conf.d]),
[sysconfig=$withval], [sysconfig=default])
AC_ARG_WITH(hostname,
@@ -224,6 +224,9 @@ AC_DEFINE_UNQUOTED(RESCUE_CONF, "$rescue_conf", [Finit rescue mode .conf])
AC_EXPAND_DIR(sample_conf, "$libdir/finit/sample.conf")
AC_DEFINE_UNQUOTED(SAMPLE_CONF, "$sample_conf", [Finit sameple.conf for initctl create])
AC_EXPAND_DIR(path_stdpath, "$sbindir:$bindir:/usr/sbin:/usr/bin:/sbin:/bin")
AC_DEFINE_UNQUOTED(_PATH_STDPATH, "$path_stdpath", [Default PATH])
# Generate all files
AC_OUTPUT
@@ -232,7 +235,7 @@ cat <<EOF
------------------ Summary ------------------
$PACKAGE_NAME version $PACKAGE_VERSION
Prefix................: $prefix
Exec prefix...........: $eprefix
Exec prefix...........: `eval echo $exec_prefix`
Sysconfdir............: `eval echo $sysconfdir`
Localstatedir.........: `eval echo $localstatedir`
Finit config file.....: $conf_path
+5 -2
View File
@@ -235,8 +235,11 @@ static void pidfile_init(void *arg)
*/
path = realpath(_PATH_VARRUN, NULL);
if (!path) {
_pe("Failed ");
return;
path = realpath("/run", NULL);
if (!path) {
_e("System does not have %s or /run, aborting.", _PATH_VARRUN);
return;
}
}
if (pidfile_add_path(&iw_pidfile, path))
-1
View File
@@ -716,7 +716,6 @@ static struct conf_change *conf_find(char *file)
struct conf_change *node, *tmp;
TAILQ_FOREACH_SAFE(node, &conf_change_list, link, tmp) {
_d("file: %s vs changed file: %s", file, node->name);
if (string_compare(node->name, file))
return node;
}
-5
View File
@@ -36,11 +36,6 @@
#include <lite/lite.h>
#include <uev/uev.h>
/* just in case */
#ifndef _PATH_STDPATH
#define _PATH_STDPATH "/usr/bin:/bin:/usr/sbin:/sbin"
#endif
#ifndef _PATH_VARRUN
#define _PATH_VARRUN "/var/run/"
#endif
+15 -2
View File
@@ -143,10 +143,9 @@ static int do_runlevel(char *arg)
struct init_request rq = {
.magic = INIT_MAGIC,
.cmd = INIT_CMD_RUNLVL,
.runlevel = (int)arg[0],
};
if (!rq.runlevel) {
if (!arg) {
int prevlevel = 0;
int runlevel;
char prev;
@@ -165,6 +164,9 @@ static int do_runlevel(char *arg)
return 0;
}
/* set runlevel */
rq.runlevel = (int)arg[0];
return client_send(&rq, sizeof(rq));
}
@@ -195,6 +197,13 @@ static int do_startstop(int cmd, char *arg)
.cmd = INIT_CMD_SVC_QUERY
};
if (!arg || !arg[0])
errx(1, "missing argument to %s", (cmd == INIT_CMD_START_SVC
? "start"
: (cmd == INIT_CMD_STOP_SVC
? "stop"
: "restart")));
strlcpy(rq.data, arg, sizeof(rq.data));
if (client_send(&rq, sizeof(rq))) {
fprintf(stderr, "No such job(s) or service(s): %s\n\n", rq.data);
@@ -343,6 +352,9 @@ static int do_cond(char *cmd)
{ NULL, NULL }
};
if (!cmd)
goto fallback;
arg = strpbrk(cmd, " \0");
if (arg)
*arg++ = 0;
@@ -352,6 +364,7 @@ static int do_cond(char *cmd)
return command[c].cb(arg);
}
fallback:
return do_cond_show(NULL);
}
+1 -1
View File
@@ -270,7 +270,7 @@ static int do_edit(char *arg, int creat)
char *editor[] = {
"sensible-editor",
"editor",
"${VISUAL:-${EDITOR:-$(command -v mg vi | head -1)}}"
"${VISUAL:-${EDITOR:-$(command -v mg || command -v vi)}}"
};
char path[256];
char *fn;
+38 -6
View File
@@ -918,24 +918,56 @@ static void parse_name(svc_t *svc, char *arg)
*/
static void parse_cmdline_args(svc_t *svc, char *cmd)
{
int i;
char sep = 0;
char *arg;
int i = 0;
strlcpy(svc->args[0], cmd, sizeof(svc->args[0]));
strlcpy(svc->args[i++], cmd, sizeof(svc->args[0]));
while (i < MAX_NUM_SVC_ARGS)
svc->args[i++][0] = 0;
/*
* Copy supplied args. Stop at MAX_NUM_SVC_ARGS-1 to allow the args
* array to be zero-terminated.
*/
for (i = 1; (arg = strtok(NULL, " ")) && i < (MAX_NUM_SVC_ARGS - 1); i++)
strlcpy(svc->args[i], arg, sizeof(svc->args[0]));
for (i = 1; (arg = strtok(NULL, " ")) && i < (MAX_NUM_SVC_ARGS - 1);) {
char ch = arg[0];
size_t len;
/* XXX: ugly string arg re-concatenation, fixme */
if (ch == '"' || ch == '\'')
sep = ch;
else if (sep)
strlcat(svc->args[i], " ", sizeof(svc->args[0]));
strlcat(svc->args[i], arg, sizeof(svc->args[0]));
/* string arg contained already? */
len = strlen(arg);
if (sep && len >= 1) {
ch = arg[len - 1];
if (ch != sep)
continue;
}
sep = 0;
i++;
}
/*
* Clear remaining args in case they were set earlier.
* This also zero-terminates the args array.
*/
for (; i < MAX_NUM_SVC_ARGS; i++)
svc->args[i][0] = 0;
while (i < MAX_NUM_SVC_ARGS)
svc->args[i++][0] = 0;
#if 0
for (i = 0; i < MAX_NUM_SVC_ARGS; i++) {
if (!svc->args[i][0])
break;
_d("%s ", svc->args[i]);
}
#endif
}
+1 -1
View File
@@ -44,6 +44,6 @@ fi
mkdir -p "$FINIT_RCSD"
tty=/dev/$(cat /sys/class/tty/console/active)
mkfifo "$tty"
ln -fs /shared/pts "$tty"
exec "$@"
-4
View File
@@ -138,7 +138,3 @@ echo "$finit_ppid" > "$TENV_ROOT"/running_test.pid
log "$color_reset" 'Setup of test environment done' ''
finit_pid=$(retry "pgrep -P $finit_ppid")
tty=/dev/$(texec cat /sys/class/tty/console/active)
texec cat "$tty" &
sleep 1
+2
View File
@@ -38,6 +38,7 @@ binaries = $(DEST)/bin/cat \
$(DEST)/bin/env \
$(DEST)/bin/find \
$(DEST)/bin/kill \
$(DEST)/bin/ln \
$(DEST)/bin/ls \
$(DEST)/bin/mkdir \
$(DEST)/bin/mkfifo \
@@ -57,6 +58,7 @@ dirs = $(DEST)/bin \
$(DEST)/etc \
$(DEST)/proc \
$(DEST)/sbin \
$(DEST)/shared \
$(DEST)/sys \
$(DEST)/test_assets \
$(DEST)/tmp
+4 -1
View File
@@ -45,4 +45,7 @@ exec "$unshare" \
--mount \
--mount-proc \
--uts --ipc --net \
"$chroot" "$TENV_ROOT" /bin/chrootsetup.sh "$@"
sh -c "
ln -fs /proc/1/fd/1 $TENV_ROOT/shared/pts;
exec $chroot $TENV_ROOT /bin/chrootsetup.sh $*
"