Mailing List Archive

[6.0] e54544b0c Swap the VSB_tofile() arguments
commit e54544b0c341b2cfb86bd5c911e04dabbb505f19
Author: Dridi Boukelmoune <dridi.boukelmoune@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

Conflicts:
lib/libvcc/vcc_compile.c
bin/varnishd/proxy/cache_proxy_proto.c

diff --git a/bin/varnishd/common/common_vsmw.c b/bin/varnishd/common/common_vsmw.c
index dcf83dbd3..dcc85fc22 100644
--- a/bin/varnishd/common/common_vsmw.c
+++ b/bin/varnishd/common/common_vsmw.c
@@ -206,7 +206,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);
}

@@ -253,7 +253,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 8db75e33b..6f4c2accd 100644
--- a/bin/varnishd/mgt/mgt_cli.c
+++ b/bin/varnishd/mgt/mgt_cli.c
@@ -144,7 +144,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();
@@ -193,7 +193,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/varnishd/proxy/cache_proxy_proto.c b/bin/varnishd/proxy/cache_proxy_proto.c
index ddcc8db77..64935686d 100644
--- a/bin/varnishd/proxy/cache_proxy_proto.c
+++ b/bin/varnishd/proxy/cache_proxy_proto.c
@@ -667,7 +667,7 @@ VPX_Send_Proxy(int fd, int version, const struct sess *sp)
WRONG("Wrong proxy version");

AZ(VSB_finish(vsb));
- (void)VSB_tofile(fd, vsb); // XXX: Error handling ?
+ (void)VSB_tofile(vsb, fd); // XXX: Error handling ?
if (!DO_DEBUG(DBG_PROTOCOL)) {
VSB_delete(vsb);
return;
diff --git a/bin/varnishtest/vtc_haproxy.c b/bin/varnishtest/vtc_haproxy.c
index d6565b834..04590596e 100644
--- a/bin/varnishtest/vtc_haproxy.c
+++ b/bin/varnishtest/vtc_haproxy.c
@@ -173,7 +173,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 20969c27a..da4747872 100644
--- a/bin/varnishtest/vtc_http.c
+++ b/bin/varnishtest/vtc_http.c
@@ -216,7 +216,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));
}
@@ -1424,7 +1424,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 ae98f53e1..b2e0e2659 100644
--- a/bin/varnishtest/vtc_process.c
+++ b/bin/varnishtest/vtc_process.c
@@ -793,7 +793,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 4477ab056..a72221573 100644
--- a/bin/varnishtest/vtc_proxy.c
+++ b/bin/varnishtest/vtc_proxy.c
@@ -126,7 +126,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 10e4c9563..086ace255 100644
--- a/include/vsb.h
+++ b/include/vsb.h
@@ -85,7 +85,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 e6519e98c..3c641730e 100644
--- a/lib/libvarnish/vsb.c
+++ b/lib/libvarnish/vsb.c
@@ -626,7 +626,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/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)
_______________________________________________
varnish-commit mailing list
varnish-commit@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit