From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id EFCF13858409; Wed, 25 Jan 2023 17:08:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EFCF13858409 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674666499; bh=Y8PCKveTzr3W0Um0ajf3vE09Zg3jP3Kyu6e6SendSfQ=; h=From:To:Subject:Date:From; b=Y88SWwoSnlLjtYT19mUC5K5+IKN4YX2mh6/dwWaSgY/i6pv2INK5WftRDazWD+/tY wFJVzFjA3vFap40SuYFPy/GGk12PCPcpkge5x+WCjLveXSdUiWzcDSKTzMDsinLfcR d+VhvDegv6/cQRErPwA6alBo3M2Nr4svnvl2CH/w= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Takashi Yano To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/cygwin-3_4-branch] Cygwin: dsp: Fix hang on close() if another thread calls write(). X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/cygwin-3_4-branch X-Git-Oldrev: 62bc6bee3bdbb79404ce52860b25f06750ca83ba X-Git-Newrev: 4384f47b93a1111bda31eb1570605a52a35730cc Message-Id: <20230125170819.EFCF13858409@sourceware.org> Date: Wed, 25 Jan 2023 17:08:19 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D4384f47b93a= 1111bda31eb1570605a52a35730cc commit 4384f47b93a1111bda31eb1570605a52a35730cc Author: Takashi Yano Date: Wed Jan 25 18:30:50 2023 +0900 Cygwin: dsp: Fix hang on close() if another thread calls write(). =20 fhandler_dev_dsp (OSS) has a problem that waitforallsent(), which is called from close(), falls into infinite loop if another thread calls write() accidentally after close(). This patch fixes the issue. =20 Reviewed-by: Corinna Vinschen Signed-off-by: Takashi Yano Diff: --- winsup/cygwin/fhandler/dsp.cc | 9 +++++++++ winsup/cygwin/local_includes/fhandler.h | 1 + 2 files changed, 10 insertions(+) diff --git a/winsup/cygwin/fhandler/dsp.cc b/winsup/cygwin/fhandler/dsp.cc index 8798cf876..cfbf6bec7 100644 --- a/winsup/cygwin/fhandler/dsp.cc +++ b/winsup/cygwin/fhandler/dsp.cc @@ -1093,6 +1093,8 @@ fhandler_dev_dsp::open (int flags, mode_t) =20 debug_printf ("ACCMODE=3D%y audio_in=3D%d audio_out=3D%d, err=3D%d, ret= =3D%d", flags & O_ACCMODE, num_in, num_out, err, ret); + if (ret) + being_closed =3D false; return ret; } =20 @@ -1106,6 +1108,12 @@ fhandler_dev_dsp::_write (const void *ptr, size_t le= n) int len_s =3D len; const char *ptr_s =3D static_cast (ptr); =20 + if (being_closed) + { + set_errno (EBADF); + return -1; + } + if (audio_out_) /* nothing to do */; else if (IS_WRITE ()) @@ -1207,6 +1215,7 @@ int fhandler_dev_dsp::close () { debug_printf ("audio_in=3D%p audio_out=3D%p", audio_in_, audio_out_); + being_closed =3D true; close_audio_in (); close_audio_out (); return fhandler_base::close (); diff --git a/winsup/cygwin/local_includes/fhandler.h b/winsup/cygwin/local_= includes/fhandler.h index 5fe979538..e7315ae16 100644 --- a/winsup/cygwin/local_includes/fhandler.h +++ b/winsup/cygwin/local_includes/fhandler.h @@ -2758,6 +2758,7 @@ class fhandler_dev_dsp: public fhandler_base int audiochannels_; Audio_out *audio_out_; Audio_in *audio_in_; + bool being_closed; public: fhandler_dev_dsp (); fhandler_dev_dsp *base () const {return (fhandler_dev_dsp *)archetype;}