From: phk Date: Wed, 12 Jul 2006 08:56:09 +0000 (+0000) Subject: Fix CLI "config.load" X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3d14eca49a7d38d5ad5af462e0005228a7c9ac0d;p=varnish Fix CLI "config.load" git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@451 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index 26a10857..e531d33c 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -287,7 +287,7 @@ void RES_Error(struct worker *w, struct sess *sp, int error, const char *msg); /* cache_vcl.c */ void RelVCL(struct VCL_conf *vc); struct VCL_conf *GetVCL(void); -int CVCL_Load(const char *fn, const char *name); +int CVCL_Load(const char *fn, const char *name, struct cli *cli); #define VCL_RET_MAC(l,u,b) #define VCL_MET_MAC(l,u,b) void VCL_##l##_method(struct sess *); diff --git a/varnish-cache/bin/varnishd/cache_main.c b/varnish-cache/bin/varnishd/cache_main.c index acdb5ea8..2701d6db 100644 --- a/varnish-cache/bin/varnishd/cache_main.c +++ b/varnish-cache/bin/varnishd/cache_main.c @@ -105,7 +105,7 @@ child_main(void) setbuf(stderr, NULL); printf("Child starts\n"); - CVCL_Load(heritage.vcl_file, "boot"); + CVCL_Load(heritage.vcl_file, "boot", NULL); AZ(pthread_mutex_init(&sessmtx, NULL)); VBE_Init(); VSL_Init(); diff --git a/varnish-cache/bin/varnishd/cache_vcl.c b/varnish-cache/bin/varnishd/cache_vcl.c index c271102a..b1bd2a62 100644 --- a/varnish-cache/bin/varnishd/cache_vcl.c +++ b/varnish-cache/bin/varnishd/cache_vcl.c @@ -58,30 +58,59 @@ RelVCL(struct VCL_conf *vc) /*--------------------------------------------------------------------*/ +static struct vcls * +find_vcls(const char *name) +{ + struct vcls *vcl; + + TAILQ_FOREACH(vcl, &vcl_head, list) + if (!strcmp(vcl->name, name)) + return (vcl); + return (NULL); +} + int -CVCL_Load(const char *fn, const char *name) +CVCL_Load(const char *fn, const char *name, struct cli *cli) { struct vcls *vcl; + vcl = find_vcls(name); + if (vcl != NULL) { + if (cli == NULL) + fprintf(stderr, "Config '%s' already loaded", name); + else + cli_out(cli, "Config '%s' already loaded", name); + return (1); + } + vcl = calloc(sizeof *vcl, 1); assert(vcl != NULL); vcl->dlh = dlopen(fn, RTLD_NOW | RTLD_LOCAL); unlink(fn); if (vcl->dlh == NULL) { - fprintf(stderr, "dlopen(%s): %s\n", fn, dlerror()); + if (cli == NULL) + fprintf(stderr, "dlopen(%s): %s\n", fn, dlerror()); + else + cli_out(cli, "dlopen(%s): %s\n", fn, dlerror()); free(vcl); return (1); } vcl->conf = dlsym(vcl->dlh, "VCL_conf"); if (vcl->conf == NULL) { - fprintf(stderr, "No VCL_conf symbol\n"); + if (cli == NULL) + fprintf(stderr, "No VCL_conf symbol\n"); + else + cli_out(cli, "No VCL_conf symbol\n"); dlclose(vcl->dlh); free(vcl); return (1); } if (vcl->conf->magic != VCL_CONF_MAGIC) { - fprintf(stderr, "Wrong VCL_CONF_MAGIC\n"); + if (cli == NULL) + fprintf(stderr, "Wrong VCL_CONF_MAGIC\n"); + else + cli_out(cli, "Wrong VCL_CONF_MAGIC\n"); dlclose(vcl->dlh); free(vcl); return (1); @@ -93,7 +122,10 @@ CVCL_Load(const char *fn, const char *name) if (active_vcl == NULL) active_vcl = vcl; AZ(pthread_mutex_unlock(&sessmtx)); - fprintf(stderr, "Loaded \"%s\" as \"%s\"\n", fn , name); + if (cli == NULL) + fprintf(stderr, "Loaded \"%s\" as \"%s\"\n", fn , name); + else + cli_out(cli, "Loaded \"%s\" as \"%s\"\n", fn , name); vcl->conf->init_func(); return (0); } @@ -111,57 +143,12 @@ cli_func_config_list(struct cli *cli, char **av __unused, void *priv __unused) } } -static struct vcls * -find_vcls(const char *name) -{ - struct vcls *vcl; - - TAILQ_FOREACH(vcl, &vcl_head, list) - if (!strcmp(vcl->name, name)) - return (vcl); - return (NULL); -} - void cli_func_config_load(struct cli *cli, char **av, void *priv __unused) { - struct vcls *vcl; - vcl = find_vcls(av[2]); - if (vcl != NULL) { - cli_out(cli, "Config '%s' already loaded", av[2]); - cli_result(cli, CLIS_PARAM); - return; - } - vcl = calloc(sizeof *vcl, 1); - assert(vcl != NULL); - - vcl->dlh = dlopen(av[3], RTLD_NOW | RTLD_LOCAL); - if (vcl->dlh == NULL) { - cli_out(cli, "dlopen(%s): %s\n", av[3], dlerror()); + if (CVCL_Load(av[3], av[2], cli)) cli_result(cli, CLIS_PARAM); - free(vcl); - return; - } - vcl->conf = dlsym(vcl->dlh, "VCL_conf"); - if (vcl->conf == NULL) { - cli_out(cli, "No VCL_conf symbol\n"); - cli_result(cli, CLIS_PARAM); - dlclose(vcl->dlh); - free(vcl); - return; - } - if (vcl->conf->magic != VCL_CONF_MAGIC) { - cli_out(cli, "Wrong VCL_CONF_MAGIC\n"); - cli_result(cli, CLIS_PARAM); - dlclose(vcl->dlh); - free(vcl); - return; - } - vcl->name = strdup(av[2]); - assert(vcl->name != NULL); - TAILQ_INSERT_TAIL(&vcl_head, vcl, list); - cli_out(cli, "Loaded \"%s\" from \"%s\"\n", vcl->name , av[3]); return; }