[master] 21c603de4 mgt_jail_unix: Dedup generation of error messages
Nils Goroll
nils.goroll at uplex.de
Fri Feb 14 08:53:14 UTC 2025
commit 21c603de4009ddfe4187c50ccbb323c8f21496bd
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Fri Feb 14 09:11:16 2025 +0100
mgt_jail_unix: Dedup generation of error messages
Similar case as 9a18ce3bdd6e06ef3b6d654fd36d23e6ebfe3372, but this time for
make_subdir
diff --git a/bin/varnishd/mgt/mgt_jail.c b/bin/varnishd/mgt/mgt_jail.c
index b94e89f0a..e9957a6bb 100644
--- a/bin/varnishd/mgt/mgt_jail.c
+++ b/bin/varnishd/mgt/mgt_jail.c
@@ -200,6 +200,7 @@ VJ_make_subdir(const char *dname, const char *what, struct vsb *vsb)
AN(dname);
AN(what);
+ AN(vsb);
CHECK_OBJ_NOTNULL(vjt, JAIL_TECH_MAGIC);
if (vjt->make_subdir != NULL)
return (vjt->make_subdir(dname, what, vsb));
@@ -207,15 +208,8 @@ VJ_make_subdir(const char *dname, const char *what, struct vsb *vsb)
VJ_master(JAIL_MASTER_FILE);
if (mkdir(dname, 0755) < 0 && errno != EEXIST) {
e = errno;
- if (vsb != NULL) {
- VSB_printf(vsb,
- "Cannot create %s directory '%s': %s\n",
- what, dname, VAS_errtxt(e));
- } else {
- MGT_Complain(C_ERR,
- "Cannot create %s directory '%s': %s",
- what, dname, VAS_errtxt(e));
- }
+ VSB_printf(vsb, "Cannot create %s directory '%s': %s\n",
+ what, dname, VAS_errtxt(e));
return (1);
}
VJ_master(JAIL_MASTER_LOW);
diff --git a/bin/varnishd/mgt/mgt_jail_unix.c b/bin/varnishd/mgt/mgt_jail_unix.c
index 70414c806..01c6f5e02 100644
--- a/bin/varnishd/mgt/mgt_jail_unix.c
+++ b/bin/varnishd/mgt/mgt_jail_unix.c
@@ -239,19 +239,13 @@ vju_make_subdir(const char *dname, const char *what, struct vsb *vsb)
AN(dname);
AN(what);
+ AN(vsb);
AZ(seteuid(0));
if (mkdir(dname, 0755) < 0 && errno != EEXIST) {
e = errno;
- if (vsb != NULL) {
- VSB_printf(vsb,
- "Cannot create %s directory '%s': %s\n",
- what, dname, VAS_errtxt(e));
- } else {
- MGT_Complain(C_ERR,
- "Cannot create %s directory '%s': %s",
- what, dname, VAS_errtxt(e));
- }
+ VSB_printf(vsb, "Cannot create %s directory '%s': %s\n",
+ what, dname, VAS_errtxt(e));
return (1);
}
AZ(chown(dname, vju_uid, vju_gid));
diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c
index 2fbcfccad..47f51ae96 100644
--- a/bin/varnishd/mgt/mgt_main.c
+++ b/bin/varnishd/mgt/mgt_main.c
@@ -640,6 +640,7 @@ main(int argc, char * const *argv)
pid_t pid;
struct arg_list *alp;
int first_arg = 1;
+ struct vsb *vsb;
if (argc == 2 && !strcmp(argv[1], "--optstring")) {
printf("%s\n", opt_spec);
@@ -896,25 +897,17 @@ main(int argc, char * const *argv)
AZ(system("rm -rf vmod_cache vext_cache worker_tmpdir"));
VJ_master(JAIL_MASTER_LOW);
- if (VJ_make_subdir("vmod_cache", "VMOD cache", NULL)) {
- ARGV_ERR(
- "Cannot create vmod directory (%s/vmod_cache): %s\n",
- workdir, VAS_errtxt(errno));
- }
-
- if (arg_list_count("E") &&
- VJ_make_subdir("vext_cache", "VEXT cache", NULL)) {
- ARGV_ERR(
- "Cannot create vmod directory (%s/vext_cache): %s\n",
- workdir, VAS_errtxt(errno));
- }
-
- if (VJ_make_subdir("worker_tmpdir",
- "TMPDIR for the worker process", NULL)) {
- ARGV_ERR(
- "Cannot create vmod directory (%s/worker_tmpdir): %s\n",
- workdir, VAS_errtxt(errno));
- }
+ vsb = VSB_new_auto();
+ AN(vsb);
+ o = VJ_make_subdir("vmod_cache", "VMOD cache", vsb) ||
+ VJ_make_subdir("worker_tmpdir",
+ "TMPDIR for the worker process", vsb) ||
+ (arg_list_count("E") &&
+ VJ_make_subdir("vext_cache", "VEXT cache", vsb));
+ MGT_ComplainVSB(o ? C_ERR : C_INFO, vsb);
+ VSB_destroy(&vsb);
+ if (o)
+ ARGV_EXIT;
o = open("worker_tmpdir", O_RDONLY);
VJ_master(JAIL_MASTER_SYSTEM);
More information about the varnish-commit
mailing list