From 8f1d1717f87cec32fa459ef6b1bf732267b299d1 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Mon, 27 Mar 2023 14:27:16 +0200 Subject: [PATCH] initctl: let -n ignore errors from enable/disable as well Signed-off-by: Joachim Wiberg --- src/initctl.c | 2 +- src/initctl.h | 1 + src/serv.c | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/initctl.c b/src/initctl.c index 60da06af..9c5ef8e6 100644 --- a/src/initctl.c +++ b/src/initctl.c @@ -1267,7 +1267,7 @@ static int usage(int rc) " -f, --force Ignore missing files and arguments, never prompt\n" " -h, --help This help text\n" " -j, --json JSON output in 'status' and 'cond' commands\n" - " -n, --noerr Ignore error for non-existent services\n" + " -n, --noerr Ignore error, e.g., already started/enabled/...\n" " -1, --once Only one lap in commands like 'top'\n" " -p, --plain Use plain table headings, no ctrl chars\n" " -q, --quiet Silent, only return status of command\n" diff --git a/src/initctl.h b/src/initctl.h index 16604062..939eb006 100644 --- a/src/initctl.h +++ b/src/initctl.h @@ -37,6 +37,7 @@ extern int iforce; /* initctl -f */ extern int ionce; /* initctl -1 */ extern int heading; /* initctl -t */ extern int json; /* initctl -j */ +extern int noerr; /* initctl -n */ extern int verbose; /* initctl -v */ extern int plain; /* initctl -p */ extern int quiet; /* initctl -q */ diff --git a/src/serv.c b/src/serv.c index 579737e9..9180664a 100644 --- a/src/serv.c +++ b/src/serv.c @@ -282,7 +282,7 @@ int serv_enable(char *arg) snprintf(argpath, sizeof(argpath), "%s/enabled/%s", finit_rcsd, arg); if (fexist(argpath)) - ERRX(1, "%s already enabled", arg); + ERRX(noerr ? 0 : 1, "%s already enabled", arg); return symlink(path, argpath) != 0; } @@ -308,10 +308,10 @@ int do_disable(char *arg, int check) dbg("Failed changing to %s/enabled/: %s", finit_rcsd, strerror(errno)); if (check && stat(arg, &st)) - ERRX(6, "%s not (an) enabled (service).", arg); + ERRX(noerr ? 0 : 6, "%s not (an) enabled (service).", arg); if (check && (st.st_mode & S_IFMT) == S_IFLNK) - ERRX(1, "cannot disable %s, not a symlink.", arg); + ERRX(noerr ? 0 : 1, "cannot disable %s, not a symlink.", arg); return remove(arg) != 0; }