mirror of
https://github.com/troglobit/finit.git
synced 2026-10-30 12:50:34 +00:00
initctl: refactor to use new suffix() function
Reduce code duplication and use suffix() function to check and append a suffix to a path. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
7b501f255b
commit
deada0fa89
1 file changed
+13
-15
+13
-15
@@ -224,18 +224,11 @@ int serv_list(char *arg)
|
|||||||
.*/
|
.*/
|
||||||
static char *conf(char *path, size_t len, char *name, int creat)
|
static char *conf(char *path, size_t len, char *name, int creat)
|
||||||
{
|
{
|
||||||
char corr[40];
|
|
||||||
|
|
||||||
if (!name || !name[0] || !strcmp(name, "finit") || !strcmp(name, "finit.conf")) {
|
if (!name || !name[0] || !strcmp(name, "finit") || !strcmp(name, "finit.conf")) {
|
||||||
strlcpy(path, finit_conf, len);
|
strlcpy(path, finit_conf, len);
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strstr(name, ".conf")) {
|
|
||||||
snprintf(corr, sizeof(corr), "%s.conf", name);
|
|
||||||
name = corr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!fisdir(finit_rcsd))
|
if (!fisdir(finit_rcsd))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@@ -243,14 +236,19 @@ static char *conf(char *path, size_t len, char *name, int creat)
|
|||||||
if (!fisdir(path)) {
|
if (!fisdir(path)) {
|
||||||
if (creat && mkdir(path, 0755) && errno != EEXIST)
|
if (creat && mkdir(path, 0755) && errno != EEXIST)
|
||||||
return NULL;
|
return NULL;
|
||||||
else
|
paste(path, len, finit_rcsd, name);
|
||||||
paste(path, len, finit_rcsd, name);
|
|
||||||
} else
|
} else
|
||||||
strlcat(path, name, len);
|
strlcat(path, name, len);
|
||||||
|
|
||||||
|
if (suffix(path, len, ".conf"))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
/* fall back to static service unless edit/create */
|
/* fall back to static service unless edit/create */
|
||||||
if (!creat && !fexist(path))
|
if (!creat && !fexist(path)) {
|
||||||
paste(path, len, finit_rcsd, name);
|
paste(path, len, finit_rcsd, name);
|
||||||
|
if (suffix(path, len, ".conf"))
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
@@ -336,14 +334,14 @@ int do_disable(char *arg, int check)
|
|||||||
return serv_list("available");
|
return serv_list("available");
|
||||||
}
|
}
|
||||||
|
|
||||||
len = strlen(arg);
|
len = strlen(arg) + 7;
|
||||||
serv = alloca(len + 6);
|
serv = alloca(len);
|
||||||
if (!serv)
|
if (!serv)
|
||||||
ERR(71, "failed allocating stack");
|
ERR(71, "failed allocating stack");
|
||||||
|
|
||||||
strlcpy(serv, arg, len + 6);
|
strlcpy(serv, arg, len);
|
||||||
if (len < 6 || strcmp(&serv[len - 5], ".conf"))
|
if (suffix(serv, len, ".conf"))
|
||||||
strlcat(serv, ".conf", len + 6);
|
ERR(71, "failed composing service name (%s)", serv);
|
||||||
|
|
||||||
if (chdir(finit_rcsd))
|
if (chdir(finit_rcsd))
|
||||||
ERR(72, "failed cd %s", finit_rcsd);
|
ERR(72, "failed cd %s", finit_rcsd);
|
||||||
|
|||||||
Reference in new issue
Block a user