CLEANUP: cli: rename the last few "stats_" to "cli_"

There were still a very small list of functions, variables and fields
called "stats_" while they were really purely CLI-centric. There's the
frontend called "stats_fe" in the global section, which instantiates a
"cli_applet" called "<CLI>" so it was renamed "cli_fe".

The "alloc_stats_fe" function cas renamed to "cli_alloc_fe" which also
better matches the naming convention of all cli-specific functions.

Finally the "stats_permission_denied_msg" used to return an error on
the CLI was renamed "cli_permission_denied_msg".

Now there's no more "stats_something" that designates the CLI.
This commit is contained in:
Willy Tarreau 2021-03-13 11:00:33 +01:00
parent f14c7570d6
commit 4975d1482f
4 changed files with 51 additions and 51 deletions

View File

@ -156,7 +156,7 @@ struct global {
mode_t mode; /* 0 to leave unchanged */ mode_t mode; /* 0 to leave unchanged */
} ux; } ux;
} unix_bind; } unix_bind;
struct proxy *stats_fe; /* the frontend holding the stats settings */ struct proxy *cli_fe; /* the frontend holding the stats settings */
#ifdef USE_CPU_AFFINITY #ifdef USE_CPU_AFFINITY
struct { struct {
unsigned long proc[MAX_PROCS]; /* list of CPU masks for the 32/64 first processes */ unsigned long proc[MAX_PROCS]; /* list of CPU masks for the 32/64 first processes */

View File

@ -145,7 +145,7 @@ int str2listener(char *str, struct proxy *curproxy, struct bind_conf *bind_conf,
} }
ss2 = str2sa_range(str, NULL, &port, &end, &fd, &proto, err, ss2 = str2sa_range(str, NULL, &port, &end, &fd, &proto, err,
curproxy == global.stats_fe ? NULL : global.unix_bind.prefix, curproxy == global.cli_fe ? NULL : global.unix_bind.prefix,
NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_MAND | PA_O_PORT_RANGE | NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_MAND | PA_O_PORT_RANGE |
PA_O_SOCKET_FD | PA_O_STREAM | PA_O_XPRT); PA_O_SOCKET_FD | PA_O_STREAM | PA_O_XPRT);
if (!ss2) if (!ss2)
@ -206,7 +206,7 @@ int str2receiver(char *str, struct proxy *curproxy, struct bind_conf *bind_conf,
} }
ss2 = str2sa_range(str, NULL, &port, &end, &fd, &proto, err, ss2 = str2sa_range(str, NULL, &port, &end, &fd, &proto, err,
curproxy == global.stats_fe ? NULL : global.unix_bind.prefix, curproxy == global.cli_fe ? NULL : global.unix_bind.prefix,
NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_MAND | PA_O_PORT_RANGE | NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_MAND | PA_O_PORT_RANGE |
PA_O_SOCKET_FD | PA_O_DGRAM | PA_O_XPRT); PA_O_SOCKET_FD | PA_O_DGRAM | PA_O_XPRT);
if (!ss2) if (!ss2)
@ -2132,7 +2132,7 @@ int check_config_validity()
break; break;
} }
if (curproxy != global.stats_fe && (curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->conf.listeners)) { if (curproxy != global.cli_fe && (curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->conf.listeners)) {
ha_warning("config : %s '%s' has no 'bind' directive. Please declare it as a backend if this was intended.\n", ha_warning("config : %s '%s' has no 'bind' directive. Please declare it as a backend if this was intended.\n",
proxy_type_str(curproxy), curproxy->id); proxy_type_str(curproxy), curproxy->id);
err_code |= ERR_WARN; err_code |= ERR_WARN;
@ -3338,18 +3338,18 @@ int check_config_validity()
/* Check multi-process mode compatibility */ /* Check multi-process mode compatibility */
if (global.nbproc > 1 && global.stats_fe) { if (global.nbproc > 1 && global.cli_fe) {
list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { list_for_each_entry(bind_conf, &global.cli_fe->conf.bind, by_fe) {
unsigned long mask; unsigned long mask;
mask = proc_mask(global.stats_fe->bind_proc) && all_proc_mask; mask = proc_mask(global.cli_fe->bind_proc) && all_proc_mask;
mask &= proc_mask(bind_conf->settings.bind_proc); mask &= proc_mask(bind_conf->settings.bind_proc);
/* stop here if more than one process is used */ /* stop here if more than one process is used */
if (atleast2(mask)) if (atleast2(mask))
break; break;
} }
if (&bind_conf->by_fe != &global.stats_fe->conf.bind) { if (&bind_conf->by_fe != &global.cli_fe->conf.bind) {
ha_warning("stats socket will not work as expected in multi-process mode (nbproc > 1), you should force process binding globally using 'stats bind-process' or per socket using the 'process' attribute.\n"); ha_warning("stats socket will not work as expected in multi-process mode (nbproc > 1), you should force process binding globally using 'stats bind-process' or per socket using the 'process' attribute.\n");
} }
} }
@ -3368,14 +3368,14 @@ int check_config_validity()
curproxy->bind_proc = proc_mask(curproxy->bind_proc); curproxy->bind_proc = proc_mask(curproxy->bind_proc);
} }
if (global.stats_fe) { if (global.cli_fe) {
list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { list_for_each_entry(bind_conf, &global.cli_fe->conf.bind, by_fe) {
unsigned long mask; unsigned long mask;
mask = bind_conf->settings.bind_proc ? bind_conf->settings.bind_proc : 0; mask = bind_conf->settings.bind_proc ? bind_conf->settings.bind_proc : 0;
global.stats_fe->bind_proc |= mask; global.cli_fe->bind_proc |= mask;
} }
global.stats_fe->bind_proc = proc_mask(global.stats_fe->bind_proc); global.cli_fe->bind_proc = proc_mask(global.cli_fe->bind_proc);
} }
/* propagate bindings from frontends to backends. Don't do it if there /* propagate bindings from frontends to backends. Don't do it if there

View File

@ -68,7 +68,7 @@
static struct applet cli_applet; static struct applet cli_applet;
static struct applet mcli_applet; static struct applet mcli_applet;
static const char stats_permission_denied_msg[] = static const char cli_permission_denied_msg[] =
"Permission denied\n" "Permission denied\n"
""; "";
@ -331,7 +331,7 @@ void cli_register_kw(struct cli_kw_list *kw_list)
/* allocate a new stats frontend named <name>, and return it /* allocate a new stats frontend named <name>, and return it
* (or NULL in case of lack of memory). * (or NULL in case of lack of memory).
*/ */
static struct proxy *alloc_stats_fe(const char *name, const char *file, int line) static struct proxy *cli_alloc_fe(const char *name, const char *file, int line)
{ {
struct proxy *fe; struct proxy *fe;
@ -364,9 +364,9 @@ static struct proxy *alloc_stats_fe(const char *name, const char *file, int line
* '\n' must not be written. The function must be called with <args> pointing to * '\n' must not be written. The function must be called with <args> pointing to
* the first word after "stats". * the first word after "stats".
*/ */
static int stats_parse_global(char **args, int section_type, struct proxy *curpx, static int cli_parse_global(char **args, int section_type, struct proxy *curpx,
const struct proxy *defpx, const char *file, int line, const struct proxy *defpx, const char *file, int line,
char **err) char **err)
{ {
struct bind_conf *bind_conf; struct bind_conf *bind_conf;
struct listener *l; struct listener *l;
@ -379,18 +379,18 @@ static int stats_parse_global(char **args, int section_type, struct proxy *curpx
return -1; return -1;
} }
if (!global.stats_fe) { if (!global.cli_fe) {
if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { if ((global.cli_fe = cli_alloc_fe("GLOBAL", file, line)) == NULL) {
memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]);
return -1; return -1;
} }
} }
bind_conf = bind_conf_alloc(global.stats_fe, file, line, args[2], xprt_get(XPRT_RAW)); bind_conf = bind_conf_alloc(global.cli_fe, file, line, args[2], xprt_get(XPRT_RAW));
bind_conf->level &= ~ACCESS_LVL_MASK; bind_conf->level &= ~ACCESS_LVL_MASK;
bind_conf->level |= ACCESS_LVL_OPER; /* default access level */ bind_conf->level |= ACCESS_LVL_OPER; /* default access level */
if (!str2listener(args[2], global.stats_fe, bind_conf, file, line, err)) { if (!str2listener(args[2], global.cli_fe, bind_conf, file, line, err)) {
memprintf(err, "parsing [%s:%d] : '%s %s' : %s\n", memprintf(err, "parsing [%s:%d] : '%s %s' : %s\n",
file, line, args[0], args[1], err && *err ? *err : "error"); file, line, args[0], args[1], err && *err ? *err : "error");
return -1; return -1;
@ -409,7 +409,7 @@ static int stats_parse_global(char **args, int section_type, struct proxy *curpx
return -1; return -1;
} }
if (kw->parse(args, cur_arg, global.stats_fe, bind_conf, err) != 0) { if (kw->parse(args, cur_arg, global.cli_fe, bind_conf, err) != 0) {
if (err && *err) if (err && *err)
memprintf(err, "'%s %s' : '%s'", args[0], args[1], *err); memprintf(err, "'%s %s' : '%s'", args[0], args[1], *err);
else else
@ -434,7 +434,7 @@ static int stats_parse_global(char **args, int section_type, struct proxy *curpx
list_for_each_entry(l, &bind_conf->listeners, by_bind) { list_for_each_entry(l, &bind_conf->listeners, by_bind) {
l->accept = session_accept_fd; l->accept = session_accept_fd;
l->default_target = global.stats_fe->default_target; l->default_target = global.cli_fe->default_target;
l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */
l->nice = -64; /* we want to boost priority for local stats */ l->nice = -64; /* we want to boost priority for local stats */
global.maxsock++; /* for the listening socket */ global.maxsock++; /* for the listening socket */
@ -463,13 +463,13 @@ static int stats_parse_global(char **args, int section_type, struct proxy *curpx
memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); memprintf(err, "'%s %s' expects a positive value", args[0], args[1]);
return -1; return -1;
} }
if (!global.stats_fe) { if (!global.cli_fe) {
if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { if ((global.cli_fe = cli_alloc_fe("GLOBAL", file, line)) == NULL) {
memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]);
return -1; return -1;
} }
} }
global.stats_fe->timeout.client = MS_TO_TICKS(timeout); global.cli_fe->timeout.client = MS_TO_TICKS(timeout);
} }
else if (strcmp(args[1], "maxconn") == 0) { else if (strcmp(args[1], "maxconn") == 0) {
int maxconn = atol(args[2]); int maxconn = atol(args[2]);
@ -479,20 +479,20 @@ static int stats_parse_global(char **args, int section_type, struct proxy *curpx
return -1; return -1;
} }
if (!global.stats_fe) { if (!global.cli_fe) {
if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { if ((global.cli_fe = cli_alloc_fe("GLOBAL", file, line)) == NULL) {
memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]);
return -1; return -1;
} }
} }
global.stats_fe->maxconn = maxconn; global.cli_fe->maxconn = maxconn;
} }
else if (strcmp(args[1], "bind-process") == 0) { /* enable the socket only on some processes */ else if (strcmp(args[1], "bind-process") == 0) { /* enable the socket only on some processes */
int cur_arg = 2; int cur_arg = 2;
unsigned long set = 0; unsigned long set = 0;
if (!global.stats_fe) { if (!global.cli_fe) {
if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { if ((global.cli_fe = cli_alloc_fe("GLOBAL", file, line)) == NULL) {
memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]);
return -1; return -1;
} }
@ -509,7 +509,7 @@ static int stats_parse_global(char **args, int section_type, struct proxy *curpx
} }
cur_arg++; cur_arg++;
} }
global.stats_fe->bind_proc = set; global.cli_fe->bind_proc = set;
} }
else { else {
memprintf(err, "'%s' only supports 'socket', 'maxconn', 'bind-process' and 'timeout' (got '%s')", args[0], args[1]); memprintf(err, "'%s' only supports 'socket', 'maxconn', 'bind-process' and 'timeout' (got '%s')", args[0], args[1]);
@ -573,7 +573,7 @@ int listeners_setenv(struct proxy *frontend, const char *varname)
int cli_socket_setenv() int cli_socket_setenv()
{ {
if (listeners_setenv(global.stats_fe, "HAPROXY_CLI") < 0) if (listeners_setenv(global.cli_fe, "HAPROXY_CLI") < 0)
return -1; return -1;
if (listeners_setenv(mworker_proxy, "HAPROXY_MASTER_CLI") < 0) if (listeners_setenv(mworker_proxy, "HAPROXY_MASTER_CLI") < 0)
return -1; return -1;
@ -592,7 +592,7 @@ int cli_has_level(struct appctx *appctx, int level)
{ {
if ((appctx->cli_level & ACCESS_LVL_MASK) < level) { if ((appctx->cli_level & ACCESS_LVL_MASK) < level) {
cli_err(appctx, stats_permission_denied_msg); cli_err(appctx, cli_permission_denied_msg);
return 0; return 0;
} }
return 1; return 1;
@ -1419,8 +1419,8 @@ static int cli_io_handler_show_cli_sock(struct appctx *appctx)
/* fall through */ /* fall through */
case STAT_ST_LIST: case STAT_ST_LIST:
if (global.stats_fe) { if (global.cli_fe) {
list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { list_for_each_entry(bind_conf, &global.cli_fe->conf.bind, by_fe) {
struct listener *l; struct listener *l;
/* /*
@ -1429,7 +1429,7 @@ static int cli_io_handler_show_cli_sock(struct appctx *appctx)
*/ */
if (appctx->ctx.cli.p0 && if (appctx->ctx.cli.p0 &&
&bind_conf->by_fe == (&global.stats_fe->conf.bind)->n) { &bind_conf->by_fe == (&global.cli_fe->conf.bind)->n) {
/* change the current node to the latest dumped and continue the loop */ /* change the current node to the latest dumped and continue the loop */
bind_conf = LIST_ELEM(appctx->ctx.cli.p0, typeof(bind_conf), by_fe); bind_conf = LIST_ELEM(appctx->ctx.cli.p0, typeof(bind_conf), by_fe);
continue; continue;
@ -2769,7 +2769,7 @@ int mworker_cli_proxy_new_listener(char *line)
goto err; goto err;
} }
if (kw->parse(args, cur_arg, global.stats_fe, bind_conf, &err) != 0) { if (kw->parse(args, cur_arg, global.cli_fe, bind_conf, &err) != 0) {
if (err) if (err)
memprintf(&err, "'%s %s' : '%s'", args[0], args[1], err); memprintf(&err, "'%s %s' : '%s'", args[0], args[1], err);
else else
@ -2832,14 +2832,14 @@ int mworker_cli_sockpair_new(struct mworker_proc *mworker_proc, int proc)
} }
/* XXX: we might want to use a separate frontend at some point */ /* XXX: we might want to use a separate frontend at some point */
if (!global.stats_fe) { if (!global.cli_fe) {
if ((global.stats_fe = alloc_stats_fe("GLOBAL", "master-socket", 0)) == NULL) { if ((global.cli_fe = cli_alloc_fe("GLOBAL", "master-socket", 0)) == NULL) {
ha_alert("out of memory trying to allocate the stats frontend"); ha_alert("out of memory trying to allocate the stats frontend");
goto error; goto error;
} }
} }
bind_conf = bind_conf_alloc(global.stats_fe, "master-socket", 0, "", xprt_get(XPRT_RAW)); bind_conf = bind_conf_alloc(global.cli_fe, "master-socket", 0, "", xprt_get(XPRT_RAW));
if (!bind_conf) if (!bind_conf)
goto error; goto error;
@ -2847,14 +2847,14 @@ int mworker_cli_sockpair_new(struct mworker_proc *mworker_proc, int proc)
bind_conf->level |= ACCESS_LVL_ADMIN; /* TODO: need to lower the rights with a CLI keyword*/ bind_conf->level |= ACCESS_LVL_ADMIN; /* TODO: need to lower the rights with a CLI keyword*/
bind_conf->settings.bind_proc = 1UL << proc; bind_conf->settings.bind_proc = 1UL << proc;
global.stats_fe->bind_proc = 0; /* XXX: we should be careful with that, it can be removed by configuration */ global.cli_fe->bind_proc = 0; /* XXX: we should be careful with that, it can be removed by configuration */
if (!memprintf(&path, "sockpair@%d", mworker_proc->ipc_fd[1])) { if (!memprintf(&path, "sockpair@%d", mworker_proc->ipc_fd[1])) {
ha_alert("Cannot allocate listener.\n"); ha_alert("Cannot allocate listener.\n");
goto error; goto error;
} }
if (!str2listener(path, global.stats_fe, bind_conf, "master-socket", 0, &err)) { if (!str2listener(path, global.cli_fe, bind_conf, "master-socket", 0, &err)) {
free(path); free(path);
ha_alert("Cannot create a CLI sockpair listener for process #%d\n", proc); ha_alert("Cannot create a CLI sockpair listener for process #%d\n", proc);
goto error; goto error;
@ -2863,7 +2863,7 @@ int mworker_cli_sockpair_new(struct mworker_proc *mworker_proc, int proc)
list_for_each_entry(l, &bind_conf->listeners, by_bind) { list_for_each_entry(l, &bind_conf->listeners, by_bind) {
l->accept = session_accept_fd; l->accept = session_accept_fd;
l->default_target = global.stats_fe->default_target; l->default_target = global.cli_fe->default_target;
l->options |= (LI_O_UNLIMITED | LI_O_NOSTOP); l->options |= (LI_O_UNLIMITED | LI_O_NOSTOP);
HA_ATOMIC_ADD(&unstoppable_jobs, 1); HA_ATOMIC_ADD(&unstoppable_jobs, 1);
/* it's a sockpair but we don't want to keep the fd in the master */ /* it's a sockpair but we don't want to keep the fd in the master */
@ -2921,7 +2921,7 @@ static struct cli_kw_list cli_kws = {{ },{
INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws); INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws);
static struct cfg_kw_list cfg_kws = {ILH, { static struct cfg_kw_list cfg_kws = {ILH, {
{ CFG_GLOBAL, "stats", stats_parse_global }, { CFG_GLOBAL, "stats", cli_parse_global },
{ 0, NULL, NULL }, { 0, NULL, NULL },
}}; }};

View File

@ -713,11 +713,11 @@ int delete_oldpid(int pid)
static void get_cur_unixsocket() static void get_cur_unixsocket()
{ {
/* if -x was used, try to update the stat socket if not available anymore */ /* if -x was used, try to update the stat socket if not available anymore */
if (global.stats_fe) { if (global.cli_fe) {
struct bind_conf *bind_conf; struct bind_conf *bind_conf;
/* pass through all stats socket */ /* pass through all stats socket */
list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { list_for_each_entry(bind_conf, &global.cli_fe->conf.bind, by_fe) {
struct listener *l; struct listener *l;
list_for_each_entry(l, &bind_conf->listeners, by_bind) { list_for_each_entry(l, &bind_conf->listeners, by_bind) {
@ -2069,8 +2069,8 @@ static void init(int argc, char **argv)
if (cfg_maxconn > 0) if (cfg_maxconn > 0)
global.maxconn = cfg_maxconn; global.maxconn = cfg_maxconn;
if (global.stats_fe) if (global.cli_fe)
global.maxsock += global.stats_fe->maxconn; global.maxsock += global.cli_fe->maxconn;
if (cfg_peers) { if (cfg_peers) {
/* peers also need to bypass global maxconn */ /* peers also need to bypass global maxconn */
@ -3537,10 +3537,10 @@ int main(int argc, char **argv)
* Caution: the GTUNE_SOCKET_TRANSFER is now set after the fork. * Caution: the GTUNE_SOCKET_TRANSFER is now set after the fork.
* */ * */
if (global.stats_fe) { if (global.cli_fe) {
struct bind_conf *bind_conf; struct bind_conf *bind_conf;
list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { list_for_each_entry(bind_conf, &global.cli_fe->conf.bind, by_fe) {
if (bind_conf->level & ACCESS_FD_LISTENERS) { if (bind_conf->level & ACCESS_FD_LISTENERS) {
if (!bind_conf->settings.bind_proc || bind_conf->settings.bind_proc & (1UL << proc)) { if (!bind_conf->settings.bind_proc || bind_conf->settings.bind_proc & (1UL << proc)) {
global.tune.options |= GTUNE_SOCKET_TRANSFER; global.tune.options |= GTUNE_SOCKET_TRANSFER;