Message ID | patch-5.6-4e378da2cce-20210825T231400Z-avarab@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | tr2: plug memory leaks + logic errors + Win32 & Linux feature parity | expand |
On Thu, Aug 26, 2021 at 01:19:23AM +0200, Ævar Arnfjörð Bjarmason wrote: > Change code added in 2f732bf15e6 (tr2: log parent process name, > 2021-07-21) to use a switch statement without a "default" branch to > have the compiler error if this code ever drifts out of sync with the > members of the "enum trace2_process_info_reason". OK... arguably this code should have been written with a switch statement to begin with, but this looks like unnecessary churn to me. Maybe the next patch adds a new value of this enum? Let's see. Thanks, Taylor
diff --git a/compat/linux/procinfo.c b/compat/linux/procinfo.c index c86daff2b26..46a751c9a1d 100644 --- a/compat/linux/procinfo.c +++ b/compat/linux/procinfo.c @@ -30,29 +30,30 @@ static void get_ancestry_names(struct strvec *names) void trace2_collect_process_info(enum trace2_process_info_reason reason) { + struct strvec names = STRVEC_INIT; + if (!trace2_is_enabled()) return; - if (reason == TRACE2_PROCESS_INFO_EXIT) + switch (reason) { + case TRACE2_PROCESS_INFO_EXIT: /* * The Windows version of this calls its * get_peak_memory_info() here. We may want to insert * similar process-end statistics here in the future. */ - return; - - if (reason == TRACE2_PROCESS_INFO_STARTUP) { + break; + case TRACE2_PROCESS_INFO_STARTUP: /* * NEEDSWORK: we could do the entire ptree in an array instead, * see compat/win32/trace2_win32_process_info.c. */ - struct strvec names = STRVEC_INIT; - get_ancestry_names(&names); if (names.nr) trace2_cmd_ancestry(names.v); strvec_clear(&names); + break; } return;
Change code added in 2f732bf15e6 (tr2: log parent process name, 2021-07-21) to use a switch statement without a "default" branch to have the compiler error if this code ever drifts out of sync with the members of the "enum trace2_process_info_reason". Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- compat/linux/procinfo.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)