mirror of
https://github.com/troglobit/finit.git
synced 2026-10-04 06:44:12 +07:00
initctl: add -c create flag, to force creation at edit
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
+8
-1
@@ -48,6 +48,7 @@ struct command {
|
||||
int (*cb)(char *arg);
|
||||
};
|
||||
|
||||
int icreate = 0;
|
||||
int heading = 1;
|
||||
int numeric = 0;
|
||||
int verbose = 0;
|
||||
@@ -645,6 +646,7 @@ static int usage(int rc)
|
||||
"\n"
|
||||
"Options:\n"
|
||||
" -b, --batch Batch mode, no screen size probing\n"
|
||||
" -c, --create Create missing paths (and files) as needed\n"
|
||||
" -n, --numeric Show JOB:ID instead of NAME:ID\n"
|
||||
" -t, --no-heading Skip table headings\n"
|
||||
" -v, --verbose Verbose output\n"
|
||||
@@ -738,6 +740,7 @@ int main(int argc, char *argv[])
|
||||
};
|
||||
struct option long_options[] = {
|
||||
{ "batch", 0, NULL, 'b' },
|
||||
{ "create", 0, NULL, 'c' },
|
||||
{ "help", 0, NULL, 'h' },
|
||||
{ "numeric", 0, NULL, 'n' },
|
||||
{ "no-heading", 0, NULL, 't' },
|
||||
@@ -748,12 +751,16 @@ int main(int argc, char *argv[])
|
||||
if (transform(progname(argv[0])))
|
||||
return reboot_main(argc, argv);
|
||||
|
||||
while ((c = getopt_long(argc, argv, "bh?ntv", long_options, NULL)) != EOF) {
|
||||
while ((c = getopt_long(argc, argv, "bch?ntv", long_options, NULL)) != EOF) {
|
||||
switch(c) {
|
||||
case 'b':
|
||||
interactive = 0;
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
icreate = 1;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
case '?':
|
||||
return usage(0);
|
||||
|
||||
+15
-18
@@ -35,6 +35,7 @@
|
||||
static const char *cwd;
|
||||
static const char *available = FINIT_RCSD "/available";
|
||||
static const char *enabled = FINIT_RCSD "/enabled";
|
||||
extern int icreate; /* initctl -c */
|
||||
|
||||
static void pushd(const char *dir)
|
||||
{
|
||||
@@ -246,28 +247,19 @@ static int do_edit(char *arg, int creat)
|
||||
"mg",
|
||||
"vi"
|
||||
};
|
||||
char corr[40];
|
||||
char path[256];
|
||||
char *fn;
|
||||
|
||||
if (!arg || !arg[0])
|
||||
return serv_list(NULL);
|
||||
|
||||
if (!strstr(arg, ".conf")) {
|
||||
snprintf(corr, sizeof(corr), "%s.conf", arg);
|
||||
arg = corr;
|
||||
}
|
||||
|
||||
pushd(FINIT_RCSD);
|
||||
if (mkdir("available", 0755) && EEXIST != errno)
|
||||
err(1, "Failed creating %s/available directory", FINIT_RCSD);
|
||||
|
||||
snprintf(path, sizeof(path), "%s/%s", available, arg);
|
||||
if (!fexist(path)) {
|
||||
if (!creat)
|
||||
fn = conf(path, sizeof(path), arg, creat);
|
||||
if (!fexist(fn)) {
|
||||
if (!creat) {
|
||||
warnx("Cannot find %s, use create command, or select one of:", arg);
|
||||
return serv_list(NULL);
|
||||
}
|
||||
|
||||
/* XXX: fill with template/commented-out examples */
|
||||
}
|
||||
} else if (creat)
|
||||
warnx("the file %s already exists, falling back to edit.", fn);
|
||||
|
||||
for (size_t i = 0; i < NELEMS(editor); i++) {
|
||||
if (systemf("%s %s 2>/dev/null", editor[i], path))
|
||||
@@ -280,7 +272,12 @@ static int do_edit(char *arg, int creat)
|
||||
|
||||
int serv_edit(char *arg)
|
||||
{
|
||||
return do_edit(arg, 0);
|
||||
if (!arg || !arg[0]) {
|
||||
warnx("missing argument to edit, may be one of:");
|
||||
return serv_list("available");
|
||||
}
|
||||
|
||||
return do_edit(arg, icreate);
|
||||
}
|
||||
|
||||
int serv_creat(char *arg)
|
||||
|
||||
Reference in New Issue
Block a user