[master] 9a18ce3bd mgt_jail_unix: Dedup generation of error messages

Nils Goroll nils.goroll at uplex.de
Thu Feb 13 20:27:05 UTC 2025


commit 9a18ce3bdd6e06ef3b6d654fd36d23e6ebfe3372
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Thu Feb 13 18:08:14 2025 +0100

    mgt_jail_unix: Dedup generation of error messages
    
    Instead of duplicating the code for "a vsb is present" (which was actually never
    the case) and not so, we always write to a vsb and output it in VJ_make_workdir.

diff --git a/bin/varnishd/mgt/mgt_jail.c b/bin/varnishd/mgt/mgt_jail.c
index 6ba0a8e9a..bc88a8f55 100644
--- a/bin/varnishd/mgt/mgt_jail.c
+++ b/bin/varnishd/mgt/mgt_jail.c
@@ -143,12 +143,20 @@ VJ_subproc(enum jail_subproc_e jse)
 int
 VJ_make_workdir(const char *dname)
 {
+	struct vsb *vsb;
 	int i;
 
 	AN(dname);
 	CHECK_OBJ_NOTNULL(vjt, JAIL_TECH_MAGIC);
+
 	if (vjt->make_workdir != NULL) {
-		i = vjt->make_workdir(dname, NULL, NULL);
+		vsb = VSB_new_auto();
+		AN(vsb);
+		i = vjt->make_workdir(dname, NULL, vsb);
+		AZ(VSB_finish(vsb));
+		if (VSB_len(vsb) > 0)
+			MGT_ComplainVSB(i ? C_ERR : C_INFO, vsb);
+		VSB_destroy(&vsb);
 		if (i)
 			return (i);
 		VJ_master(JAIL_MASTER_FILE);
diff --git a/bin/varnishd/mgt/mgt_jail_linux.c b/bin/varnishd/mgt/mgt_jail_linux.c
index 19889c2d0..b8f136020 100644
--- a/bin/varnishd/mgt/mgt_jail_linux.c
+++ b/bin/varnishd/mgt/mgt_jail_linux.c
@@ -39,7 +39,6 @@
 #include <pwd.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
 #include <unistd.h>
 #include <sys/prctl.h>
 #include <sys/vfs.h>
@@ -87,22 +86,19 @@ vjl_make_workdir(const char *dname, const char *what, struct vsb *vsb)
 {
 	struct statfs info;
 
+	AN(vsb);
 	if (jail_tech_unix.make_workdir(dname, what, vsb) != 0)
 		return (1);
 
 	vjl_master(JAIL_MASTER_FILE);
 	if (statfs(dname, &info) != 0) {
-		if (vsb)
-			VSB_printf(vsb, "Could not stat working directory '%s': %s (%d)\n", dname, VAS_errtxt(errno), errno);
-		else
-			MGT_Complain(C_ERR, "Could not stat working directory '%s': %s (%d)", dname, VAS_errtxt(errno), errno);
+		VSB_printf(vsb, "Could not stat working directory '%s':"
+		    " %s (%d)\n", dname, VAS_errtxt(errno), errno);
 		return (1);
 	}
 	if (info.f_type != TMPFS_MAGIC) {
-		if (vsb != NULL)
-			VSB_printf(vsb, "Working directory not mounted on tmpfs partition\n");
-		else
-			MGT_Complain(C_INFO, "Working directory not mounted on tmpfs partition");
+		VSB_printf(vsb, "Working directory not mounted on"
+		    " tmpfs partition\n");
 	}
 	vjl_master(JAIL_MASTER_LOW);
 	return (0);
diff --git a/bin/varnishd/mgt/mgt_jail_unix.c b/bin/varnishd/mgt/mgt_jail_unix.c
index 18e2fcb0f..70414c806 100644
--- a/bin/varnishd/mgt/mgt_jail_unix.c
+++ b/bin/varnishd/mgt/mgt_jail_unix.c
@@ -265,11 +265,11 @@ vju_make_workdir(const char *dname, const char *what, struct vsb *vsb)
 
 	AN(dname);
 	AZ(what);
-	AZ(vsb);
+	AN(vsb);
 	AZ(seteuid(0));
 
 	if (mkdir(dname, 0755) < 0 && errno != EEXIST) {
-		MGT_Complain(C_ERR, "Cannot create working directory '%s': %s",
+		VSB_printf(vsb, "Cannot create working directory '%s': %s",
 		    dname, VAS_errtxt(errno));
 		return (1);
 	}


More information about the varnish-commit mailing list