Skip to content

Commit 326460a

Browse files
avargitster
authored andcommitted
tr2: do compiler enum check in trace2_collect_process_info()
Change code added in 2f732bf (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 <[email protected]> Acked-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6eccfc3 commit 326460a

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

compat/linux/procinfo.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,30 @@ static void get_ancestry_names(struct strvec *names)
3131

3232
void trace2_collect_process_info(enum trace2_process_info_reason reason)
3333
{
34+
struct strvec names = STRVEC_INIT;
35+
3436
if (!trace2_is_enabled())
3537
return;
3638

37-
if (reason == TRACE2_PROCESS_INFO_EXIT)
39+
switch (reason) {
40+
case TRACE2_PROCESS_INFO_EXIT:
3841
/*
3942
* The Windows version of this calls its
4043
* get_peak_memory_info() here. We may want to insert
4144
* similar process-end statistics here in the future.
4245
*/
43-
return;
44-
45-
if (reason == TRACE2_PROCESS_INFO_STARTUP) {
46+
break;
47+
case TRACE2_PROCESS_INFO_STARTUP:
4648
/*
4749
* NEEDSWORK: we could do the entire ptree in an array instead,
4850
* see compat/win32/trace2_win32_process_info.c.
4951
*/
50-
struct strvec names = STRVEC_INIT;
51-
5252
get_ancestry_names(&names);
5353

5454
if (names.nr)
5555
trace2_cmd_ancestry(names.v);
5656
strvec_clear(&names);
57+
break;
5758
}
5859

5960
return;

0 commit comments

Comments
 (0)