initctl: introduce -f,--force option, for delete command

Never prompt, for scripting.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2021-02-28 12:20:29 +01:00
1 parent 5dcf7be3c9
commit 460add3cae
2 files changed
+12 -6

No files matched your search

+8 -1
View File
@@ -49,6 +49,7 @@ struct command {
}; };
int icreate = 0; int icreate = 0;
int iforce = 0;
int heading = 1; int heading = 1;
int numeric = 0; int numeric = 0;
int verbose = 0; int verbose = 0;
@@ -666,6 +667,7 @@ static int usage(int rc)
"Options:\n" "Options:\n"
" -b, --batch Batch mode, no screen size probing\n" " -b, --batch Batch mode, no screen size probing\n"
" -c, --create Create missing paths (and files) as needed\n" " -c, --create Create missing paths (and files) as needed\n"
" -f, --force Ignore missing files and arguments, never prompt\n"
" -n, --numeric Show JOB:ID instead of NAME:ID\n" " -n, --numeric Show JOB:ID instead of NAME:ID\n"
" -t, --no-heading Skip table headings\n" " -t, --no-heading Skip table headings\n"
" -v, --verbose Verbose output\n" " -v, --verbose Verbose output\n"
@@ -775,6 +777,7 @@ int main(int argc, char *argv[])
struct option long_options[] = { struct option long_options[] = {
{ "batch", 0, NULL, 'b' }, { "batch", 0, NULL, 'b' },
{ "create", 0, NULL, 'c' }, { "create", 0, NULL, 'c' },
{ "force", 0, NULL, 'f' },
{ "help", 0, NULL, 'h' }, { "help", 0, NULL, 'h' },
{ "numeric", 0, NULL, 'n' }, { "numeric", 0, NULL, 'n' },
{ "no-heading", 0, NULL, 't' }, { "no-heading", 0, NULL, 't' },
@@ -787,7 +790,7 @@ int main(int argc, char *argv[])
if (transform(progname(argv[0]))) if (transform(progname(argv[0])))
return reboot_main(argc, argv); return reboot_main(argc, argv);
while ((c = getopt_long(argc, argv, "bch?ntv", long_options, NULL)) != EOF) { while ((c = getopt_long(argc, argv, "bcfh?ntv", long_options, NULL)) != EOF) {
switch(c) { switch(c) {
case 'b': case 'b':
interactive = 0; interactive = 0;
@@ -797,6 +800,10 @@ int main(int argc, char *argv[])
icreate = 1; icreate = 1;
break; break;
case 'f':
iforce = 1;
break;
case 'h': case 'h':
case '?': case '?':
return usage(0); return usage(0);
+4 -5
View File
@@ -33,6 +33,7 @@
#include "util.h" #include "util.h"
extern int icreate; /* initctl -c */ extern int icreate; /* initctl -c */
extern int iforce; /* initctl -f */
static int calc_width(char *arr[], size_t len) static int calc_width(char *arr[], size_t len)
@@ -352,12 +353,10 @@ int serv_delete(char *arg)
if (!fn) if (!fn)
errx(1, FINIT_RCSD " missing on system."); errx(1, FINIT_RCSD " missing on system.");
if (!fexist(fn)) { if (!fexist(fn))
warnx("Cannot find %s", fn); warnx("cannot find %s", fn);
return 1;
}
if (yorn("Remove file and symlink(s) to %s (y/N)? ", fn)) { if (iforce || yorn("Remove file and symlink(s) to %s (y/N)? ", fn)) {
do_disable(arg, 0); do_disable(arg, 0);
remove(fn); remove(fn);
} }