Commit 83d642bb authored by Poul-Henning Kamp's avatar Poul-Henning Kamp Committed by Lasse Karstensen

Sanitize the VFIL_searchpath() caling convention to not need throwing

away const.
parent d1d86be7
......@@ -282,12 +282,13 @@ mcf_vcl_load(struct cli *cli, const char * const *av, void *priv)
}
VFIL_setpath(&vcl_path, mgt_vcl_dir);
fn = TRUST_ME(av[3]);
if (VFIL_searchpath(vcl_path, NULL, &vcl, &fn)) {
if (VFIL_searchpath(vcl_path, NULL, &vcl, av[3], &fn)) {
VCLI_Out(cli, "Cannot open '%s'", fn != NULL ? fn : av[3]);
REPLACE(fn, NULL);
VCLI_SetResult(cli, CLIS_PARAM);
return;
}
REPLACE(fn, NULL);
mgt_new_vcl(cli, av[2], vcl, av[4], 0);
free(vcl);
......
......@@ -39,5 +39,5 @@ int VFIL_allocate(int fd, off_t size, int insist);
void VFIL_setpath(struct vfil_path**, const char *path);
typedef int vfil_path_func_f(void *priv, const char *fn);
int VFIL_searchpath(const struct vfil_path *, vfil_path_func_f *func,
void *priv, char **fn);
void *priv, const char *fni, char **fno);
......@@ -298,41 +298,38 @@ vfil_path_openfile(void *priv, const char *fn)
int
VFIL_searchpath(const struct vfil_path *vp, vfil_path_func_f *func, void *priv,
char **fnp)
const char *fni, char **fno)
{
struct vsb *vsb;
struct vfil_dir *vd;
const char *fn;
int i, e;
CHECK_OBJ_NOTNULL(vp, VFIL_PATH_MAGIC);
AN(fnp);
AN(*fnp);
fn = *fnp;
*fnp = NULL;
AN(fno);
*fno = NULL;
if (func == NULL) {
func = vfil_path_openfile;
AN(priv);
}
if (*fn == '/') {
i = func(priv, fn);
if (*fni == '/') {
i = func(priv, fni);
if (i <= 0)
REPLACE(*fnp, fn);
REPLACE(*fno, fni);
return (i);
}
vsb = VSB_new_auto();
AN(vsb);
VTAILQ_FOREACH(vd, &vp->paths, list) {
VSB_clear(vsb);
VSB_printf(vsb, "%s/%s", vd->dir, fn);
VSB_printf(vsb, "%s/%s", vd->dir, fni);
AZ(VSB_finish(vsb));
i = func(priv, VSB_data(vsb));
if (i <= 0) {
e = errno;
*fnp = strdup(VSB_data(vsb));
AN(*fnp);
*fno = strdup(VSB_data(vsb));
AN(*fno);
VSB_delete(vsb);
errno = e;
return (i);
......
......@@ -450,7 +450,7 @@ vcc_destroy_source(struct source *sp)
/*--------------------------------------------------------------------*/
static struct source *
vcc_file_source(const struct vcp * const vcp, struct vsb *sb, char *fn)
vcc_file_source(const struct vcp * const vcp, struct vsb *sb, const char *fn)
{
char *f, *fnp;
struct source *sp;
......@@ -460,8 +460,7 @@ vcc_file_source(const struct vcp * const vcp, struct vsb *sb, char *fn)
return (NULL);
}
f = NULL;
fnp = fn;
if (VFIL_searchpath(vcp->vcl_path, NULL, &f, &fnp) || f == NULL) {
if (VFIL_searchpath(vcp->vcl_path, NULL, &f, fn, &fnp) || f == NULL) {
VSB_printf(sb, "Cannot read file '%s' (%s)\n",
fnp != NULL ? fnp : fn, strerror(errno));
return (NULL);
......
......@@ -49,7 +49,6 @@ vcc_path_dlopen(void *priv, const char *fn)
AN(priv);
AN(fn);
fprintf(stderr, "TRY <%s>\n", fn);
hdl = dlopen(fn, RTLD_NOW | RTLD_LOCAL);
if (hdl == NULL)
return (1);
......@@ -126,9 +125,8 @@ vcc_ParseImport(struct vcc *tl)
SkipToken(tl, ';');
fnp = fn;
if (VFIL_searchpath(tl->param->vmod_path,
vcc_path_dlopen, &hdl, &fnp)) {
vcc_path_dlopen, &hdl, fn, &fnp)) {
VSB_printf(tl->sb, "Could not load VMOD %.*s\n", PF(mod));
VSB_printf(tl->sb, "\tFile name: %s\n", fnp != NULL ? fnp : fn);
VSB_printf(tl->sb, "\tdlerror: %s\n", dlerror());
......
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