Flexelinting

parent 348e7ba0
......@@ -36,3 +36,6 @@ TESTS = @VMOD_TESTS@
EXTRA_DIST = \
vmod_weightadjust.vcc \
$(VMOD_TESTS)
flint:
flexelint $(VARNISHAPI_CFLAGS) -I .. flint.lnt *.c
-sem(VAS_Fail, r_no)
-e717 // do ... while(1) ...
-e801 // goto
-e506 // const bool
-e793 // sifnificant characters...
-emacro(747, ALLOC_OBJ) // Significant prototype coercion
-efile(766, config.h)
-e763 // XXX TODO Redudant declaration
//vdir.c
-esym(534, VSB_*)
\ No newline at end of file
......@@ -31,7 +31,6 @@
#include <stdlib.h>
#include "cache/cache.h"
#include "cache/cache_director.h"
#include "vbm.h"
#include "vrnd.h"
......@@ -43,8 +42,10 @@
#define vmod_directors_random vmod_weightadjust_random
#define VMOD_DIRECTORS_RANDOM_MAGIC VMOD_WEIGHTADJUST_RANDOM_MAGIC
//lint -e652 override
#define vmod_random__init _vmod_random__init
#define vmod_random__fini _vmod_random__fini
//lint +e652 override
static VCL_BOOL
vmod_random_healthy(VRT_CTX, VCL_BACKEND dir, VCL_TIME *changed)
......@@ -79,7 +80,7 @@ vmod_random_resolve(VRT_CTX, VCL_BACKEND dir)
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(dir, DIRECTOR_MAGIC);
CAST_OBJ_NOTNULL(rr, dir->priv, VMOD_DIRECTORS_RANDOM_MAGIC);
r = scalbn(VRND_RandomTestable(), -31);
r = scalbn((double)VRND_RandomTestable(), -31);
assert(r >= 0 && r < 1.0);
be = vdir_pick_be(ctx, rr->vd, r);
return (be);
......
......@@ -38,7 +38,6 @@
#include "cache/cache.h"
#include "vbm.h"
#include "vcl.h"
#include "vsb.h"
#include "vdir.h"
......@@ -167,8 +166,8 @@ vdir_remove_backend(VRT_CTX, struct vdir *vd, VCL_BACKEND be, unsigned *cur)
VRT_Assign_Backend(&vd->backend[u], NULL);
vd->total_weight -= vd->weight[u];
n = (vd->n_backend - u) - 1;
memmove(&vd->backend[u], &vd->backend[u+1], n * sizeof(vd->backend[0]));
memmove(&vd->weight[u], &vd->weight[u+1], n * sizeof(vd->weight[0]));
memmove(&vd->backend[u], &vd->backend[u]+1, n * sizeof(vd->backend[0]));
memmove(&vd->weight[u], &vd->weight[u]+1, n * sizeof(vd->weight[0]));
vd->n_backend--;
if (cur) {
......@@ -239,7 +238,7 @@ vdir_list(VRT_CTX, struct vdir *vd, struct vsb *vsb, int pflag, int jflag,
be = vd->backend[u];
CHECK_OBJ_NOTNULL(be, DIRECTOR_MAGIC);
h = vbit_test(vd->healthy, u);
h = (typeof(h))vbit_test(vd->healthy, u);
w = h ? vd->weight[u] : 0.0;
......@@ -331,7 +330,7 @@ vdir_update_health(VRT_CTX, struct vdir *vd)
}
if (c > changed)
changed = c;
if (h != vbit_test(healthy, u)) {
if (h != (typeof(h))vbit_test(healthy, u)) {
if (h)
vbit_set(healthy, u);
else
......
......@@ -37,9 +37,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <poll.h>
#include <sys/socket.h>
#include <errno.h>
#include <limits.h>
#include <pcre.h>
......@@ -47,14 +45,8 @@
#include "cache/cache.h"
#include "vcl.h"
#include "vre.h"
#include "vsa.h"
#include "vtim.h"
#include "vtcp.h"
#include "vsb.h"
#include "waiter/waiter.h"
#include "cache/cache_director.h"
#include "cache/cache_backend.h"
#include "vdir.h"
......@@ -93,7 +85,7 @@ priv_vcl_free(VRT_CTX, void *priv)
(void)ctx;
CAST_OBJ_NOTNULL(wa_vcl, priv, VMOD_WADJ_VCL_MAGIC);
AN(VTAILQ_EMPTY(&wa_vcl->props));
assert(VTAILQ_EMPTY(&wa_vcl->props));
AZ(pthread_mutex_destroy(&wa_vcl->mtx));
FREE_OBJ(wa_vcl);
AZ(wa_vcl);
......@@ -115,6 +107,7 @@ vmod_event_function(VRT_CTX, struct vmod_priv *priv, enum vcl_event_e e)
switch (e) {
case VCL_EVENT_LOAD:
ALLOC_OBJ(wa_vcl, VMOD_WADJ_VCL_MAGIC);
AN(wa_vcl);
VTAILQ_INIT(&wa_vcl->props);
AZ(pthread_mutex_init(&wa_vcl->mtx, NULL));
priv->priv = wa_vcl;
......@@ -138,9 +131,9 @@ vmod_event_function(VRT_CTX, struct vmod_priv *priv, enum vcl_event_e e)
/* largely taken from vbp_build_req() */
static char *
wadj_cfg_req(const struct backend *be, VCL_STRING url, VCL_STRING request,
int *len)
ssize_t *len)
{
const int reql = request ? strlen(request) + 1 : 0;
const size_t reql = request ? strlen(request) + 1 : 0;
char s[reql];
char *ret, *tok, *save;
int c = 0;
......@@ -176,10 +169,12 @@ wadj_cfg_req(const struct backend *be, VCL_STRING url, VCL_STRING request,
ret = strdup(VSB_data(vsb));
AN(ret);
*len = VSB_len(vsb);
assert(*len >= 0);
VSB_destroy(&vsb);
return (ret);
}
//lint -e{818} priv
VCL_VOID
vmod_random__init(VRT_CTX, struct vmod_weightadjust_random **rrp,
const char *vcl_name, struct vmod_priv *priv)
......@@ -217,6 +212,7 @@ vmod_random__fini(struct vmod_weightadjust_random **rrp)
AZ(rr);
}
//lint -e{818} args
VCL_VOID
vmod_random_add_backend(VRT_CTX,
struct VPFX(weightadjust_random) *rr,
......@@ -262,6 +258,7 @@ vmod_random_add_backend(VRT_CTX,
}
ALLOC_OBJ(prop, WADJ_PROP_MAGIC);
AN(prop);
AZ(pthread_mutex_init(&prop->wakeup.mtx, NULL));
AZ(pthread_cond_init(&prop->wakeup.cv, NULL));
prop->vd = rr->vd;
......
......@@ -51,8 +51,6 @@
#include "vtcp.h"
#include "vrnd.h"
#include "waiter/waiter.h"
#include "cache/cache_director.h"
#include "cache/cache_backend.h"
#ifdef FIXME
#include "cache/cache_tcp_pool.h"
......@@ -82,11 +80,12 @@ int VCP_Open(struct conn_pool *, vtim_dur tmo, VCL_IP *, int*);
/* largely copied from vbp_poke */
static void
wadj_poke(const struct wadj_prop *prop, char *buf,
unsigned *len)
ssize_t *len)
{
int s, tmo, i, err;
int s, tmo, err;
ssize_t i;
ssize_t rlen;
double t_start, t_now, t_end;
unsigned rlen;
struct pollfd pfda[1], *pfd = pfda;
const struct suckaddr *sa;
// pcre JIT requires 32K anyway, and we are not running when it is
......@@ -117,9 +116,10 @@ wadj_poke(const struct wadj_prop *prop, char *buf,
return;
}
i = write(s, prop->req, prop->reqlen);
assert(prop->reqlen >= 0);
i = write(s, prop->req, (size_t)prop->reqlen);
if (i != prop->reqlen) {
POKE_ERR(prop, "short write (%d out of %d bytes)",
POKE_ERR(prop, "short write (%zd out of %zd bytes)",
i, prop->reqlen);
VTCP_close(&s);
return;
......@@ -132,7 +132,7 @@ wadj_poke(const struct wadj_prop *prop, char *buf,
pfd->revents = 0;
tmo = (int)round((t_end - t_now) * 1e3);
if (tmo > 0)
i = poll(pfd, 1, tmo);
i = poll(pfd, 1UL, tmo);
if (i == 0 || tmo <= 0) {
POKE_ERR(prop, "read timeout after %fs",
VTIM_real() - t_start);
......@@ -140,7 +140,7 @@ wadj_poke(const struct wadj_prop *prop, char *buf,
return;
}
if (rlen < prop->bufsz)
i = read(s, buf + rlen, prop->bufsz - rlen);
i = read(s, buf + rlen, (size_t)(prop->bufsz - rlen));
else
i = read(s, drain, sizeof(drain));
if (i <= 0)
......@@ -155,6 +155,7 @@ wadj_poke(const struct wadj_prop *prop, char *buf,
buf[rlen] = '\0';
else {
assert(rlen == prop->bufsz);
assert(rlen > 0);
buf[--rlen] = '\0';
}
......@@ -179,7 +180,7 @@ wadj_update(void *arg)
char *p, *pp;
AN(pr->bufsz);
char buf[pr->bufsz];
unsigned len;
ssize_t len;
double w;
AN(pr->vd);
......@@ -192,7 +193,7 @@ wadj_update(void *arg)
POKE_TRACE(pr, "starting");
due.tv_sec = (long)VTIM_real();
due.tv_nsec = 1e9 * VRND_RandomTestableDouble();
due.tv_nsec = (typeof(due.tv_nsec))(1e9 * VRND_RandomTestableDouble());
AZ(pthread_mutex_lock(&wa->mtx));
while (pr->run >= STARTING) {
......@@ -201,15 +202,16 @@ wadj_update(void *arg)
if (i == 0 || i == EINTR)
continue;
assert(i == ETIMEDOUT);
due.tv_sec += pr->interval;
due.tv_sec += (typeof(due.tv_sec))pr->interval;
wadj_poke(pr, buf, &len);
if (len == 0)
continue;
assert(len > 0);
assert(len <= pr->bufsz);
// XXX should use VRE_MATCH_NOTBOL|VRE_MATCH_NOTEOL
i = VRE_capture(pr->vre, buf, len, 0 /*here*/, groups, 2, NULL);
i = VRE_capture(pr->vre, buf, (size_t)len, 0 /*here*/, groups,
2UL, NULL);
if (i < 0) {
POKE_ERR(pr, "regular expression error %d", i);
......@@ -221,7 +223,6 @@ wadj_update(void *arg)
"need one caputuring match, got %d", i - 1);
continue;
}
groups[1].e = '\0';
p = (char *)groups[1].b;
errno = 0;
......@@ -268,6 +269,7 @@ static void
wadj_thr_start(struct wadj_prop *prop)
{
pthread_attr_t attr;
size_t sz;
if (prop->run >= STARTING)
return;
......@@ -279,7 +281,9 @@ wadj_thr_start(struct wadj_prop *prop)
}
AZ(pthread_attr_init(&attr));
// 32K JIT + 32K general + buf
AZ(pthread_attr_setstacksize(&attr, 64 * 1024 + prop->bufsz));
assert(prop->bufsz > 0);
sz = 64 * 1024 + (size_t)prop->bufsz;
AZ(pthread_attr_setstacksize(&attr, sz));
prop->run = STARTING;
AZ(pthread_create(&prop->thread, &attr, wadj_update, prop));
......@@ -311,7 +315,7 @@ wadj_thr_stop(struct wadj_prop *prop)
/* wa_vcl->mtx must be held */
void
wadj_thr_ctl(struct vmod_wadj_vcl *wa_vcl,
wadj_thr_ctl(const struct vmod_wadj_vcl *wa_vcl,
struct wadj_prop *prop, enum wadj_thr_action_e action)
{
if (wa_vcl->state == VCL_EVENT_LOAD ||
......@@ -321,13 +325,15 @@ wadj_thr_ctl(struct vmod_wadj_vcl *wa_vcl,
if (prop) {
if (wa_vcl->state == VCL_EVENT_WARM) {
if (action == START || action == DEFAULT)
return wadj_thr_start(prop);
wadj_thr_start(prop);
else
return wadj_thr_stop(prop);
wadj_thr_stop(prop);
return;
}
assert(wa_vcl->state == VCL_EVENT_COLD);
return wadj_thr_stop(prop);
wadj_thr_stop(prop);
return;
}
assert(prop == NULL);
......@@ -379,6 +385,7 @@ wadj_dir_fini(const struct wadj_prop_head *vd_props,
{
struct wadj_prop *prop, *save;
//lint -e{850} loop variable modified
VTAILQ_FOREACH_SAFE(prop, vd_props, list_vd, save) {
VTAILQ_REMOVE(vcl_props, prop, list_vcl);
VRT_Assign_Backend(&prop->dir, NULL);
......
......@@ -56,7 +56,7 @@ struct wadj_prop {
enum run_state_e run;
VCL_REGEX vre;
char *req;
int reqlen;
ssize_t reqlen;
VCL_DURATION timeout;
VCL_DURATION interval;
VCL_INT bufsz;
......@@ -77,7 +77,7 @@ enum wadj_thr_action_e {
DEFAULT
};
void wadj_thr_ctl(struct vmod_wadj_vcl *wa_vcl,
void wadj_thr_ctl(const struct vmod_wadj_vcl *wa_vcl,
struct wadj_prop *prop, enum wadj_thr_action_e action);
void wadj_dir_fini(const struct wadj_prop_head *vd_props,
struct wadj_prop_head *vcl_props);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment