From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id mEMYGwasOWE2eAAAWB0awg (envelope-from ) for ; Thu, 09 Sep 2021 02:39:02 -0400 Received: by simark.ca (Postfix, from userid 112) id 6CEB31EE23; Thu, 9 Sep 2021 02:39:02 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 213D71EDDB for ; Thu, 9 Sep 2021 02:39:01 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 81B073847818 for ; Thu, 9 Sep 2021 06:39:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 81B073847818 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1631169540; bh=HEBE3iin+EPjiQlF+IkUa+csAI4nJLtOEi139sWuL94=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=k2HbcvJyb7E3mGRKKR7nQwSrbHGEkWHN0b3vBBx/Tgf3UZoynZnlpYUFL0KqquEnb yG+Y9Bye0Lixq9iLl03JR3sm7BwWsprdMrAiWDEAhcz5aa7F1/26QoeS5bMoqgBMc1 TsvX5UwB88/SpVXTudbMA0Mz/+3B8gs0xOuiX+Hc= Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) by sourceware.org (Postfix) with ESMTP id 9E062384B801 for ; Thu, 9 Sep 2021 06:38:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9E062384B801 To: gdb-patches@sourceware.org Subject: [PATCH 2/2] sim: use gnulib to set nonblocking mode Date: Thu, 9 Sep 2021 02:38:36 -0400 Message-Id: <20210909063836.16875-2-vapier@gentoo.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210909063836.16875-1-vapier@gentoo.org> References: <20210909063836.16875-1-vapier@gentoo.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Mike Frysinger via Gdb-patches Reply-To: Mike Frysinger Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" Replace various custom ad-hoc fcntl/O_NONBLOCK implementations with the gnulib nonblocking module. This makes our code much tidier and portable to other systems (e.g. Windows). --- sim/bfin/dv-bfin_emac.c | 5 +++-- sim/common/dv-sockser.c | 11 +++-------- sim/common/sim-io.c | 22 +++++++--------------- sim/ppc/main.c | 20 ++++++-------------- 4 files changed, 19 insertions(+), 39 deletions(-) diff --git a/sim/bfin/dv-bfin_emac.c b/sim/bfin/dv-bfin_emac.c index e5ceedbef514..b53191d3838a 100644 --- a/sim/bfin/dv-bfin_emac.c +++ b/sim/bfin/dv-bfin_emac.c @@ -35,6 +35,8 @@ #include #endif +#include "nonblocking.h" + #ifdef HAVE_LINUX_IF_TUN_H # define WITH_TUN 1 #else @@ -570,8 +572,7 @@ bfin_emac_tap_init (struct hw *me) return; } - flags = fcntl (emac->tap, F_GETFL); - fcntl (emac->tap, F_SETFL, flags | O_NONBLOCK); + set_nonblocking_flag (emac->tap, true); #endif } diff --git a/sim/common/dv-sockser.c b/sim/common/dv-sockser.c index 477e8f681af7..5423765c66a3 100644 --- a/sim/common/dv-sockser.c +++ b/sim/common/dv-sockser.c @@ -24,9 +24,6 @@ along with this program. If not, see . */ #include #include #include -#ifdef HAVE_FCNTL_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif @@ -40,6 +37,8 @@ along with this program. If not, see . */ #include #include +#include "nonblocking.h" + #include "sim-main.h" #include "sim-assert.h" #include "sim-options.h" @@ -256,17 +255,13 @@ connected_p (SIM_DESC sd) return 0; /* Set non-blocking i/o. */ -#if defined(F_GETFL) && defined(O_NONBLOCK) - flags = fcntl (sockser_fd, F_GETFL); - flags |= O_NONBLOCK; - if (fcntl (sockser_fd, F_SETFL, flags) == -1) + if (set_nonblocking_flag (sockser_fd, true)) { sim_io_eprintf (sd, "unable to set nonblocking i/o"); close (sockser_fd); sockser_fd = -1; return 0; } -#endif return 1; } diff --git a/sim/common/sim-io.c b/sim/common/sim-io.c index a5a7ff17b067..9398cba57233 100644 --- a/sim/common/sim-io.c +++ b/sim/common/sim-io.c @@ -22,15 +22,14 @@ /* This must come before any other includes. */ #include "defs.h" +#include "nonblocking.h" + #include "sim-main.h" #include "sim-io.h" #include "sim/callback.h" #include "targ-vals.h" #include -#if HAVE_FCNTL_H -#include -#endif #if HAVE_UNISTD_H #include @@ -350,23 +349,20 @@ sim_io_poll_read (SIM_DESC sd, char *buf, int sizeof_buf) { -#if defined(O_NONBLOCK) && defined(F_GETFL) && defined(F_SETFL) int fd = STATE_CALLBACK (sd)->fdmap[sim_io_fd]; - int flags; int status; int nr_read; int result; STATE_CALLBACK (sd)->last_errno = 0; /* get the old status */ - flags = fcntl (fd, F_GETFL, 0); - if (flags == -1) + status = get_nonblocking_flag (fd); + if (status == -1) { - perror ("sim_io_poll_read"); + perror ("sim_io_read_stdin"); return 0; } /* temp, disable blocking IO */ - status = fcntl (fd, F_SETFL, flags | O_NONBLOCK); - if (status == -1) + if (status == 0 && set_nonblocking_flag (fd, true) == -1) { perror ("sim_io_read_stdin"); return 0; @@ -384,16 +380,12 @@ sim_io_poll_read (SIM_DESC sd, STATE_CALLBACK (sd)->last_errno = errno; } /* return to regular vewing */ - status = fcntl (fd, F_SETFL, flags); - if (status == -1) + if (status == 0 && set_nonblocking_flag (fd, false) == -1) { perror ("sim_io_read_stdin"); /* return 0; */ } return result; -#else - return sim_io_read (sd, sim_io_fd, buf, sizeof_buf); -#endif } int diff --git a/sim/ppc/main.c b/sim/ppc/main.c index d9a40700973d..f64b163afea7 100644 --- a/sim/ppc/main.c +++ b/sim/ppc/main.c @@ -26,6 +26,8 @@ #include +#include "nonblocking.h" + #include "psim.h" #include "options.h" #include "device.h" /* FIXME: psim should provide the interface */ @@ -42,11 +44,6 @@ #include #include -#if !defined(O_NONBLOCK) || !defined(F_GETFL) || !defined(F_SETFL) -#undef WITH_STDIO -#define WITH_STDIO DO_USE_STDIO -#endif - extern char **environ; @@ -152,22 +149,19 @@ sim_io_read_stdin(char *buf, return sim_io_eof; break; case DONT_USE_STDIO: -#if defined(O_NONBLOCK) && defined(F_GETFL) && defined(F_SETFL) { /* check for input */ - int flags; int status; int nr_read; int result; /* get the old status */ - flags = fcntl(0, F_GETFL, 0); - if (flags == -1) { + status = get_nonblocking_flag (0); + if (status == -1) { perror("sim_io_read_stdin"); return sim_io_eof; } /* temp, disable blocking IO */ - status = fcntl(0, F_SETFL, flags | O_NONBLOCK); - if (status == -1) { + if (status == 0 && set_nonblocking_flag (0, true) == -1) { perror("sim_io_read_stdin"); return sim_io_eof; } @@ -185,15 +179,13 @@ sim_io_read_stdin(char *buf, result = sim_io_eof; } /* return to regular vewing */ - status = fcntl(0, F_SETFL, flags); - if (status == -1) { + if (status == 0 && set_nonblocking_flag (0, false) == -1) { perror("sim_io_read_stdin"); return sim_io_eof; } return result; } break; -#endif default: error("sim_io_read_stdin: invalid switch\n"); break; -- 2.33.0