1
0
mirror of https://github.com/simh/simh.git synced 2026-01-11 23:52:58 +00:00

SCP: Be sure to flush output files when aborting.

Emit a last gasp message prior to flushing files before aborting.
This commit is contained in:
Mark Pizzolato 2022-07-17 13:01:25 -10:00
parent 9285073024
commit bc98e1c609
8 changed files with 34 additions and 30 deletions

View File

@ -1154,7 +1154,7 @@ else { /* Bottom End (After I/O processing) */
case FNC_SEARCH: /* search */
case FNC_SEEK: /* seek */
case FNC_WRITEH: /* write headers stub */
abort (); /* should NEVER happen */
sim_abort ("rp_svc() error", __FILE__, __LINE__); /* should NEVER happen */
break;
case FNC_WRITE: /* write */

16
scp.c
View File

@ -12316,10 +12316,9 @@ if (sim_clock_queue != QUEUE_LIST_END)
else
sim_interval = noqueue_time = NOQUEUE_WAIT;
if (uptr->next) {
sim_printf ("Cancel failed for %s\n", sim_uname(uptr));
if (sim_deb)
fclose(sim_deb);
abort ();
char buf[128];
snprintf (buf, sizeof (buf), "Cancel failed for %s\n", sim_uname(uptr));
sim_abort (buf, __FILE__, __LINE__);
}
return SCPE_OK;
}
@ -13685,6 +13684,15 @@ if (cond > SCPE_MAX_ERR)
return SCPE_OK;
}
/* Abort and sanely close output files */
/* This routine should ONLY be called from SCP modules */
void sim_abort (const char *msg, const char *file, int linenum)
{
sim_printf ("%s - aborting from %s:%d\n", msg, file, linenum);
sim_flush_buffered_files ();
abort ();
}
/* Debug printout routines, from Dave Hittner */
const char *debug_bstates = "01_^";

1
scp.h
View File

@ -274,6 +274,7 @@ void _sim_debug_device (uint32 dbits, DEVICE* dptr, const char* fmt, ...) GCC_FM
#define sim_debug_unit(dbits, uptr, ...) do { if ((sim_deb != NULL) && ((uptr) != NULL) && (uptr->dptr != NULL) && (((uptr)->dctrl | (uptr)->dptr->dctrl) & (dbits))) _sim_debug_unit (dbits, uptr, __VA_ARGS__);} while (0)
#endif
void sim_flush_buffered_files (void);
void sim_abort (const char *msg, const char *filename, int filelinenum);
void fprint_stopped_gen (FILE *st, t_stat v, REG *pc, DEVICE *dptr);
#define SCP_HELP_FLAT (1u << 31) /* Force flat help when prompting is not possible */

View File

@ -1142,9 +1142,11 @@ struct MEMFILE {
/* This replaces any references to "assert()" which should never be invoked */
/* with an expression which causes side effects (i.e. must be executed for */
/* the program to work correctly) */
#define ASSURE(_Expression) while (!(_Expression)) {fprintf(stderr, "%s failed at %s line %d\n", #_Expression, __FILE__, __LINE__); \
sim_printf("%s failed at %s line %d\n", #_Expression, __FILE__, __LINE__); \
abort();}
#define ASSURE(_Expression) while (!(_Expression)) { \
char buf[512]; \
snprintf(buf, sizeof (buf), "%s failed", #_Expression); \
sim_abort (buf, __FILE__, __LINE__); \
}
/* Asynch/Threaded I/O support */
@ -1190,15 +1192,9 @@ extern int32 sim_asynch_inst_latency;
for (_cptr = que; \
(_cptr != QUEUE_LIST_END); \
_cptr = _cptr->next) \
if (!_cptr->next) { \
if (sim_deb) { \
sim_debug (SIM_DBG_EVENT, sim_dflt_dev, "Queue Corruption detected\n");\
fclose(sim_deb); \
} \
sim_printf("Queue Corruption detected in %s line %d\n",\
__FILE__, __LINE); \
abort(); \
} \
if (!_cptr->next) \
sim_abort ("Queue Corruption detected", \
__FILE__, __LINE__); \
if (lock) \
pthread_mutex_unlock (lock); \
} while (0)
@ -1352,9 +1348,8 @@ extern int32 sim_asynch_inst_latency;
#endif /* USE_AIO_INTRINSICS */
#define AIO_VALIDATE(uptr) \
if (!pthread_equal ( pthread_self(), sim_asynch_main_threadid )) { \
sim_printf("Improper thread context for operation on %s in %s line %d\n", \
sim_uname(uptr), __FILE__, __LINE__); \
abort(); \
sim_abort ("Improper thread context for operation detected", \
__FILE__, __LINE__); \
} else (void)0
#define AIO_CHECK_EVENT \
if (0 > --sim_asynch_check) { \

View File

@ -231,8 +231,8 @@ if ((!callback) || !ctx->asynch_io)
"sim_disk AIO_CALL(op=%d, unit=%d, lba=0x%X, sects=%d)\n",\
op, (int)(uptr - ctx->dptr->units), _lba, _sects);\
\
if (ctx->callback) \
abort(); /* horrible mistake, stop */ \
if (ctx->callback) /* horrible mistake, stop */ \
sim_abort ("AIO_CALL error", __FILE__, __LINE__); \
ctx->io_dop = op; \
ctx->lba = _lba; \
ctx->buf = _buf; \
@ -314,7 +314,7 @@ DISK_PCALLBACK callback = ctx->callback;
sim_debug_unit (ctx->dbit, uptr, "_disk_completion_dispatch(unit=%d, dop=%d, callback=%p)\n", (int)(uptr - ctx->dptr->units), ctx->io_dop, (void *)(ctx->callback));
if (ctx->io_dop != DOP_DONE)
abort(); /* horribly wrong, stop */
sim_abort ("_disk_completion_dispatch()", __FILE__, __LINE__); /* horribly wrong, stop */
if (ctx->callback && ctx->io_dop == DOP_DONE) {
ctx->callback = NULL;

View File

@ -3721,7 +3721,7 @@ switch (dev->eth_api) {
break;
default:
bpf_used = to_me = 0; /* Should NEVER happen */
abort();
sim_abort ("_eth_callback()", __FILE__, __LINE__);
break;
}

View File

@ -186,8 +186,8 @@ if ((callback == NULL) || !(ctx->asynch_io))
sim_debug_unit (ctx->dbit, uptr, \
"sim_tape AIO_CALL(op=%d, unit=%d)\n", op, (int)(uptr-ctx->dptr->units));\
\
if (ctx->callback) \
abort(); /* horrible mistake, stop */ \
if (ctx->callback) /* horrible mistake, stop */ \
sim_abort ("AIO_CALL error", __FILE__, __LINE__); \
ctx->io_top = op; \
ctx->buf = _buf; \
ctx->bc = _bc; \
@ -325,7 +325,7 @@ TAPE_PCALLBACK callback = ctx->callback;
sim_debug_unit (ctx->dbit, uptr, "_tape_completion_dispatch(unit=%d, top=%d, callback=%p)\n", (int)(uptr-ctx->dptr->units), ctx->io_top, ctx->callback);
if (ctx->io_top != TOP_DONE)
abort(); /* horribly wrong, stop */
sim_abort ("_tape_completion_dispatch()", __FILE__, __LINE__); /* horribly wrong, stop */
if (ctx->asynch_io)
pthread_mutex_lock (&ctx->io_lock);

View File

@ -3898,7 +3898,7 @@ while (sim_asynch_enabled) {
if (select_errno == EINTR)
break;
sim_printf ("select() returned -1, errno=%d - %s\r\n", select_errno, strerror(select_errno));
abort();
sim_abort ("", __FILE__, __LINE__);
break;
default:
wait_count = 0;
@ -4015,7 +4015,7 @@ while (sim_asynch_enabled) {
switch (status) {
case WAIT_FAILED:
sim_printf ("WaitForMultipleObjects() Failed, LastError=%d\r\n", GetLastError());
abort();
sim_abort ("", __FILE__, __LINE__);
break;
case WAIT_TIMEOUT:
sim_debug (TMXR_DBG_ASY, dptr, "_tmxr_serial_poll() - Poll Timeout - %dms\n", timeout_usec/1000);
@ -4126,7 +4126,7 @@ while (sim_asynch_enabled) {
&iosb, 0, 0, buf, 1, 1, term, 0, 0);
if (status != SS$_NORMAL) {
sim_printf ("_tmxr_serial_line_poll() - QIO Failed, Status=%d\r\n", status);
abort();
sim_abort ("", __FILE__, __LINE__);
}
wait_count = 0;
sys$synch (0, &iosb);