mirror of
https://github.com/troglobit/finit.git
synced 2026-11-13 17:00:16 +00:00
conf: pass -- in a block command to the program
A command that takes -- as an argument lost it, and everything after
it, to the description:
service name {
command = "cmd -- arg"
description = "a cmd"
}
ran `cmd` with description `arg`.
The block translator builds a legacy one-liner, appending the
description as "-- text", and service_register() splits that line at
the first "-- ", here the one in the command.
Split the description off only for legacy one-liners. Blocks now hand
it to the new service_register_desc() as an argument.
Fixes #512
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
5 files changed
+69
-30
No files matched your search
+5
-7
@@ -1126,7 +1126,7 @@ static int sec_getbool(cfg_t *sec, const char *key, const char *alias)
|
||||
* The line-based format could only spell this as one stanza per
|
||||
* candidate, relying on nowarn to skip the ones that were not
|
||||
* installed. A candidate not being there is not an error here, so
|
||||
* only the winner is looked up again by service_register().
|
||||
* only the winner is looked up again by service_register_desc().
|
||||
*
|
||||
* A leading '-' still says a missing binary is expected, cf. systemd
|
||||
* ExecStart=-.
|
||||
@@ -1443,7 +1443,7 @@ static void provides_translate(cfg_t *sec, svc_t *svc, char *file)
|
||||
/*
|
||||
* These have no legacy token, they are validated by service_set_dir()
|
||||
* and stored directly on the registered svc. Empty means unset,
|
||||
* service_register() has already cleared the fields.
|
||||
* service_register_desc() has already cleared the fields.
|
||||
*/
|
||||
static void dirs_translate(cfg_t *sec, svc_t *svc, char *file)
|
||||
{
|
||||
@@ -1728,11 +1728,9 @@ static void svc_translate(cfg_t *sec, int type, struct rlimit rlimit[], char *fi
|
||||
/* the command and its arguments, verbatim */
|
||||
addtok(line, sizeof(line), "%s", cmd);
|
||||
|
||||
if ((str = sec_getstr(sec, "description", "desc")))
|
||||
addtok(line, sizeof(line), "-- %s", str);
|
||||
|
||||
str = sec_getstr(sec, "description", "desc");
|
||||
dbg("translated: %s", line);
|
||||
svc = service_register(type, line, rlimit, file);
|
||||
svc = service_register_desc(type, line, str, rlimit, file);
|
||||
if (!svc)
|
||||
return;
|
||||
|
||||
@@ -1807,7 +1805,7 @@ static void tty_translate(cfg_t *sec, struct rlimit rlimit[], char *file)
|
||||
addtok(line, sizeof(line), "%s", str);
|
||||
|
||||
dbg("translated: tty %s", line);
|
||||
service_register(SVC_TYPE_TTY, line, rlimit, file);
|
||||
service_register_desc(SVC_TYPE_TTY, line, NULL, rlimit, file);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
+45
-22
@@ -2156,9 +2156,10 @@ static void parse_cmdline_args(svc_t *svc, char *cmd, char **args)
|
||||
}
|
||||
|
||||
/**
|
||||
* service_register - Register service, task or run commands
|
||||
* service_register_desc - Register service, task or run commands
|
||||
* @type: %SVC_TYPE_SERVICE(0), %SVC_TYPE_TASK(1), %SVC_TYPE_RUN(2)
|
||||
* @cfg: Configuration, complete command, with -- for description text
|
||||
* @cfg: Configuration, complete command, without description text
|
||||
* @desc: Description text, or %NULL
|
||||
* @rlimit: Limits for this service/task/run, may be global limits
|
||||
* @file: The file name service was loaded from
|
||||
*
|
||||
@@ -2216,9 +2217,10 @@ static void parse_cmdline_args(svc_t *svc, char *cmd, char **args)
|
||||
* skipped on purpose -- conditional loading, bootstrap over, nowarn --
|
||||
* also returns %NULL, with @errno zero.
|
||||
*/
|
||||
svc_t *service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
||||
svc_t *service_register_desc(int type, char *cfg, const char *desc,
|
||||
struct rlimit rlimit[], char *file)
|
||||
{
|
||||
char *cmd, *desc, *runlevels = NULL, *cond = NULL;
|
||||
char *cmd, *runlevels = NULL, *cond = NULL;
|
||||
char *username = NULL, *log = NULL, *pid = NULL;
|
||||
char *name = NULL, *halt = NULL, *delay = NULL;
|
||||
char *id = NULL, *env = NULL, *cgroup = NULL;
|
||||
@@ -2254,24 +2256,6 @@ svc_t *service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
desc = strstr(line, "-- ");
|
||||
if (desc) {
|
||||
*desc = 0;
|
||||
desc += 3;
|
||||
|
||||
while (*desc && isblank(*desc))
|
||||
desc++;
|
||||
} else {
|
||||
int pos;
|
||||
|
||||
/* Find "--\n" to denote empty/no description */
|
||||
pos = (int)strlen(line) - 2;
|
||||
if (pos > 0 && !strcmp(&line[pos], "--")) {
|
||||
line[pos] = 0;
|
||||
desc = &line[pos];
|
||||
}
|
||||
}
|
||||
|
||||
args = line;
|
||||
cmd = parse_args(&args);
|
||||
if (!cmd) {
|
||||
@@ -2739,6 +2723,45 @@ svc_t *service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
||||
return svc;
|
||||
}
|
||||
|
||||
/**
|
||||
* service_register - Register from a legacy one-liner
|
||||
* @type: %SVC_TYPE_SERVICE(0), %SVC_TYPE_TASK(1), %SVC_TYPE_RUN(2)
|
||||
* @cfg: Configuration, complete command, with -- for description text
|
||||
* @rlimit: Limits for this service/task/run, may be global limits
|
||||
* @file: The file name service was loaded from
|
||||
*
|
||||
* The first "-- " in @cfg starts the description, the rest is handed
|
||||
* to service_register_desc().
|
||||
*/
|
||||
svc_t *service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
||||
{
|
||||
char *line, *desc;
|
||||
|
||||
if (!cfg)
|
||||
return service_register_desc(type, cfg, NULL, rlimit, file);
|
||||
|
||||
line = strdupa(cfg);
|
||||
desc = strstr(line, "-- ");
|
||||
if (desc) {
|
||||
*desc = 0;
|
||||
desc += 3;
|
||||
|
||||
while (*desc && isblank(*desc))
|
||||
desc++;
|
||||
} else {
|
||||
int pos;
|
||||
|
||||
/* Find "--\n" to denote empty/no description */
|
||||
pos = (int)strlen(line) - 2;
|
||||
if (pos > 0 && !strcmp(&line[pos], "--")) {
|
||||
line[pos] = 0;
|
||||
desc = &line[pos];
|
||||
}
|
||||
}
|
||||
|
||||
return service_register_desc(type, line, desc, rlimit, file);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function is called at the end of a runlevel change or reload
|
||||
* command to delete all remnants of removed services.
|
||||
|
||||
@@ -44,6 +44,8 @@ extern const struct svcdir svcdirs[NUM_SVCDIRS];
|
||||
|
||||
int service_set_dir (svc_t *svc, const struct svcdir *sd, const char *name);
|
||||
svc_t *service_register (int type, char *line, struct rlimit rlimit[], char *file);
|
||||
svc_t *service_register_desc (int type, char *line, const char *desc,
|
||||
struct rlimit rlimit[], char *file);
|
||||
void service_unregister (svc_t *svc);
|
||||
|
||||
void service_runtask_clean (void);
|
||||
|
||||
Reference in new issue
Block a user