initctl: use standardized exit codes for all fatal errors

This change diversifies the exit codes used by initctl on fatal errors.
Previously only Std C codes 0 and 1 were used, with the initctl specific
255 for some cases.

Both the LSB init script codes and BSD sysexits.h codes are used.  See
util.c exitcodes[] for the full list.  The idea is to complement the
change in 9a76f08, issue #266, so that initctl can be used silently for
scripting purposes.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2022-05-15 11:32:06 +02:00
parent 4dff8237f1
commit 0e93dfd640
3 changed files with 35 additions and 35 deletions
+4 -4
View File
@@ -243,7 +243,7 @@ static float cgroup_cpuload(struct cg *cg)
snprintf(fn, sizeof(fn), "%s/cpu.stat", cg->cg_path);
fp = fopen(fn, "r");
if (!fp)
ERR(1, "Cannot open %s", fn);
ERR(72, "Cannot open %s", fn);
while (fgets(buf, sizeof(buf), fp)) {
uint64_t curr;
@@ -285,7 +285,7 @@ static struct cg *append(char *path)
cg = calloc(1, sizeof(struct cg));
if (!cg)
ERR(1, "failed allocating struct cg");
ERR(71, "failed allocating struct cg");
cg->cg_path = strdup(path);
if (list)
@@ -295,7 +295,7 @@ static struct cg *append(char *path)
item.key = cg->cg_path;
item.data = cg;
if (!hsearch(item, ENTER))
ERR(1, "failed adding to hash table");
ERR(70, "failed adding to hash table");
return cg;
}
@@ -609,7 +609,7 @@ int show_cgtop(char *arg)
}
if (!hcreate(ttrows + 25))
ERR(1, "failed creating hash table");
ERR(70, "failed creating hash table");
sysinfo(&si);
total_ram = si.totalram * si.mem_unit;