Skip to content

Commit 1f0fbfc

Browse files
committed
Fix debug flush race from open-simh PR 454
Fix the debug-output flush race described in open-simh/simh#454, but with a much simpler local implementation. The old debug flush path drained SIMH's internal debug buffer, then closed and reopened ordinary debug files to force the stdio buffers out. That temporarily cleared and replaced the global debug stream, which could race with other threads emitting debug output. Keep the internal debug-buffer flush, then call fflush() on the current debug stream. This preserves the useful flush behavior without closing or replacing sim_deb. Upstream-PR: open-simh/simh#454
1 parent 0a57aee commit 1f0fbfc

1 file changed

Lines changed: 6 additions & 24 deletions

File tree

src/core/scp.c

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10388,36 +10388,18 @@ static void _sim_debug_write (const char *buf, size_t len)
1038810388
_sim_debug_write_flush (buf, len, FALSE);
1038910389
}
1039010390

10391+
/* Flush pending debug output. */
1039110392
static t_stat _sim_debug_flush (void)
1039210393
{
10393-
int32 saved_quiet = sim_quiet;
10394-
int32 saved_sim_switches = sim_switches;
10395-
int32 saved_deb_switches = sim_deb_switches;
10396-
struct timespec saved_deb_basetime = sim_deb_basetime;
10397-
char saved_debug_filename[CBUFSIZE];
10394+
if (sim_deb == NULL) /* no debug? */
10395+
return SCPE_OK;
1039810396

10399-
if (sim_deb == NULL) /* no debug? */
10400-
return SCPE_OK;
10397+
_sim_debug_write_flush ("", 0, TRUE);
1040110398

10402-
_sim_debug_write_flush ("", 0, TRUE);
10399+
if (fflush (sim_deb) != 0)
10400+
return SCPE_IOERR;
1040310401

10404-
if (sim_deb == sim_log) { /* debug is log */
10405-
fflush (sim_deb); /* fflush is the best we can do */
1040610402
return SCPE_OK;
10407-
}
10408-
10409-
if (!(saved_deb_switches & SWMASK ('B'))) {
10410-
strcpy (saved_debug_filename, sim_logfile_name (sim_deb, sim_deb_ref));
10411-
10412-
sim_quiet = 1;
10413-
sim_set_deboff (0, NULL);
10414-
sim_switches = saved_deb_switches;
10415-
sim_set_debon (0, saved_debug_filename);
10416-
sim_deb_basetime = saved_deb_basetime;
10417-
sim_switches = saved_sim_switches;
10418-
sim_quiet = saved_quiet;
10419-
}
10420-
return SCPE_OK;
1042110403
}
1042210404

1042310405

0 commit comments

Comments
 (0)