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 <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson
2020-04-23 15:21:28 +02:00
parent 54e5fd2a78
commit 8fe4aad53e
2 changed files with 12 additions and 10 deletions
+5 -7
View File
@@ -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) {
+7 -3
View File
@@ -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)