Skip to content

Commit

Permalink
initctl: add support for showing [email protected]
Browse files Browse the repository at this point in the history
Fixes #411

Signed-off-by: Joachim Wiberg <[email protected]>
  • Loading branch information
troglobit committed Oct 13, 2024
1 parent dfaf351 commit 56e558c
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/serv.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ int serv_list(char *arg)
* If the resulting file doesn't exist, and creat is not set, *or*
* the base directory doesn't exist, we return NULL.
.*/
static char *conf(char *path, size_t len, char *name, int creat)
static char *conf(char *path, size_t len, char *name, int creat, int template)
{
if (!name || !name[0] || !strcmp(name, "finit") || !strcmp(name, "finit.conf")) {
strlcpy(path, finit_conf, len);
Expand All @@ -245,7 +245,13 @@ static char *conf(char *path, size_t len, char *name, int creat)

/* fall back to static service unless edit/create */
if (!creat && !fexist(path)) {
paste(path, len, finit_rcsd, name);
char *at = strchr(path, '@');

if (template && at)
*++at = 0;
else
paste(path, len, finit_rcsd, name);

if (suffix(path, len, ".conf"))
return NULL;
}
Expand Down Expand Up @@ -381,7 +387,7 @@ int serv_touch(char *arg)
}

/* 2. Try /etc/finit.d/available/$arg.conf and other combos (legacy) */
fn = conf(path, sizeof(path), arg, 0);
fn = conf(path, sizeof(path), arg, 0, 0);
if (!fexist(fn)) {
if (!strstr(arg, "finit.conf"))
ERRX(noerr ? 0 : 72, "%s not available.", arg);
Expand All @@ -405,13 +411,18 @@ int serv_show(char *arg)
char path[256];
char *fn;

fn = conf(path, sizeof(path), arg, 0);
fn = conf(path, sizeof(path), arg, 0, 0);
if (!fexist(fn)) {
if (is_builtin(arg))
ERRX(4, "%s is a built-in service.", arg);

WARNX("Cannot find %s", arg);
return 1;
fn = conf(path, sizeof(path), arg, 0, 1);
if (!fn || !fexist(fn)) {
WARNX("Cannot find %s", arg);
return 1;
}

return systemf("cat %s | sed 's/%%i/system/g'", fn);
}

return systemf("cat %s", fn);
Expand Down Expand Up @@ -442,7 +453,7 @@ static int do_edit(char *arg, int creat)
char path[256];
char *fn;

fn = conf(path, sizeof(path), arg, creat);
fn = conf(path, sizeof(path), arg, creat, 0);
if (!fexist(fn)) {
if (is_builtin(arg))
ERRX(4, "%s is a built-in service.", arg);
Expand Down Expand Up @@ -496,7 +507,7 @@ int serv_creat(char *arg)
return do_edit(arg, 1);

/* Open fn for writing from pipe */
fn = conf(buf, sizeof(buf), arg, 1);
fn = conf(buf, sizeof(buf), arg, 1, 0);
if (!fn)
ERR(73, "failed creating conf %s", arg);

Expand Down Expand Up @@ -525,7 +536,7 @@ int serv_delete(char *arg)
return serv_list("available");
}

fn = conf(buf, sizeof(buf), arg, 0);
fn = conf(buf, sizeof(buf), arg, 0, 0);
if (!fn) {
if (is_builtin(arg))
ERRX(4, "%s is a built-in service.", arg);
Expand Down

0 comments on commit 56e558c

Please sign in to comment.