[master] 20c8aafb2 Swap the VSB_tofile() arguments
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Wed Mar 11 09:28:07 UTC 2020
commit 20c8aafb281ed5693771d65dc4e33e827173946c
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Wed Mar 11 10:14:01 2020 +0100
Swap the VSB_tofile() arguments
Automated with Coccinelle, so the semantic patch could be reused in the
vtest project.
Closes #3238
diff --git a/bin/varnishd/common/common_vsmw.c b/bin/varnishd/common/common_vsmw.c
index 383d90c36..a60efd918 100644
--- a/bin/varnishd/common/common_vsmw.c
+++ b/bin/varnishd/common/common_vsmw.c
@@ -208,7 +208,7 @@ vsmw_append_record(struct vsmw *vsmw, struct vsmwseg *seg, char act)
VSB_clear(vsmw->vsb);
vsmw_fmt_index(vsmw, seg, act);
AZ(VSB_finish(vsmw->vsb));
- XXXAZ(VSB_tofile(fd, vsmw->vsb)); // XXX handle ENOSPC? #2764
+ XXXAZ(VSB_tofile(vsmw->vsb, fd)); // XXX handle ENOSPC? #2764
closefd(&fd);
}
@@ -255,7 +255,7 @@ vsmw_delseg(struct vsmw *vsmw, struct vsmwseg *seg)
VTAILQ_FOREACH(s2, &vsmw->segs, list)
vsmw_fmt_index(vsmw, s2, '+');
AZ(VSB_finish(vsmw->vsb));
- XXXAZ(VSB_tofile(fd, vsmw->vsb)); // XXX handle ENOSPC? #2764
+ XXXAZ(VSB_tofile(vsmw->vsb, fd)); // XXX handle ENOSPC? #2764
closefd(&fd);
AZ(renameat(vsmw->vdirfd, t, vsmw->vdirfd, vsmw->idx));
REPLACE(t, NULL);
diff --git a/bin/varnishd/mgt/mgt_cli.c b/bin/varnishd/mgt/mgt_cli.c
index 8cf182bac..b046d20c7 100644
--- a/bin/varnishd/mgt/mgt_cli.c
+++ b/bin/varnishd/mgt/mgt_cli.c
@@ -147,7 +147,7 @@ mcf_askchild(struct cli *cli, const char * const *av, void *priv)
}
VSB_putc(cli_buf, '\n');
AZ(VSB_finish(cli_buf));
- if (VSB_tofile(cli_o, cli_buf)) {
+ if (VSB_tofile(cli_buf, cli_o)) {
VCLI_SetResult(cli, CLIS_COMMS);
VCLI_Out(cli, "CLI communication error");
MCH_Cli_Fail();
@@ -196,7 +196,7 @@ mgt_cli_askchild(unsigned *status, char **resp, const char *fmt, ...)
AZ(VSB_finish(cli_buf));
i = VSB_len(cli_buf);
assert(i > 0 && VSB_data(cli_buf)[i - 1] == '\n');
- if (VSB_tofile(cli_o, cli_buf)) {
+ if (VSB_tofile(cli_buf, cli_o)) {
*status = CLIS_COMMS;
if (resp != NULL)
*resp = strdup("CLI communication error");
diff --git a/bin/varnishtest/vtc_haproxy.c b/bin/varnishtest/vtc_haproxy.c
index 80fb8b827..c650f81b5 100644
--- a/bin/varnishtest/vtc_haproxy.c
+++ b/bin/varnishtest/vtc_haproxy.c
@@ -229,7 +229,7 @@ cmd_haproxy_cli_send(CMD_ARGS)
}
vtc_dump(hc->vl, 4, "CLI send", VSB_data(vsb), -1);
- if (VSB_tofile(hc->sock, vsb))
+ if (VSB_tofile(vsb, hc->sock))
vtc_fatal(hc->vl,
"CLI fd %d send error %s", hc->sock, strerror(errno));
diff --git a/bin/varnishtest/vtc_http.c b/bin/varnishtest/vtc_http.c
index 85441f25f..b122aa343 100644
--- a/bin/varnishtest/vtc_http.c
+++ b/bin/varnishtest/vtc_http.c
@@ -217,7 +217,7 @@ http_write(const struct http *hp, int lvl, const char *pfx)
AZ(VSB_finish(hp->vsb));
vtc_dump(hp->vl, lvl, pfx, VSB_data(hp->vsb), VSB_len(hp->vsb));
- if (VSB_tofile(hp->fd, hp->vsb))
+ if (VSB_tofile(hp->vsb, hp->fd))
vtc_log(hp->vl, hp->fatal, "Write failed: %s",
strerror(errno));
}
@@ -1381,7 +1381,7 @@ cmd_http_sendhex(CMD_ARGS)
vsb = vtc_hex_to_bin(hp->vl, av[1]);
assert(VSB_len(vsb) >= 0);
vtc_hexdump(hp->vl, 4, "sendhex", VSB_data(vsb), VSB_len(vsb));
- if (VSB_tofile(hp->fd, vsb))
+ if (VSB_tofile(vsb, hp->fd))
vtc_log(hp->vl, hp->fatal, "Write failed: %s",
strerror(errno));
VSB_destroy(&vsb);
diff --git a/bin/varnishtest/vtc_process.c b/bin/varnishtest/vtc_process.c
index 99c68cc0c..24f7bab0b 100644
--- a/bin/varnishtest/vtc_process.c
+++ b/bin/varnishtest/vtc_process.c
@@ -803,7 +803,7 @@ process_write_hex(const struct process *p, const char *text)
vsb = vtc_hex_to_bin(p->vl, text);
assert(VSB_len(vsb) >= 0);
vtc_hexdump(p->vl, 4, "sendhex", VSB_data(vsb), VSB_len(vsb));
- AZ(VSB_tofile(p->fd_term, vsb));
+ AZ(VSB_tofile(vsb, p->fd_term));
VSB_destroy(&vsb);
}
diff --git a/bin/varnishtest/vtc_proxy.c b/bin/varnishtest/vtc_proxy.c
index 7a3fd7ac7..1bee39657 100644
--- a/bin/varnishtest/vtc_proxy.c
+++ b/bin/varnishtest/vtc_proxy.c
@@ -128,7 +128,7 @@ vtc_send_proxy(int fd, int version, const struct suckaddr *sac,
WRONG("Wrong proxy version");
AZ(VSB_finish(vsb));
- i = VSB_tofile(fd, vsb);
+ i = VSB_tofile(vsb, fd);
VSB_delete(vsb);
return (i);
}
diff --git a/include/vsb.h b/include/vsb.h
index a8fe4f6e5..b4305e42a 100644
--- a/include/vsb.h
+++ b/include/vsb.h
@@ -89,7 +89,7 @@ void VSB_quote_pfx(struct vsb *, const char*, const void *,
int len, int how);
void VSB_quote(struct vsb *, const void *, int len, int how);
void VSB_indent(struct vsb *, int);
-int VSB_tofile(int fd, const struct vsb *);
+int VSB_tofile(const struct vsb *, int fd);
#ifdef __cplusplus
};
#endif
diff --git a/lib/libvarnish/vsb.c b/lib/libvarnish/vsb.c
index e0b48c50e..4c4570c7b 100644
--- a/lib/libvarnish/vsb.c
+++ b/lib/libvarnish/vsb.c
@@ -658,7 +658,7 @@ VSB_indent(struct vsb *s, int i)
}
int
-VSB_tofile(int fd, const struct vsb *s)
+VSB_tofile(const struct vsb *s, int fd)
{
int sz;
diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c
index 1be668bfd..87c6614e9 100644
--- a/lib/libvcc/vcc_compile.c
+++ b/lib/libvcc/vcc_compile.c
@@ -110,7 +110,7 @@ TLWriteVSB(struct vcc *tl, const char *fn, const struct vsb *vsb,
what, fn, strerror(errno));
return (-1);
}
- i = VSB_tofile(fo, vsb);
+ i = VSB_tofile(vsb, fo);
if (i) {
VSB_printf(tl->sb,
"Could not write %s to %s: %s\n",
diff --git a/tools/coccinelle/vsb_tofile.cocci b/tools/coccinelle/vsb_tofile.cocci
new file mode 100644
index 000000000..b8ca8254d
--- /dev/null
+++ b/tools/coccinelle/vsb_tofile.cocci
@@ -0,0 +1,46 @@
+/*
+ * This patch fixes the order of VSB_tofile arguments.
+ */
+
+@@
+idexpression struct vsb *vsb;
+idexpression int fd;
+@@
+
+- VSB_tofile(fd, vsb)
++ VSB_tofile(vsb, fd)
+
+@@
+idexpression struct vsb[] vsb;
+idexpression int fd;
+@@
+
+- VSB_tofile(fd, vsb)
++ VSB_tofile(vsb, fd)
+
+@@
+idexpression struct vsb *vsb;
+expression fd;
+@@
+
+- VSB_tofile(fd, vsb)
++ VSB_tofile(vsb, fd)
+
+/* Opportunistic fallback */
+
+@@
+idexpression int fd;
+expression vsb;
+@@
+
+- VSB_tofile(fd, vsb)
++ VSB_tofile(vsb, fd)
+
+/* Opportunistic last resort */
+
+@@
+expression fd, other;
+@@
+
+- VSB_tofile(fd, other->vsb)
++ VSB_tofile(other->vsb, fd)
More information about the varnish-commit
mailing list