Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/winsup
diff options
context:
space:
mode:
authorTakashi Yano <takashi.yano@nifty.ne.jp>2023-01-25 12:30:50 +0300
committerTakashi Yano <takashi.yano@nifty.ne.jp>2023-01-25 20:04:56 +0300
commit4384f47b93a1111bda31eb1570605a52a35730cc (patch)
tree39159f8c3987df76554b377258fb8a5860c66f09 /winsup
parent62bc6bee3bdbb79404ce52860b25f06750ca83ba (diff)
Cygwin: dsp: Fix hang on close() if another thread calls write().
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. Reviewed-by: Corinna Vinschen <corinna@vinschen.de> Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Diffstat (limited to 'winsup')
-rw-r--r--winsup/cygwin/fhandler/dsp.cc9
-rw-r--r--winsup/cygwin/local_includes/fhandler.h1
2 files changed, 10 insertions, 0 deletions
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)
debug_printf ("ACCMODE=%y audio_in=%d audio_out=%d, err=%d, ret=%d",
flags & O_ACCMODE, num_in, num_out, err, ret);
+ if (ret)
+ being_closed = false;
return ret;
}
@@ -1106,6 +1108,12 @@ fhandler_dev_dsp::_write (const void *ptr, size_t len)
int len_s = len;
const char *ptr_s = static_cast <const char *> (ptr);
+ 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=%p audio_out=%p", audio_in_, audio_out_);
+ being_closed = 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;}