Unverified Commit 506c452a authored by Martin Blix Grydeland's avatar Martin Blix Grydeland Committed by Nils Goroll

Make mgt_has_vcl() return an error string

mgt_has_vcl() now returns an error string describing why it doesn't have a
valid VCL.

This is taken from #3711 by @bsdphk
parent 9228395e
......@@ -231,7 +231,7 @@ void mgt_vcl_init(void);
void mgt_vcl_startup(struct cli *, const char *vclsrc, const char *origin,
const char *vclname, int Cflag);
int mgt_push_vcls(struct cli *, unsigned *status, char **p);
int mgt_has_vcl(void);
const char *mgt_has_vcl(void);
extern char *mgt_cc_cmd;
extern const char *mgt_vcl_path;
extern const char *mgt_vmod_path;
......
......@@ -707,15 +707,17 @@ mch_pid_json(struct cli *cli, const char * const *av, void *priv)
static void v_matchproto_(cli_func_t)
mch_cli_server_start(struct cli *cli, const char * const *av, void *priv)
{
const char *err;
(void)av;
(void)priv;
if (child_state == CH_STOPPED) {
if (mgt_has_vcl()) {
err = mgt_has_vcl();
if (err == NULL) {
mgt_launch_child(cli);
} else {
VCLI_SetResult(cli, CLIS_CANT);
VCLI_Out(cli, "No VCL available");
VCLI_Out(cli, "%s", err);
}
} else {
VCLI_SetResult(cli, CLIS_CANT);
......
......@@ -483,6 +483,7 @@ main(int argc, char * const *argv)
char *p;
struct cli cli[1];
char **av;
const char *err;
unsigned u;
struct sigaction sac;
struct vev *e;
......@@ -909,10 +910,11 @@ main(int argc, char * const *argv)
}
assert(I_fd == -1);
if (!d_flag && !mgt_has_vcl() && !novcl)
MGT_Complain(C_ERR, "No VCL loaded yet");
err = mgt_has_vcl();
if (!d_flag && err != NULL && !novcl)
MGT_Complain(C_ERR, "%s", err);
if (mgt_has_vcl() && ! d_flag)
if (err == NULL && !d_flag)
u = MCH_Start_Child();
else
u = 0;
......
......@@ -281,11 +281,16 @@ mgt_vcl_del(struct vclprog *vp)
FREE_OBJ(vp);
}
int
const char *
mgt_has_vcl(void)
{
return (!VTAILQ_EMPTY(&vclhead));
if (VTAILQ_EMPTY(&vclhead))
return ("No VCL loaded");
if (mgt_vcl_active == NULL)
return ("No active VCL");
CHECK_OBJ_NOTNULL(mgt_vcl_active, VCLPROG_MAGIC);
AN(mgt_vcl_active->warm);
return (NULL);
}
/*
......
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