mirror of
https://github.com/troglobit/finit.git
synced 2026-11-27 20:48:24 +00:00
initctl: usability improvements to ls/edit family of commands
- List /etc/finit.conf - Allow edit of /etc/finit.conf, using finit/finit.conf or NULL - Add helpful question to edit /etc/finit.conf if no edit arg. - Show available files if delete has no arg, like disable Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
015a52a20d
commit
93039e40cc
1 file changed
+35
-10
+35
-10
@@ -55,8 +55,27 @@ static void do_list(const char *path)
|
|||||||
glob_t gl;
|
glob_t gl;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
if (chdir(path))
|
if (chdir(path)) {
|
||||||
|
char *dir, *ptr;
|
||||||
|
|
||||||
|
if (!fexist(path))
|
||||||
return;
|
return;
|
||||||
|
dir = strdupa(path);
|
||||||
|
if (!dir)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ptr = strrchr(dir, '/');
|
||||||
|
if (ptr)
|
||||||
|
*ptr++ = 0;
|
||||||
|
else
|
||||||
|
ptr = dir;
|
||||||
|
|
||||||
|
if (heading)
|
||||||
|
print_header("%s%s ", once ? "\n" : "", dir);
|
||||||
|
puts(ptr);
|
||||||
|
puts("");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (glob("*.conf", 0, NULL, &gl))
|
if (glob("*.conf", 0, NULL, &gl))
|
||||||
return;
|
return;
|
||||||
@@ -135,15 +154,19 @@ int serv_list(char *arg)
|
|||||||
if (fisdir(FINIT_RCSD))
|
if (fisdir(FINIT_RCSD))
|
||||||
do_list(FINIT_RCSD);
|
do_list(FINIT_RCSD);
|
||||||
|
|
||||||
|
if (fexist(FINIT_CONF))
|
||||||
|
do_list(FINIT_CONF);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return path to configuration file for 'name', relative to FINIT_RCSD.
|
* Return path to configuration file for 'name'. This may be any of the
|
||||||
* This may be any of the following, provided sysconfdir is /etc:
|
* following, provided sysconfdir is /etc:
|
||||||
*
|
*
|
||||||
* - /etc/finit.d/$name.conf
|
|
||||||
* - /etc/finit.d/available/$name.conf
|
* - /etc/finit.d/available/$name.conf
|
||||||
|
* - /etc/finit.d/$name.conf
|
||||||
|
* - /etc/finit.conf
|
||||||
*
|
*
|
||||||
* The system *may* have a /etc/finit.d/available/ directory, or it may
|
* The system *may* have a /etc/finit.d/available/ directory, or it may
|
||||||
* just use a plain /etc/finit.d/ -- we do not set policy.
|
* just use a plain /etc/finit.d/ -- we do not set policy.
|
||||||
@@ -155,7 +178,7 @@ static char *conf(char *path, size_t len, char *name, int creat)
|
|||||||
{
|
{
|
||||||
char corr[40];
|
char corr[40];
|
||||||
|
|
||||||
if (!name || !name[0]) {
|
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;
|
||||||
}
|
}
|
||||||
@@ -319,7 +342,7 @@ static int do_edit(char *arg, int creat)
|
|||||||
if (!fexist(fn)) {
|
if (!fexist(fn)) {
|
||||||
if (!creat) {
|
if (!creat) {
|
||||||
warnx("Cannot find %s, use -c flag, create command, or select one of:", arg);
|
warnx("Cannot find %s, use -c flag, create command, or select one of:", arg);
|
||||||
return serv_list("available");
|
return serv_list(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SAMPLE_CONF
|
#ifdef SAMPLE_CONF
|
||||||
@@ -341,8 +364,8 @@ static int do_edit(char *arg, int creat)
|
|||||||
int serv_edit(char *arg)
|
int serv_edit(char *arg)
|
||||||
{
|
{
|
||||||
if (!arg || !arg[0]) {
|
if (!arg || !arg[0]) {
|
||||||
warnx("missing argument to edit, may be one of:");
|
if (!yorn("Do you want to edit %s (y/N)? ", FINIT_CONF))
|
||||||
return serv_list("available");
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return do_edit(arg, icreate);
|
return do_edit(arg, icreate);
|
||||||
@@ -386,8 +409,10 @@ int serv_delete(char *arg)
|
|||||||
char buf[256];
|
char buf[256];
|
||||||
char *fn;
|
char *fn;
|
||||||
|
|
||||||
if (!arg || !arg[0])
|
if (!arg || !arg[0]) {
|
||||||
errx(1, "missing argument to delete");
|
warnx("missing argument to delete, may be one of:");
|
||||||
|
return serv_list("available");
|
||||||
|
}
|
||||||
|
|
||||||
fn = conf(buf, sizeof(buf), arg, 0);
|
fn = conf(buf, sizeof(buf), arg, 0);
|
||||||
if (!fn)
|
if (!fn)
|
||||||
|
|||||||
Reference in new issue
Block a user