patches/finit: backport upstream fixes to initctl

Patches in queue for upcoming v4.8 release of Finit fixes:

 - initctl touch does not respect -n flag, returning error
 - initctl touch does not support template services

Related to issue #375

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2024-04-03 16:08:37 +02:00
parent f47da7c249
commit 34203db00a
2 changed files with 117 additions and 0 deletions
@@ -0,0 +1,41 @@
From 052136cb9927379e75bc346d46c86d728f1e33ef Mon Sep 17 00:00:00 2001
From: Joachim Wiberg <troglobit@gmail.com>
Date: Tue, 2 Apr 2024 16:03:31 +0200
Subject: [PATCH 08/12] initctl: touch does not respect -n switch
Organization: Addiva Elektronik
Fixes #402
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
---
src/serv.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/serv.c b/src/serv.c
index e14d5ec..1cace46 100644
--- a/src/serv.c
+++ b/src/serv.c
@@ -377,9 +377,9 @@ int serv_touch(char *arg)
fn = conf(path, sizeof(path), arg, 0);
if (!fexist(fn)) {
if (!strstr(arg, "finit.conf"))
- ERRX(72, "%s not available.", arg);
+ ERRX(noerr ? 0 : 72, "%s not available.", arg);
if (is_builtin(arg))
- ERRX(4, "%s is a built-in service.", arg);
+ ERRX(noerr ? 0 : 4, "%s is a built-in service.", arg);
strlcpy(path, finit_conf, sizeof(path));
fn = path;
@@ -387,7 +387,7 @@ int serv_touch(char *arg)
/* libite:touch() follows symlinks */
if (utimensat(AT_FDCWD, fn, NULL, AT_SYMLINK_NOFOLLOW))
- ERR(71, "failed marking %s for reload", fn);
+ ERR(noerr ? 0 : 71, "failed marking %s for reload", fn);
return 0;
}
--
2.34.1
@@ -0,0 +1,76 @@
From 7b501f255b5730ce9da5c72aa6abd87bbf20ba11 Mon Sep 17 00:00:00 2001
From: Joachim Wiberg <troglobit@gmail.com>
Date: Wed, 3 Apr 2024 06:46:18 +0200
Subject: [PATCH 09/12] initctl: touch does not support template services
Organization: Addiva Elektronik
Fixes #403
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
---
src/serv.c | 10 ++++++++++
src/util.h | 20 ++++++++++++++++++++
2 files changed, 30 insertions(+)
diff --git a/src/serv.c b/src/serv.c
index 1cace46..6344ce3 100644
--- a/src/serv.c
+++ b/src/serv.c
@@ -374,6 +374,15 @@ int serv_touch(char *arg)
return serv_list("enabled");
}
+ /* 1. Try /etc/finit.d/enabled/$arg.conf to handle template@.conf */
+ paste(path, sizeof(path), finit_rcsd, "enabled/");
+ strlcat(path, arg, sizeof(path));
+ if (!suffix(path, sizeof(path), ".conf") && fexist(path)) {
+ fn = path;
+ goto touchit;
+ }
+
+ /* 2. Try /etc/finit.d/available/$arg.conf and other combos (legacy) */
fn = conf(path, sizeof(path), arg, 0);
if (!fexist(fn)) {
if (!strstr(arg, "finit.conf"))
@@ -385,6 +394,7 @@ int serv_touch(char *arg)
fn = path;
}
+touchit:
/* libite:touch() follows symlinks */
if (utimensat(AT_FDCWD, fn, NULL, AT_SYMLINK_NOFOLLOW))
ERR(noerr ? 0 : 71, "failed marking %s for reload", fn);
diff --git a/src/util.h b/src/util.h
index 9f0cbf0..80e1c51 100644
--- a/src/util.h
+++ b/src/util.h
@@ -109,6 +109,26 @@ static inline int paste(char *buf, size_t len, const char *dir, const char *file
fisslashdir(dir) ? "" : file[0] == '/' ? "" : "/", file);
}
+/* ensure path has suffix */
+static inline int suffix(char *path, size_t len, const char *sfx)
+{
+ size_t slen = strlen(sfx);
+ size_t plen = strlen(path);
+
+ if (plen < slen)
+ slen = strlcat(path, sfx, len);
+ else {
+ plen -= slen;
+ if (strcmp(&path[plen], sfx))
+ slen = strlcat(path, sfx, len);
+ }
+
+ if (slen >= len)
+ return -1;
+
+ return 0;
+}
+
#endif /* FINIT_UTIL_H_ */
/**
--
2.34.1