From 8fe4aad53ee7215f5e8969bab46cdbca82f83c5f Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Thu, 23 Apr 2020 15:16:40 +0200 Subject: [PATCH] Make run/task/service :ID optional, default to zero/NULL This patch makes the ':ID' field optional when registering non-inetd run/taks/service etc. It has always been optional in the .conf files, but internally we defaulted to ':1'. To open up for more useful conditions we now default to zero/NULL :ID, meaning the user now *must* keep track of the :ID field if they have multiple services with the same name. This should already have been an issue since such services would likely have conflicted with their PID files (same name). So it's unlikely to affect any user severely. Signed-off-by: Joachim Nilsson --- src/service.c | 12 +++++------- src/svc.c | 10 +++++++--- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/service.c b/src/service.c index 0c7e72cc..8e590055 100644 --- a/src/service.c +++ b/src/service.c @@ -977,20 +977,18 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file) parse_cmdline_args(svc, cmd); goto inetd_setup; } - if (!id) { - int n = svc_next_id_int(cmd); - if (n) { - snprintf(id_str, sizeof(id_str), "%d", n); - id = id_str; - } + /* inetd services need a unique ID, so we must always set one. */ + if (!id) { + snprintf(id_str, sizeof(id_str), "%d", svc_next_id_int(cmd)); + id = id_str; } } recreate: #endif if (!id) - id = "1"; + id = ""; svc = svc_find(cmd, id); if (!svc) { diff --git a/src/svc.c b/src/svc.c index 68fea45c..7b76e147 100644 --- a/src/svc.c +++ b/src/svc.c @@ -100,7 +100,8 @@ svc_t *svc_new(char *cmd, char *id, int type) svc->type = type; svc->job = job; - strlcpy(svc->id, id, sizeof(svc->id)); + if (id && id[0]) + strlcpy(svc->id, id, sizeof(svc->id)); strlcpy(svc->cmd, cmd, sizeof(svc->cmd)); /* Default description, if missing */ @@ -535,7 +536,10 @@ int svc_enabled(svc_t *svc) return 1; } -/* Same base service, return unique ID as an integer */ +/* + * Same base service, return unique ID as an integer + * Note: intended for use with INETD services. + */ int svc_next_id_int(char *cmd) { int n = 1; @@ -552,7 +556,7 @@ int svc_next_id_int(char *cmd) n++; } - return 0; + return 1; } int svc_is_unique(svc_t *svc)