Skip to content

Commit e9928c3

Browse files
einval22wlallemand
authored andcommitted
BUG/MINOR: mworker: do 'program' postparser checks in read_cfg_in_discovery_mode
cfg_program_postparser() contains 2 parts: - check the combination of MODE_MWORKER and "program" section. if "program" section was parsed, MODE_MWORKER is mandatory; - check "command" keyword, which is mandatory for this section as well. This is more appropriate now, after the master-worker refactoring, do the first part in read_cfg_in_discovery_mode, where we already check the combination of MODE_MWORKER and -S option. We need to do the second part just below, in read_cfg_in_discovery_mode() as well, because it's only the master process, who parses now program section and programs are forked before running postparser functions in step_init_2. Otherwise, mworker_ext_launch_all() will emit a log message, that program is started, but actually nothing has been launched, if 'command' keyword is absent. This not needs to be backported, as related to the master-worker refactoring.
1 parent 1767196 commit e9928c3

File tree

2 files changed

+31
-27
lines changed

2 files changed

+31
-27
lines changed

src/haproxy.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3102,6 +3102,7 @@ static void run_master_in_recovery_mode(int argc, char **argv)
31023102
static void read_cfg_in_discovery_mode(int argc, char **argv)
31033103
{
31043104
struct cfgfile *cfg, *cfg_tmp;
3105+
struct mworker_proc *proc;
31053106

31063107
/* load configs in memory and parse only global section (MODE_DISCOVERY) */
31073108
global.mode |= MODE_DISCOVERY;
@@ -3151,6 +3152,36 @@ static void read_cfg_in_discovery_mode(int argc, char **argv)
31513152
exit(EXIT_FAILURE);
31523153
}
31533154

3155+
/* "progam" sections, if there are any, were alredy parsed only by master
3156+
* and programs are forked before calling postparser functions from
3157+
* postparser list. So, all checks related to "program" section integrity
3158+
* and sections vs MODE_MWORKER combinations should be done here.
3159+
*/
3160+
list_for_each_entry(proc, &proc_list, list) {
3161+
if (proc->options & PROC_O_TYPE_PROG) {
3162+
if (!(global.mode & MODE_MWORKER)) {
3163+
ha_alert("'program' section is defined in configuration, "
3164+
"but master-worker mode (-W) is not enabled.\n");
3165+
exit(EXIT_FAILURE);
3166+
}
3167+
3168+
if ((proc->reloads == 0) && (proc->command == NULL)) {
3169+
if (getenv("HAPROXY_MWORKER_REEXEC") != NULL) {
3170+
ha_warning("Master failed to parse new configuration: "
3171+
"the program section '%s' lacks a command to launch. "
3172+
"It can't start a new worker and launch defined programs. "
3173+
"Already running worker and programs "
3174+
"will be kept. Please, check program section settings\n", proc->id);
3175+
3176+
run_master_in_recovery_mode(argc, argv);
3177+
} else {
3178+
ha_alert("The program section '%s' lacks a command to launch.\n", proc->id);
3179+
exit(EXIT_FAILURE);
3180+
}
3181+
}
3182+
}
3183+
}
3184+
31543185
/* in MODE_CHECK and in MODE_DUMP_CFG we just need to parse the
31553186
* configuration and exit, see step_init_2()
31563187
*/

src/mworker-prog.c

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -332,31 +332,4 @@ int cfg_parse_program(const char *file, int linenum, char **args, int kwm)
332332

333333
}
334334

335-
int cfg_program_postparser()
336-
{
337-
int err_code = 0;
338-
struct mworker_proc *child;
339-
340-
if (!(global.mode & MODE_DISCOVERY))
341-
return err_code;
342-
343-
list_for_each_entry(child, &proc_list, list) {
344-
if (child->reloads == 0 && (child->options & PROC_O_TYPE_PROG)) {
345-
if (child->command == NULL) {
346-
ha_alert("The program section '%s' lacks a command to launch.\n", child->id);
347-
err_code |= ERR_ALERT | ERR_FATAL;
348-
}
349-
}
350-
}
351-
352-
if (use_program && !(global.mode & MODE_MWORKER)) {
353-
ha_alert("Can't use a 'program' section without master worker mode.\n");
354-
err_code |= ERR_ALERT | ERR_FATAL;
355-
}
356-
357-
return err_code;
358-
}
359-
360-
361335
REGISTER_CONFIG_SECTION("program", cfg_parse_program, NULL);
362-
REGISTER_CONFIG_POSTPARSER("program", cfg_program_postparser);

0 commit comments

Comments
 (0)