Skip to content

Commit

Permalink
Swap the VSB_tofile() arguments
Browse files Browse the repository at this point in the history
Automated with Coccinelle, so the semantic patch could be reused in the
vtest project.

Closes varnishcache#3238

Conflicts:
    lib/libvcc/vcc_compile.c
    bin/varnishd/proxy/cache_proxy_proto.c
  • Loading branch information
Dridi authored and andrewwiik committed Apr 1, 2020
1 parent 34d866d commit d0ae65b
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 12 deletions.
4 changes: 2 additions & 2 deletions bin/varnishd/common/common_vsmw.c
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions bin/varnishd/mgt/mgt_cli.c
Expand Up @@ -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();
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion bin/varnishd/proxy/cache_proxy_proto.c
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion bin/varnishtest/vtc_haproxy.c
Expand Up @@ -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));

Expand Down
4 changes: 2 additions & 2 deletions bin/varnishtest/vtc_http.c
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion bin/varnishtest/vtc_process.c
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion bin/varnishtest/vtc_proxy.c
Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion include/vsb.h
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/libvarnish/vsb.c
Expand Up @@ -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;

Expand Down
46 changes: 46 additions & 0 deletions 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)

0 comments on commit d0ae65b

Please sign in to comment.