From 33fd6f004969b2f3a3756c9b26186f5ab532e411 Mon Sep 17 00:00:00 2001 From: Robert Andersson Date: Thu, 16 Aug 2018 09:28:57 +0200 Subject: [PATCH 1/9] Add modules-load.d plugin This plugin scans /etc/modules-load.d for modules to modprobe. Signed-off-by: Robert Andersson --- configure.ac | 1 + docs/plugins.md | 2 + plugins/Makefile.am | 8 ++++ plugins/modules-load.c | 105 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 116 insertions(+) create mode 100644 plugins/modules-load.c diff --git a/configure.ac b/configure.ac index 3896a00f..bae45ceb 100644 --- a/configure.ac +++ b/configure.ac @@ -95,6 +95,7 @@ AC_PLUGIN([inetd-chargen], [no], [Inetd plugin: character generator, RFC864]) AC_PLUGIN([inetd-daytime], [no], [Inetd plugin: daytime server, RFC867]) AC_PLUGIN([inetd-discard], [no], [Inetd plugin: discard server, RFC863]) AC_PLUGIN([inetd-time], [no], [Inetd plugin: time (rdate) server, RFC868]) +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.]) diff --git a/docs/plugins.md b/docs/plugins.md index 8c2d8eb8..3fc6b438 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -47,6 +47,8 @@ For your convenience a set of *optional* plugins are available: * *initctl.so*: Extends finit with a traditional `initctl` functionality. +* *modules-load.so*: Scans /etc/modules-load.d for modules to modprobe. + * *netlink.so*: Listens to Linux kernel Netlink events for gateway and interfaces. These events are then sent to the Finit service monitor for services that may want to be SIGHUP'ed on new default route or diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 17a67cae..73d7c7c9 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -39,6 +39,10 @@ libplug_la_SOURCES += time.c endif endif +if BUILD_MODULES_LOAD_PLUGIN +libplug_la_SOURCES += modules-load.c +endif + if BUILD_NETLINK_PLUGIN libplug_la_SOURCES += netlink.c endif @@ -80,6 +84,10 @@ pkglib_LTLIBRARIES += time.la endif endif +if BUILD_MODULES_LOAD_PLUGIN +pkglib_LTLIBRARIES += modules-load.la +endif + if BUILD_NETLINK_PLUGIN pkglib_LTLIBRARIES += netlink.la endif diff --git a/plugins/modules-load.c b/plugins/modules-load.c new file mode 100644 index 00000000..9e03201d --- /dev/null +++ b/plugins/modules-load.c @@ -0,0 +1,105 @@ +/* Scans /etc/modules-load.d for modules to load. + * + * Copyright (c) 2018 Robert Andersson + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include +#include +#include +#include + +#include "finit.h" +#include "helpers.h" +#include "plugin.h" +#include "service.h" +#include "conf.h" + +#define MODULES_LOAD_PATH "/etc/modules-load.d" +#define SERVICE_LINE ":%d [2345] /sbin/modprobe %s %s -- Kernel module: %s" + +static void load(void *arg) +{ + FILE *fp; + DIR *dirp; + struct dirent *direntp; + char line[256]; + int index = 1; + + _d("Scanning " MODULES_LOAD_PATH " for config files ..."); + + dirp = opendir(MODULES_LOAD_PATH); + if (!dirp) return; + + while ((direntp = readdir(dirp))) + { + char module_path[PATH_MAX]; + strlcpy(module_path, MODULES_LOAD_PATH "/", sizeof(module_path)); + strlcat(module_path, direntp->d_name, sizeof(module_path)); + + fp = fopen(module_path, "r"); + if (!fp) continue; + + while (fgets(line, sizeof(line), fp)) { + char cmd[CMD_SIZE], *mod, *args; + + mod = strip_line(line); + if (!*mod) continue; + + mod = chomp(mod); + if (!mod || !*mod) continue; + + mod = strtok_r(mod, " ", &args); + + snprintf(cmd, sizeof(cmd), SERVICE_LINE, index, mod, args, mod); + service_register(SVC_TYPE_TASK, cmd, global_rlimit, NULL); + + index++; + } + + fclose(fp); + } + + closedir(dirp); +} + +static plugin_t plugin = { + .name = __FILE__, + .hook[HOOK_BASEFS_UP] = { + .cb = load + }, +}; + +PLUGIN_INIT(plugin_init) +{ + plugin_register(&plugin); +} + +PLUGIN_EXIT(plugin_exit) +{ + plugin_unregister(&plugin); +} + +/** + * Local Variables: + * indent-tabs-mode: t + * c-file-style: "linux" + * End: + */ From f2cab53e559a68587cba5fe3b76dbf3a04387f68 Mon Sep 17 00:00:00 2001 From: Robert Andersson Date: Wed, 12 Sep 2018 13:46:31 +0200 Subject: [PATCH 2/9] Add service/task name config option Allows the service/task name derived from the binary to be overridden with a custom name. Example: service name:dhcpd [2] /usr/sbin/udhcpd -f -- DHCP Server Signed-off-by: Robert Andersson --- docs/config.md | 6 ++++++ src/inetd.c | 1 + src/initctl.c | 9 +-------- src/service.c | 22 ++++++++++++++++++++++ src/svc.c | 19 +++---------------- src/svc.h | 1 + 6 files changed, 34 insertions(+), 24 deletions(-) diff --git a/docs/config.md b/docs/config.md index 3d8b65ee..b8c3e16e 100644 --- a/docs/config.md +++ b/docs/config.md @@ -185,6 +185,12 @@ Syntax For a detailed description of conditions, and how to debug them, see the [Finit Conditions](conditions.md) document. + The name of a service, shown by the `initctl` tool, defaults to the + basename of the service executable. It can be changed with the + optional `name` argument: + + name: + * `inetd service/proto[@iflist] [LVLS] /path/to/daemon args` Launch a daemon when a client initiates a connection on an Internet port. Available services are listed in the UNIX `/etc/services` file. diff --git a/src/inetd.c b/src/inetd.c index 60c194db..1ef0ecc5 100644 --- a/src/inetd.c +++ b/src/inetd.c @@ -226,6 +226,7 @@ static void socket_cb(uev_t *w, void *arg, int events) strlcpy(task->desc, svc->desc, sizeof(task->desc) - strlen(conn)); strlcat(task->desc, conn, sizeof(task->desc)); strlcpy(task->iifname, iifname, sizeof(task->iifname)); + strlcpy(task->name, svc->name, sizeof(task->name)); task->stdin_fd = stdin; service_step(task); diff --git a/src/initctl.c b/src/initctl.c index ac7d66a6..abb76fb4 100644 --- a/src/initctl.c +++ b/src/initctl.c @@ -459,14 +459,7 @@ static int show_status(char *arg) if (!verbose) { int adj = screen_cols - 60; - char *name = strrchr(svc->cmd, '/'); - - if (!name) - name = svc->cmd; - else - name++; - - printf("%-16.16s %-*.*s\n", name, adj, adj, svc->desc); + printf("%-16.16s %-*.*s\n", svc->name, adj, adj, svc->desc); continue; } diff --git a/src/service.c b/src/service.c index 20889573..a471a245 100644 --- a/src/service.c +++ b/src/service.c @@ -569,6 +569,23 @@ static void parse_log(svc_t *svc, char *arg) } } +/* + * name: + */ +static void parse_name(svc_t *svc, char *arg) +{ + char *name = NULL; + + if (arg && !strncasecmp(arg, "name:", 5)) { + name = arg + 5; + } else { + name = strrchr(svc->cmd, '/'); + name = name ? name + 1 : svc->cmd; + } + + strlcpy(svc->name, name, sizeof(svc->name)); +} + /** * parse_cmdline_args - Update the command line args in the svc struct * @@ -659,6 +676,7 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file) char *username = NULL, *log = NULL, *pid = NULL; char *service = NULL, *proto = NULL, *ifaces = NULL; char *cmd, *desc, *runlevels = NULL, *cond = NULL; + char *name = NULL; svc_t *svc; plugin_t *plugin = NULL; @@ -716,6 +734,8 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file) log = cmd; else if (!strncasecmp(cmd, "pid", 3)) pid = cmd; + else if (!strncasecmp(cmd, "name:", 5)) + name = cmd; else if (cmd[0] != '/' && strchr(cmd, '/')) service = cmd; /* inetd service/proto */ else @@ -831,6 +851,8 @@ recreate: conf_parse_cond(svc, cond); + parse_name(svc, name); + if (log) parse_log(svc, log); if (desc) diff --git a/src/svc.c b/src/svc.c index bdf3c800..96eed7fc 100644 --- a/src/svc.c +++ b/src/svc.c @@ -80,7 +80,6 @@ static void svc_gc(void *arg) svc_t *svc_new(char *cmd, int id, int type) { int job = -1; - char *desc; svc_t *svc, *iter = NULL; /* Find first job n:o if registering multiple instances */ @@ -103,12 +102,7 @@ svc_t *svc_new(char *cmd, int id, int type) strlcpy(svc->cmd, cmd, sizeof(svc->cmd)); /* Default description, if missing */ - desc = strrchr(cmd, '/'); - if (desc) - desc++; - else - desc = cmd; - strlcpy(svc->desc, desc, sizeof(svc->desc)); + strlcpy(svc->desc, svc->name, sizeof(svc->desc)); TAILQ_INSERT_TAIL(&svc_list, svc, link); @@ -204,7 +198,7 @@ svc_t *svc_named_iterator(svc_t **iter, int first, char *cmd) svc_t *svc; for (svc = svc_iterator(iter, first); svc; svc = svc_iterator(iter, 0)) { - char *name = basename(svc->cmd); + char *name = svc->name; if (!strncmp(name, cmd, strlen(name))) return svc; @@ -362,17 +356,10 @@ svc_t *svc_find_by_jobid(int job, int id) */ svc_t *svc_find_by_nameid(char *name, int id) { - char *ptr; svc_t *svc, *iter = NULL; for (svc = svc_iterator(&iter, 1); svc; svc = svc_iterator(&iter, 0)) { - ptr = strrchr(svc->cmd, '/'); - if (ptr) - ptr++; - else - ptr = svc->cmd; - - if (svc->id == id && !strcmp(name, ptr)) + if (svc->id == id && !strcmp(name, svc->name)) return svc; } diff --git a/src/svc.h b/src/svc.h index 5f4adb0f..415ff741 100644 --- a/src/svc.h +++ b/src/svc.h @@ -104,6 +104,7 @@ typedef struct svc { int sighup; /* This service supports SIGHUP :) */ svc_block_t block; /* Reason that this service is currently stopped */ char cond[MAX_COND_LEN]; + char name[MAX_ARG_LEN]; /* Counters */ char once; /* run/task, (at least) once per runlevel */ From 423c8d41a783884d10ec886d3fa2aa00dfac75a0 Mon Sep 17 00:00:00 2001 From: Robert Andersson Date: Wed, 12 Sep 2018 13:54:02 +0200 Subject: [PATCH 3/9] modules-load: add task name config Signed-off-by: Robert Andersson --- plugins/modules-load.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/modules-load.c b/plugins/modules-load.c index 9e03201d..1fcf5e65 100644 --- a/plugins/modules-load.c +++ b/plugins/modules-load.c @@ -33,7 +33,8 @@ #include "conf.h" #define MODULES_LOAD_PATH "/etc/modules-load.d" -#define SERVICE_LINE ":%d [2345] /sbin/modprobe %s %s -- Kernel module: %s" +#define SERVICE_LINE \ + ":%d name:modprobe.%s [2345] /sbin/modprobe %s %s -- Kernel module: %s" static void load(void *arg) { @@ -68,7 +69,8 @@ static void load(void *arg) mod = strtok_r(mod, " ", &args); - snprintf(cmd, sizeof(cmd), SERVICE_LINE, index, mod, args, mod); + snprintf(cmd, sizeof(cmd), SERVICE_LINE, + index, mod, mod, args, mod); service_register(SVC_TYPE_TASK, cmd, global_rlimit, NULL); index++; From 6a7f1157813c43ba7b53ff56ecf81575e8ed8cec Mon Sep 17 00:00:00 2001 From: Robert Andersson Date: Thu, 27 Sep 2018 13:20:34 +0200 Subject: [PATCH 4/9] Add config option for manually started services Example: service manual:yes [2] /usr/sbin/lighttpd -- HTTP Server Signed-off-by: Robert Andersson --- docs/config.md | 6 ++++++ src/service.c | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/docs/config.md b/docs/config.md index b8c3e16e..6be0037a 100644 --- a/docs/config.md +++ b/docs/config.md @@ -185,6 +185,12 @@ Syntax For a detailed description of conditions, and how to debug them, see the [Finit Conditions](conditions.md) document. + If a service should not be automatically started, it can be configured + as manual with the optional `manual` argument. The service can then be + started at any time by running `initctl start `. + + manual:yes + The name of a service, shown by the `initctl` tool, defaults to the basename of the service executable. It can be changed with the optional `name` argument: diff --git a/src/service.c b/src/service.c index a471a245..290abf0f 100644 --- a/src/service.c +++ b/src/service.c @@ -672,6 +672,7 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file) int forking = 0; #endif int levels = 0; + int manual = 0; char *line; char *username = NULL, *log = NULL, *pid = NULL; char *service = NULL, *proto = NULL, *ifaces = NULL; @@ -736,6 +737,8 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file) pid = cmd; else if (!strncasecmp(cmd, "name:", 5)) name = cmd; + else if (!strncasecmp(cmd, "manual:yes", 10)) + manual = 1; else if (cmd[0] != '/' && strchr(cmd, '/')) service = cmd; /* inetd service/proto */ else @@ -811,6 +814,10 @@ recreate: free(line); return errno = ENOMEM; } + + if (type == SVC_TYPE_SERVICE && manual) { + svc_stop(svc); + } } #ifdef INETD_ENABLED else { From 12d14aae844c205c8501b792a2da2cc3df052a06 Mon Sep 17 00:00:00 2001 From: Robert Andersson Date: Wed, 12 Sep 2018 15:02:04 +0200 Subject: [PATCH 5/9] fix service enable/disable support Signed-off-by: Robert Andersson --- src/conf.c | 35 ++++++++++++++++------------------- src/serv.c | 8 ++++---- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/conf.c b/src/conf.c index abef1190..aefeb8ba 100644 --- a/src/conf.c +++ b/src/conf.c @@ -30,6 +30,7 @@ #include #include /* BSD sys/queue.h API */ #include +#include #include "finit.h" #include "cond.h" @@ -52,7 +53,7 @@ struct conf_change { char *name; }; -static uev_t w1, w2, w3; +static uev_t w1, w2, w3, w4; static TAILQ_HEAD(head, conf_change) conf_change_list = TAILQ_HEAD_INITIALIZER(conf_change_list); static int parse_conf(char *file); @@ -577,8 +578,8 @@ static int parse_conf(char *file) */ int conf_reload(void) { - int i, num; - struct dirent **e; + size_t i; + glob_t gl; /* Mark and sweep */ svc_mark_dynamic(); @@ -601,20 +602,14 @@ int conf_reload(void) parse_conf(FINIT_CONF); /* Next, read all *.conf in /etc/finit.d/ */ - num = scandir(rcsd, &e, NULL, alphasort); - if (num < 0) { - _d("Skipping %s, no files found ...", rcsd); - goto done; - } + glob("/etc/finit.d/*.conf", 0, NULL, &gl); + glob("/etc/finit.d/enabled/*.conf", GLOB_APPEND, NULL, &gl); - for (i = 0; i < num; i++) { - char *name = e[i]->d_name; - char path[LINE_SIZE]; + for (i = 0; i < gl.gl_pathc; i++) { + char *path = gl.gl_pathv[i]; size_t len; struct stat st; - snprintf(path, sizeof(path), "%s/%s", rcsd, name); - /* Check that it's an actual file ... beyond any symlinks */ if (lstat(path, &st)) { _d("Skipping %s, cannot access: %s", path, strerror(errno)); @@ -650,9 +645,7 @@ int conf_reload(void) parse_conf_dynamic(path); } - while (num--) - free(e[num]); - free(e); + globfree(&gl); done: /* Drop record of all .conf changes */ @@ -783,6 +776,9 @@ static void conf_cb(uev_t *w, void *arg, int events) break; } } + + if (conf_any_change()) + service_reload_dynamic(); } static int add_watcher(uev_ctx_t *ctx, uev_t *w, char *path, uint32_t opt) @@ -857,8 +853,9 @@ int conf_monitor(uev_ctx_t *ctx) * changes to either symlink or target. */ rc += add_watcher(ctx, &w1, FINIT_RCSD, 0); - rc += add_watcher(ctx, &w2, FINIT_RCSD "/available", IN_DONT_FOLLOW); - rc += add_watcher(ctx, &w3, FINIT_CONF, 0); + rc += add_watcher(ctx, &w2, FINIT_RCSD "/available/", IN_DONT_FOLLOW); + rc += add_watcher(ctx, &w3, FINIT_RCSD "/enabled/", 0); + rc += add_watcher(ctx, &w4, FINIT_CONF, 0); return rc + conf_reload(); } @@ -869,7 +866,7 @@ int conf_monitor(uev_ctx_t *ctx) int conf_init(void) { hostname = strdup(DEFHOST); - w1.fd = w2.fd = w3.fd = -1; + w1.fd = w2.fd = w3.fd = w4.fd = -1; return conf_monitor(NULL); } diff --git a/src/serv.c b/src/serv.c index 5228aa28..f638d9a8 100644 --- a/src/serv.c +++ b/src/serv.c @@ -120,7 +120,7 @@ int serv_list(char *arg) if (fisdir(enabled)) do_list("ENABLED ", enabled); if (fisdir(FINIT_RCSD)) - do_list("ENABLED ", FINIT_RCSD); + do_list("STATIC ", FINIT_RCSD); return 0; } @@ -140,11 +140,11 @@ int serv_enable(char *arg) } pushd(FINIT_RCSD); - snprintf(path, sizeof(path), "available/%s", arg); + snprintf(path, sizeof(path), "%s/%s", available, arg); if (!fexist(path)) errx(1, "Cannot find %s", path); - snprintf(link, sizeof(link), "%s/%s", FINIT_RCSD, arg); + snprintf(link, sizeof(link), "%s/%s", enabled, arg); if (fexist(link)) errx(1, "%s already exists", link); @@ -165,7 +165,7 @@ int serv_disable(char *arg) arg = corr; } - snprintf(link, sizeof(link), "%s/%s", FINIT_RCSD, arg); + snprintf(link, sizeof(link), "%s/%s", enabled, arg); if (stat(link, &st)) err(1, "Cannot find %s", link); From 053304012f1991aca3aa18c34495712426d3eaa0 Mon Sep 17 00:00:00 2001 From: Robert Andersson Date: Wed, 5 Sep 2018 17:02:09 +0200 Subject: [PATCH 6/9] Add option to log service/task output to the console Example: service log:console [2] /usr/sbin/udhcpd -f -- DHCP Server Signed-off-by: Robert Andersson --- docs/config.md | 1 + src/service.c | 9 +++++++-- src/svc.h | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/config.md b/docs/config.md index 6be0037a..7a563fa9 100644 --- a/docs/config.md +++ b/docs/config.md @@ -350,6 +350,7 @@ syslog using the native `logit` tool. The full syntax is: log:/path/to/file log:prio:facility.level,tag:ident + log:console log:null log diff --git a/src/service.c b/src/service.c index 290abf0f..0c620255 100644 --- a/src/service.c +++ b/src/service.c @@ -139,7 +139,7 @@ static int is_norespawn(void) * @svc: Service to start * * Returns: - * 0 if the service was successfully started. Non-zero otherwise. + * 0 if the service was successfully started. Non-zero otherwise. */ static int service_start(svc_t *svc) { @@ -243,6 +243,9 @@ static int service_start(svc_t *svc) redirect_null(); goto logit_done; } + if (svc->log.console) { + goto logit_done; + } /* * Open PTY to connect to logger. A pty isn't buffered @@ -466,7 +469,7 @@ static int service_stop(svc_t *svc) * * This function does some basic checks of the runtime state of Finit * and a sanity check of the @svc before sending %SIGHUP. - * + * * Returns: * POSIX OK(0) or non-zero on error. */ @@ -558,6 +561,8 @@ static void parse_log(svc_t *svc, char *arg) svc->log.enabled = 1; else if (!strcmp(tok, "null") || !strcmp(tok, "/dev/null")) svc->log.null = 1; + else if (!strcmp(tok, "console") || !strcmp(tok, "/dev/console")) + svc->log.console = 1; else if (tok[0] == '/') strlcpy(svc->log.file, tok, sizeof(svc->log.file)); else if (!strcmp(tok, "priority") || !strcmp(tok, "prio")) diff --git a/src/svc.h b/src/svc.h index 415ff741..b493e827 100644 --- a/src/svc.h +++ b/src/svc.h @@ -119,6 +119,7 @@ typedef struct svc { struct { char enabled; char null; + char console; char file[64]; char prio[20]; char ident[20]; From d371b85c4757e68fdf0322d19939e3808b0e55a2 Mon Sep 17 00:00:00 2001 From: Robert Andersson Date: Thu, 27 Sep 2018 13:12:21 +0200 Subject: [PATCH 7/9] fix C++ compilation issues Signed-off-by: Robert Andersson --- src/api.c | 4 ++-- src/client.c | 2 +- src/client.h | 2 +- src/service.c | 2 +- src/svc.c | 2 +- src/svc.h | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/api.c b/src/api.c index 08b60ac7..1eeaa2c4 100644 --- a/src/api.c +++ b/src/api.c @@ -352,8 +352,8 @@ static void api_cb(uev_t *w, void *arg, int events) if (wdog) { logit(LOG_NOTICE, "Stopping and removing %s (PID:%d)", wdog->cmd, wdog->pid); stop(wdog); - if (wdog->protected) { - wdog->protected = 0; + if (wdog->protect) { + wdog->protect = 0; wdog->runlevels = 0; } } diff --git a/src/client.c b/src/client.c index d5fec8cf..95f0d668 100644 --- a/src/client.c +++ b/src/client.c @@ -125,7 +125,7 @@ error: return NULL; } -svc_t *client_svc_find(char *arg) +svc_t *client_svc_find(const char *arg) { int sd = -1; struct init_request rq = { diff --git a/src/client.h b/src/client.h index b56c7b2b..42443132 100644 --- a/src/client.h +++ b/src/client.h @@ -32,6 +32,6 @@ int client_disconnect (void); int client_send (struct init_request *rq, ssize_t len); svc_t *client_svc_iterator (int first); -svc_t *client_svc_find (char *arg); +svc_t *client_svc_find (const char *arg); #endif /* FINIT_CLIENT_H_ */ diff --git a/src/service.c b/src/service.c index 0c620255..3bf634a4 100644 --- a/src/service.c +++ b/src/service.c @@ -909,7 +909,7 @@ recreate: svc_mark_clean(svc); if (!file) - svc->protected = 1; + svc->protect = 1; /* Free duped line, from above */ free(line); diff --git a/src/svc.c b/src/svc.c index 96eed7fc..5a9c4cd5 100644 --- a/src/svc.c +++ b/src/svc.c @@ -402,7 +402,7 @@ void svc_mark_dynamic(void) svc_t *svc, *iter = NULL; for (svc = svc_iterator(&iter, 1); svc; svc = svc_iterator(&iter, 0)) { - if (svc->protected) + if (svc->protect) continue; if (svc_is_inetd_conn(svc)) continue; diff --git a/src/svc.h b/src/svc.h index b493e827..453dea67 100644 --- a/src/svc.h +++ b/src/svc.h @@ -97,7 +97,7 @@ typedef struct svc { long start_time; /* Start time, as seconds since boot, from sysinfo() */ const svc_state_t state; /* Paused, Reloading, Restart, Running, ... */ svc_type_t type; /* Service, run, task, inetd, ... */ - int protected; /* Services like dbus-daemon & udev by Finit */ + int protect; /* Services like dbus-daemon & udev by Finit */ const int dirty; /* -1: removal, 0: unmodified, 1: modified */ int starting; /* ... waiting for pidfile to be re-asserted */ int runlevels; From b64dbbf8d0698b955d12f4731fd8194c6f528da4 Mon Sep 17 00:00:00 2001 From: Robert Andersson Date: Fri, 19 Oct 2018 16:20:23 +0200 Subject: [PATCH 8/9] fix condition string lengths Signed-off-by: Robert Andersson --- src/cond.c | 4 ++-- src/initctl.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cond.c b/src/cond.c index 38c62348..842d50e0 100644 --- a/src/cond.c +++ b/src/cond.c @@ -101,7 +101,7 @@ enum cond_state cond_get_agg(const char *names) { char *cond; enum cond_state s = COND_ON; - static char conds[MAX_ARG_LEN]; + static char conds[MAX_COND_LEN]; if (!names) return COND_ON; @@ -116,7 +116,7 @@ enum cond_state cond_get_agg(const char *names) int cond_affects(const char *name, const char *names) { char *cond; - static char conds[MAX_ARG_LEN]; + static char conds[MAX_COND_LEN]; if (!name || !names) return 0; diff --git a/src/initctl.c b/src/initctl.c index abb76fb4..eaf23e78 100644 --- a/src/initctl.c +++ b/src/initctl.c @@ -173,7 +173,7 @@ static int do_restart(char *arg) { return do_startstop(INIT_CMD_RESTART_SVC, arg static void show_cond_one(const char *_conds) { - static char conds[MAX_ARG_LEN]; + static char conds[MAX_COND_LEN]; char *cond; strlcpy(conds, _conds, sizeof(conds)); From 76fc72770e93b21dbe23773788ef9e2456522062 Mon Sep 17 00:00:00 2001 From: Robert Andersson Date: Mon, 3 Sep 2018 10:17:21 +0200 Subject: [PATCH 9/9] pidfile: monitor renamed files, e.g. rsyslogd.pid.tmp Signed-off-by: Robert Andersson --- plugins/pidfile.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/pidfile.c b/plugins/pidfile.c index 8c8f74e4..34140ec1 100644 --- a/plugins/pidfile.c +++ b/plugins/pidfile.c @@ -64,7 +64,7 @@ static void pidfile_callback(void *arg, int fd, int events) continue; mkcond(cond, sizeof(cond), svc->cmd); - if (ev->mask & (IN_CREATE | IN_ATTRIB | IN_MODIFY)) { + if (ev->mask & (IN_CREATE | IN_ATTRIB | IN_MODIFY | IN_MOVED_TO)) { svc_started(svc); cond_set(cond); } else if (ev->mask & IN_DELETE) @@ -111,6 +111,7 @@ static void pidfile_init(void *arg) { char *path; struct context *ctx = arg; + uint32_t mask = IN_CREATE | IN_ATTRIB | IN_DELETE | IN_MODIFY | IN_MOVED_TO; /* * The bootmisc plugin is responsible for setting up /var/run. @@ -123,7 +124,7 @@ static void pidfile_init(void *arg) return; } - ctx->wd = inotify_add_watch(ctx->fd, path, IN_CREATE | IN_ATTRIB | IN_DELETE | IN_MODIFY); + ctx->wd = inotify_add_watch(ctx->fd, path, mask); free(path); if (ctx->wd < 0) {