diff --git a/include/proto/backend.h b/include/proto/backend.h index b4dfc835c..24cd90936 100644 --- a/include/proto/backend.h +++ b/include/proto/backend.h @@ -35,8 +35,7 @@ int assign_server_and_queue(struct session *s); int connect_server(struct session *s); int srv_redispatch_connect(struct session *t); const char *backend_lb_algo_str(int algo); -int backend_parse_balance(const char **args, char *err, - int errlen, struct proxy *curproxy); +int backend_parse_balance(const char **args, char **err, struct proxy *curproxy); int tcp_persist_rdp_cookie(struct session *s, struct buffer *req, int an_bit); int be_downtime(struct proxy *px); diff --git a/src/backend.c b/src/backend.c index 4652fba04..7c1c92d68 100644 --- a/src/backend.c +++ b/src/backend.c @@ -1215,12 +1215,12 @@ const char *backend_lb_algo_str(int algo) { /* This function parses a "balance" statement in a backend section describing * . It returns -1 if there is any error, otherwise zero. If it - * returns -1, it may write an error message into ther buffer, for at - * most bytes, trailing zero included. The trailing '\n' will not be - * written. The function must be called with pointing to the first word - * after "balance". + * returns -1, it will write an error message into the buffer which will + * automatically be allocated and must be passed as NULL. The trailing '\n' + * will not be written. The function must be called with pointing to the + * first word after "balance". */ -int backend_parse_balance(const char **args, char *err, int errlen, struct proxy *curproxy) +int backend_parse_balance(const char **args, char **err, struct proxy *curproxy) { if (!*(args[0])) { /* if no option is set, use round-robin by default */ @@ -1258,7 +1258,7 @@ int backend_parse_balance(const char **args, char *err, int errlen, struct proxy while (*args[arg]) { if (!strcmp(args[arg], "len")) { if (!*args[arg+1] || (atoi(args[arg+1]) <= 0)) { - snprintf(err, errlen, "'balance uri len' expects a positive integer (got '%s').", args[arg+1]); + memprintf(err, "%s : '%s' expects a positive integer (got '%s').", args[0], args[arg], args[arg+1]); return -1; } curproxy->uri_len_limit = atoi(args[arg+1]); @@ -1266,7 +1266,7 @@ int backend_parse_balance(const char **args, char *err, int errlen, struct proxy } else if (!strcmp(args[arg], "depth")) { if (!*args[arg+1] || (atoi(args[arg+1]) <= 0)) { - snprintf(err, errlen, "'balance uri depth' expects a positive integer (got '%s').", args[arg+1]); + memprintf(err, "%s : '%s' expects a positive integer (got '%s').", args[0], args[arg], args[arg+1]); return -1; } /* hint: we store the position of the ending '/' (depth+1) so @@ -1276,14 +1276,14 @@ int backend_parse_balance(const char **args, char *err, int errlen, struct proxy arg += 2; } else { - snprintf(err, errlen, "'balance uri' only accepts parameters 'len' and 'depth' (got '%s').", args[arg]); + memprintf(err, "%s only accepts parameters 'len' and 'depth' (got '%s').", args[0], args[arg]); return -1; } } } else if (!strcmp(args[0], "url_param")) { if (!*args[1]) { - snprintf(err, errlen, "'balance url_param' requires an URL parameter name."); + memprintf(err, "%s requires an URL parameter name.", args[0]); return -1; } curproxy->lbprm.algo &= ~BE_LB_ALGO; @@ -1294,7 +1294,7 @@ int backend_parse_balance(const char **args, char *err, int errlen, struct proxy curproxy->url_param_len = strlen(args[1]); if (*args[2]) { if (strcmp(args[2], "check_post")) { - snprintf(err, errlen, "'balance url_param' only accepts check_post modifier."); + memprintf(err, "%s only accepts 'check_post' modifier (got '%s').", args[0], args[2]); return -1; } if (*args[3]) { @@ -1315,7 +1315,7 @@ int backend_parse_balance(const char **args, char *err, int errlen, struct proxy end = strchr(beg, ')'); if (!end || end == beg) { - snprintf(err, errlen, "'balance hdr(name)' requires an http header field name."); + memprintf(err, "hdr requires an http header field name."); return -1; } @@ -1329,7 +1329,7 @@ int backend_parse_balance(const char **args, char *err, int errlen, struct proxy if (*args[1]) { if (strcmp(args[1], "use_domain_only")) { - snprintf(err, errlen, "'balance hdr(name)' only accepts 'use_domain_only' modifier."); + memprintf(err, "%s only accepts 'use_domain_only' modifier (got '%s').", args[0], args[1]); return -1; } curproxy->hh_match_domain = 1; @@ -1347,7 +1347,7 @@ int backend_parse_balance(const char **args, char *err, int errlen, struct proxy end = strchr(beg, ')'); if (!end || end == beg) { - snprintf(err, errlen, "'balance rdp-cookie(name)' requires an rdp cookie name."); + memprintf(err, "rdp-cookie : missing cookie name."); return -1; } @@ -1361,12 +1361,12 @@ int backend_parse_balance(const char **args, char *err, int errlen, struct proxy curproxy->hh_len = strlen(curproxy->hh_name); } else { /* syntax */ - snprintf(err, errlen, "'balance rdp-cookie(name)' requires an rdp cookie name."); + memprintf(err, "rdp-cookie : missing cookie name."); return -1; } } else { - snprintf(err, errlen, "'balance' only supports 'roundrobin', 'static-rr', 'leastconn', 'source', 'uri', 'url_param', 'hdr(name)' and 'rdp-cookie(name)' options."); + memprintf(err, "only supports 'roundrobin', 'static-rr', 'leastconn', 'source', 'uri', 'url_param', 'hdr(name)' and 'rdp-cookie(name)' options."); return -1; } return 0; diff --git a/src/cfgparse.c b/src/cfgparse.c index 7e8e7d56c..134794049 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -3963,9 +3963,8 @@ stats_error_parsing: if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) err_code |= ERR_WARN; - memcpy(trash, "error near 'balance'", 21); - if (backend_parse_balance((const char **)args + 1, trash, sizeof(trash), curproxy) < 0) { - Alert("parsing [%s:%d] : %s\n", file, linenum, trash); + if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) { + Alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg); err_code |= ERR_ALERT | ERR_FATAL; goto out; }