Skip to content

Commit db25d56

Browse files
Markus ArmbrusterstefanhaRH
authored andcommitted
trace/simple: Fix unauthorized enable
st_set_trace_file() accidentally enables tracing. It's called unconditionally during startup, which is why QEMU built with the simple trace backend always writes a trace file "trace-$PID". This has been broken for quite a while. I didn't track down the exact commit. Fix st_set_trace_file() to restore the state. Signed-off-by: Markus Armbruster <[email protected]> Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Message-id: [email protected] Signed-off-by: Stefan Hajnoczi <[email protected]>
1 parent f892b49 commit db25d56

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

trace/simple.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,17 @@ static int st_write_event_mapping(void)
302302
return 0;
303303
}
304304

305-
void st_set_trace_file_enabled(bool enable)
305+
/**
306+
* Enable / disable tracing, return whether it was enabled.
307+
*
308+
* @enable: enable if %true, else disable.
309+
*/
310+
bool st_set_trace_file_enabled(bool enable)
306311
{
312+
bool was_enabled = trace_fp;
313+
307314
if (enable == !!trace_fp) {
308-
return; /* no change */
315+
return was_enabled; /* no change */
309316
}
310317

311318
/* Halt trace writeout */
@@ -323,14 +330,14 @@ void st_set_trace_file_enabled(bool enable)
323330

324331
trace_fp = fopen(trace_file_name, "wb");
325332
if (!trace_fp) {
326-
return;
333+
return was_enabled;
327334
}
328335

329336
if (fwrite(&header, sizeof header, 1, trace_fp) != 1 ||
330337
st_write_event_mapping() < 0) {
331338
fclose(trace_fp);
332339
trace_fp = NULL;
333-
return;
340+
return was_enabled;
334341
}
335342

336343
/* Resume trace writeout */
@@ -340,6 +347,7 @@ void st_set_trace_file_enabled(bool enable)
340347
fclose(trace_fp);
341348
trace_fp = NULL;
342349
}
350+
return was_enabled;
343351
}
344352

345353
/**
@@ -350,7 +358,7 @@ void st_set_trace_file_enabled(bool enable)
350358
*/
351359
void st_set_trace_file(const char *file)
352360
{
353-
st_set_trace_file_enabled(false);
361+
bool saved_enable = st_set_trace_file_enabled(false);
354362

355363
g_free(trace_file_name);
356364

@@ -361,7 +369,7 @@ void st_set_trace_file(const char *file)
361369
trace_file_name = g_strdup_printf("%s", file);
362370
}
363371

364-
st_set_trace_file_enabled(true);
372+
st_set_trace_file_enabled(saved_enable);
365373
}
366374

367375
void st_print_trace_file_status(void)

trace/simple.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#define TRACE_SIMPLE_H
1313

1414
void st_print_trace_file_status(void);
15-
void st_set_trace_file_enabled(bool enable);
15+
bool st_set_trace_file_enabled(bool enable);
1616
void st_set_trace_file(const char *file);
1717
bool st_init(void);
1818
void st_flush_trace_buffer(void);

0 commit comments

Comments
 (0)