Skip to content

Commit 0f1d37a

Browse files
committed
DEBUG: cli: support closing "hard" using close() in addition to fd_delete()
"debug dev close <fd>" currently closes that FD using fd_delete() after checking that it's known from the fdtab. Sometimes we also want to just perform a pure close() of FDs not in the fdtab (pollers, etc) in order to provoke certain error cases. The optional "hard" argument to the command will make it use a plain close() instead of fd_delete() and skip the fd owner check. The main visible effect when closing a traffic socket with it is that instead of dying from a double fd_delete() by seeing that fd.owner is already 0, it will die during the next fd_insert() seeing that fd.owner was not 0.
1 parent 3939579 commit 0f1d37a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/debug.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -806,17 +806,23 @@ static int debug_parse_cli_close(char **args, char *payload, struct appctx *appc
806806
return 1;
807807

808808
if (!*args[3])
809-
return cli_err(appctx, "Missing file descriptor number.\n");
809+
return cli_err(appctx, "Missing file descriptor number (optionally followed by 'hard').\n");
810810

811811
fd = atoi(args[3]);
812812
if (fd < 0 || fd >= global.maxsock)
813813
return cli_err(appctx, "File descriptor out of range.\n");
814814

815+
if (strcmp(args[4], "hard") == 0) {
816+
/* hard silent close, even for unknown FDs */
817+
close(fd);
818+
goto done;
819+
}
815820
if (!fdtab[fd].owner)
816821
return cli_msg(appctx, LOG_INFO, "File descriptor was already closed.\n");
817822

818-
_HA_ATOMIC_INC(&debug_commands_issued);
819823
fd_delete(fd);
824+
done:
825+
_HA_ATOMIC_INC(&debug_commands_issued);
820826
return 1;
821827
}
822828

@@ -2649,7 +2655,7 @@ REGISTER_PER_THREAD_INIT(feed_post_mortem_late);
26492655
static struct cli_kw_list cli_kws = {{ },{
26502656
{{ "debug", "dev", "bug", NULL }, "debug dev bug : call BUG_ON() and crash", debug_parse_cli_bug, NULL, NULL, NULL, ACCESS_EXPERT },
26512657
{{ "debug", "dev", "check", NULL }, "debug dev check : call CHECK_IF() and possibly crash", debug_parse_cli_check, NULL, NULL, NULL, ACCESS_EXPERT },
2652-
{{ "debug", "dev", "close", NULL }, "debug dev close <fd> : close this file descriptor", debug_parse_cli_close, NULL, NULL, NULL, ACCESS_EXPERT },
2658+
{{ "debug", "dev", "close", NULL }, "debug dev close <fd> [hard] : close this file descriptor", debug_parse_cli_close, NULL, NULL, NULL, ACCESS_EXPERT },
26532659
#if !defined(USE_OBSOLETE_LINKER)
26542660
{{ "debug", "dev", "counters", NULL }, "debug dev counters [all|bug|cnt|chk|?]* : dump/reset rare event counters", debug_parse_cli_counters, debug_iohandler_counters, NULL, NULL, 0 },
26552661
#endif

0 commit comments

Comments
 (0)