From 6a193c032d11766b32466dac4ce61f9fe589a808 Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Tue, 13 Aug 2019 20:04:09 -0700 Subject: [PATCH] ETHER: Fix possible race conditions when closing a network device Added pcap version to the SCP output of SHOW VERSION command. --- scp.c | 3 +++ sim_ether.c | 28 +++++++++++++++++----------- sim_ether.h | 1 + slirp_glue/sim_slirp.c | 2 ++ 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/scp.c b/scp.c index 39b440a4..750a7a7d 100644 --- a/scp.c +++ b/scp.c @@ -5866,6 +5866,9 @@ if (flag) { #endif fprintf (st, "\n OS clock resolution: %dms", os_tick_size); fprintf (st, "\n Time taken by msleep(1): %dms", os_ms_sleep_1); + if (eth_version ()) + fprintf (st, "\n Ethernet packet info: %s", eth_version()); + fprintf (st, "\n Time taken by msleep(1): %dms", os_ms_sleep_1); #if defined(__VMS) if (1) { char *arch = diff --git a/sim_ether.c b/sim_ether.c index b1675f0e..916769c1 100644 --- a/sim_ether.c +++ b/sim_ether.c @@ -750,7 +750,6 @@ static char* (*p_pcap_lib_version) (void); static ETH_DEV **eth_open_devices = NULL; static int eth_open_device_count = 0; -static t_bool eth_show_active = FALSE; #if defined (USE_NETWORK) || defined (USE_SHARED) static void _eth_add_to_open_list (ETH_DEV* dev) @@ -778,7 +777,6 @@ t_stat eth_show (FILE* st, UNIT* uptr, int32 val, CONST void* desc) ETH_LIST list[ETH_MAX_DEVICE]; int number; - eth_show_active = TRUE; number = eth_devices(ETH_MAX_DEVICE, list); fprintf(st, "ETH devices:\n"); if (number == -1) @@ -794,9 +792,6 @@ t_stat eth_show (FILE* st, UNIT* uptr, int32 val, CONST void* desc) for (i=0; idbit, dev->dptr, "Writer Thread Starting\n"); pthread_mutex_lock (&dev->writer_lock); while (dev->handle) { pthread_cond_wait (&dev->writer_cond, &dev->writer_lock); + if (dev->handle == NULL) /* Shutting down? */ + break; while (NULL != (request = dev->write_requests)) { /* Pull buffer off request list */ dev->write_requests = request->next; @@ -2437,6 +2438,11 @@ _eth_remove_from_open_list (dev); return SCPE_OK; } +const char *eth_version (void) +{ +return pcap_lib_version(); +} + t_stat eth_attach_help(FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, const char *cptr) { fprintf (st, "%s attach help\n\n", dptr->name); diff --git a/sim_ether.h b/sim_ether.h index 2c95ff89..02c84cec 100644 --- a/sim_ether.h +++ b/sim_ether.h @@ -349,6 +349,7 @@ t_stat eth_filter_hash (ETH_DEV* dev, int addr_count, /* set filter on incomin ETH_MULTIHASH* const hash); t_stat eth_check_address_conflict (ETH_DEV* dev, ETH_MAC* const address); +const char *eth_version (void); /* Version of dynamically loaded library (pcap) */ int eth_devices (int max, ETH_LIST* dev); /* get ethernet devices on host */ void eth_setcrc (ETH_DEV* dev, int need_crc); /* enable/disable CRC mode */ t_stat eth_set_async (ETH_DEV* dev, int latency); /* set read behavior to be async */ diff --git a/slirp_glue/sim_slirp.c b/slirp_glue/sim_slirp.c index 912899d4..f44d1b95 100644 --- a/slirp_glue/sim_slirp.c +++ b/slirp_glue/sim_slirp.c @@ -595,6 +595,8 @@ fd_set rfds, wfds, xfds; fd_set save_rfds, save_wfds, save_xfds; int nfds; +if (!slirp) /* Not active? */ + return -1; /* That's an error */ /* Populate the GPollFDs from slirp */ g_array_set_size (slirp->gpollfds, 1); /* Leave the doorbell chime alone */ slirp_pollfds_fill(slirp->gpollfds, &slirp_timeout);