From cbf4baf8ee8e459b24cf0f37bba5b36527e1330b Mon Sep 17 00:00:00 2001 From: Nora Schiffer Date: Tue, 10 Feb 2026 00:30:35 +0100 Subject: [PATCH 1/2] rcS, ubus: constify char * arguments and variables where appropriate Signed-off-by: Nora Schiffer --- procd.h | 2 +- rcS.c | 10 +++++----- rcS.h | 4 ++-- ubus.c | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/procd.h b/procd.h index c656d3b..f48edeb 100644 --- a/procd.h +++ b/procd.h @@ -27,7 +27,7 @@ #define __init __attribute__((constructor)) -extern char *ubus_socket; +extern const char *ubus_socket; void procd_connect_ubus(void); void procd_reconnect_ubus(int reconnect); diff --git a/rcS.c b/rcS.c index bfaf50b..45a96a9 100644 --- a/rcS.c +++ b/rcS.c @@ -125,7 +125,7 @@ static void q_initd_complete(struct runqueue *q, struct runqueue_task *p) free(s); } -static bool find_runqueue_list_entry(struct list_head *list, char *file, char *param) +static bool find_runqueue_list_entry(struct list_head *list, const char *file, const char *param) { struct initd *s; @@ -135,7 +135,7 @@ static bool find_runqueue_list_entry(struct list_head *list, char *file, char *p return false; } -static void add_initd(struct runqueue *q, char *file, char *param) +static void add_initd(struct runqueue *q, const char *file, const char *param) { static const struct runqueue_task_type initd_type = { .run = q_initd_run, @@ -168,7 +168,7 @@ static void add_initd(struct runqueue *q, char *file, char *param) runqueue_task_add(q, &s->proc.task, false); } -static int _rc(struct runqueue *q, char *path, const char *file, char *pattern, char *param) +static int _rc(struct runqueue *q, const char *path, const char *file, const char *pattern, const char *param) { char *dir = alloca(2 + strlen(path) + strlen(file) + strlen(pattern)); glob_t gl; @@ -194,7 +194,7 @@ static int _rc(struct runqueue *q, char *path, const char *file, char *pattern, return 0; } -int rcS(char *pattern, char *param, void (*q_empty)(struct runqueue *)) +int rcS(const char *pattern, const char *param, void (*q_empty)(struct runqueue *)) { runqueue_init(&q); q.empty_cb = q_empty; @@ -203,7 +203,7 @@ int rcS(char *pattern, char *param, void (*q_empty)(struct runqueue *)) return _rc(&q, "/etc/rc.d", pattern, "*", param); } -int rc(const char *file, char *param) +int rc(const char *file, const char *param) { return _rc(&r, "/etc/init.d", file, "", param); } diff --git a/rcS.h b/rcS.h index 91d37d1..9b6bb84 100644 --- a/rcS.h +++ b/rcS.h @@ -17,7 +17,7 @@ #include -extern int rcS(char *pattern, char *param, void (*q_empty)(struct runqueue *)); -extern int rc(const char *file, char *param); +extern int rcS(const char *pattern, const char *param, void (*q_empty)(struct runqueue *)); +extern int rc(const char *file, const char *param); #endif diff --git a/ubus.c b/ubus.c index b0b7c9a..23f640a 100644 --- a/ubus.c +++ b/ubus.c @@ -19,7 +19,7 @@ #include "procd.h" -char *ubus_socket = NULL; +const char *ubus_socket = NULL; static struct ubus_context *ctx; static struct uloop_timeout ubus_timer; static int timeout; From 3b0e92714ca88e9019e18ddc9d42565a0a492d70 Mon Sep 17 00:00:00 2001 From: Nora Schiffer Date: Tue, 10 Feb 2026 00:30:43 +0100 Subject: [PATCH 2/2] rcS: allow overriding init.d/rc.d paths Introduce -I and -R arguments which can be used to override the paths /etc/init.d and /etc/rc.d, allowing for some runlevel-like usecases. This will be used in Gluon [1] to support a 'config mode', which is currently realized using a downstream patch. [1] https://github.com/freifunk-gluon/gluon Signed-off-by: Nora Schiffer --- procd.c | 10 +++++++++- procd.h | 3 +++ rcS.c | 7 +++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/procd.c b/procd.c index 1223283..46ba680 100644 --- a/procd.c +++ b/procd.c @@ -83,6 +83,8 @@ static int usage(const char *prog) " -s Path to ubus socket\n" " -h run as hotplug daemon\n" " -d Enable debug messages\n" + " -I Path to init.d directory\n" + " -R Path to rc.d directory\n" " -S Print messages to stdout\n" "\n", prog); return 1; @@ -99,7 +101,7 @@ int main(int argc, char **argv) unsetenv("DBGLVL"); } - while ((ch = getopt(argc, argv, "d:s:h:S")) != -1) { + while ((ch = getopt(argc, argv, "d:s:h:I:R:S")) != -1) { switch (ch) { case 'h': return hotplug_run(optarg); @@ -109,6 +111,12 @@ int main(int argc, char **argv) case 'd': debug = atoi(optarg); break; + case 'I': + init_d_path = optarg; + break; + case 'R': + rc_d_path = optarg; + break; case 'S': ulog_channels = ULOG_STDIO; break; diff --git a/procd.h b/procd.h index f48edeb..55efc82 100644 --- a/procd.h +++ b/procd.h @@ -27,6 +27,9 @@ #define __init __attribute__((constructor)) +extern const char *init_d_path; +extern const char *rc_d_path; + extern const char *ubus_socket; void procd_connect_ubus(void); diff --git a/rcS.c b/rcS.c index 45a96a9..1e36c98 100644 --- a/rcS.c +++ b/rcS.c @@ -33,6 +33,9 @@ #include "procd.h" #include "rcS.h" +const char *init_d_path = "/etc/init.d"; +const char *rc_d_path = "/etc/rc.d"; + static struct runqueue q, r; struct initd { @@ -200,12 +203,12 @@ int rcS(const char *pattern, const char *param, void (*q_empty)(struct runqueue q.empty_cb = q_empty; q.max_running_tasks = 1; - return _rc(&q, "/etc/rc.d", pattern, "*", param); + return _rc(&q, rc_d_path, pattern, "*", param); } int rc(const char *file, const char *param) { - return _rc(&r, "/etc/init.d", file, "", param); + return _rc(&r, init_d_path, file, "", param); } static void r_empty(struct runqueue *q)