mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-07 23:56:57 +02:00
MINOR: server: create new function cli_find_server() to find a server
Several CLI commands require a server, so let's have a function to look this one up and prepare the appropriate error message and the appctx's state in case of failure.
This commit is contained in:
parent
de57a578ba
commit
21b069dca8
@ -48,6 +48,7 @@ void apply_server_state(void);
|
|||||||
void srv_compute_all_admin_states(struct proxy *px);
|
void srv_compute_all_admin_states(struct proxy *px);
|
||||||
int srv_set_addr_via_libc(struct server *srv, int *err_code);
|
int srv_set_addr_via_libc(struct server *srv, int *err_code);
|
||||||
int srv_init_addr(void);
|
int srv_init_addr(void);
|
||||||
|
struct server *cli_find_server(struct appctx *appctx, char *arg);
|
||||||
|
|
||||||
/* functions related to server name resolution */
|
/* functions related to server name resolution */
|
||||||
int snr_update_srv_status(struct server *s);
|
int snr_update_srv_status(struct server *s);
|
||||||
|
41
src/server.c
41
src/server.c
@ -21,6 +21,7 @@
|
|||||||
#include <common/time.h>
|
#include <common/time.h>
|
||||||
|
|
||||||
#include <types/global.h>
|
#include <types/global.h>
|
||||||
|
#include <types/cli.h>
|
||||||
#include <types/dns.h>
|
#include <types/dns.h>
|
||||||
|
|
||||||
#include <proto/checks.h>
|
#include <proto/checks.h>
|
||||||
@ -3339,6 +3340,46 @@ int srv_init_addr(void)
|
|||||||
return return_code;
|
return return_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Expects to find a backend and a server in <arg> under the form <backend>/<server>,
|
||||||
|
* and returns the pointer to the server. Otherwise, display adequate error messages
|
||||||
|
* on the CLI, sets the CLI's state to STAT_CLI_PRINT and returns NULL. This is only
|
||||||
|
* used for CLI commands requiring a server name.
|
||||||
|
* Important: the <arg> is modified to remove the '/'.
|
||||||
|
*/
|
||||||
|
struct server *cli_find_server(struct appctx *appctx, char *arg)
|
||||||
|
{
|
||||||
|
struct proxy *px;
|
||||||
|
struct server *sv;
|
||||||
|
char *line;
|
||||||
|
|
||||||
|
/* split "backend/server" and make <line> point to server */
|
||||||
|
for (line = arg; *line; line++)
|
||||||
|
if (*line == '/') {
|
||||||
|
*line++ = '\0';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!*line || !*arg) {
|
||||||
|
appctx->ctx.cli.msg = "Require 'backend/server'.\n";
|
||||||
|
appctx->st0 = STAT_CLI_PRINT;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!get_backend_server(arg, line, &px, &sv)) {
|
||||||
|
appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n";
|
||||||
|
appctx->st0 = STAT_CLI_PRINT;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (px->state == PR_STSTOPPED) {
|
||||||
|
appctx->ctx.cli.msg = "Proxy is disabled.\n";
|
||||||
|
appctx->st0 = STAT_CLI_PRINT;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return sv;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Local variables:
|
* Local variables:
|
||||||
|
Loading…
Reference in New Issue
Block a user