[master] 9056935ef mgt_util: simplify MGT_ComplainVSB
Nils Goroll
nils.goroll at uplex.de
Fri Feb 14 08:53:13 UTC 2025
commit 9056935ef6420cc299cc897146c0256385cc3550
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Fri Feb 14 09:22:02 2025 +0100
mgt_util: simplify MGT_ComplainVSB
move VSB_len() check and VSB_finish() to MGT_ComplainVSB because they are needed every time anyway.
Leave the VSB cleared for reuse.
diff --git a/bin/varnishd/mgt/mgt.h b/bin/varnishd/mgt/mgt.h
index bcdc81d70..f868613fc 100644
--- a/bin/varnishd/mgt/mgt.h
+++ b/bin/varnishd/mgt/mgt.h
@@ -219,7 +219,7 @@ char *mgt_HostName(void);
void mgt_ProcTitle(const char *comp);
void mgt_DumpRstVsl(void);
struct vsb *mgt_BuildVident(void);
-void MGT_ComplainVSB(const char *, const struct vsb *vsb);
+void MGT_ComplainVSB(const char *, struct vsb *vsb);
void MGT_Complain(const char *, const char *, ...) v_printflike_(2, 3);
const void *MGT_Pick(const struct choice *, const char *, const char *);
char **MGT_NamedArg(const char *, const char **, const char *);
diff --git a/bin/varnishd/mgt/mgt_jail.c b/bin/varnishd/mgt/mgt_jail.c
index bc88a8f55..b94e89f0a 100644
--- a/bin/varnishd/mgt/mgt_jail.c
+++ b/bin/varnishd/mgt/mgt_jail.c
@@ -153,9 +153,7 @@ VJ_make_workdir(const char *dname)
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);
+ MGT_ComplainVSB(i ? C_ERR : C_INFO, vsb);
VSB_destroy(&vsb);
if (i)
return (i);
diff --git a/bin/varnishd/mgt/mgt_util.c b/bin/varnishd/mgt/mgt_util.c
index 435e60673..7e985d30d 100644
--- a/bin/varnishd/mgt/mgt_util.c
+++ b/bin/varnishd/mgt/mgt_util.c
@@ -144,12 +144,17 @@ const char C_SECURITY[] = "Security:";
const char C_CLI[] = "Cli:";
void
-MGT_ComplainVSB(const char *loud, const struct vsb *vsb)
+MGT_ComplainVSB(const char *loud, struct vsb *vsb)
{
int sf;
- if (loud == C_CLI && !mgt_param.syslog_cli_traffic)
+ if (VSB_len(vsb) == 0 ||
+ (loud == C_CLI && !mgt_param.syslog_cli_traffic)) {
+ VSB_clear(vsb);
return;
+ }
+
+ AZ(VSB_finish(vsb));
if (loud == C_ERR)
sf = LOG_ERR;
@@ -169,6 +174,7 @@ MGT_ComplainVSB(const char *loud, const struct vsb *vsb)
if (!MGT_DO_DEBUG(DBG_VTC_MODE))
syslog(sf, "%s", VSB_data(vsb));
+ VSB_clear(vsb);
}
void
@@ -182,7 +188,6 @@ MGT_Complain(const char *loud, const char *fmt, ...)
va_start(ap, fmt);
VSB_vprintf(vsb, fmt, ap);
va_end(ap);
- AZ(VSB_finish(vsb));
MGT_ComplainVSB(loud, vsb);
VSB_destroy(&vsb);
}
More information about the varnish-commit
mailing list