summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorratchov <ratchov@openbsd.org>2021-01-28 11:17:58 +0000
committerratchov <ratchov@openbsd.org>2021-01-28 11:17:58 +0000
commitf7f6d88adf3f9e9fe610261ee9df8cb0cd7f9535 (patch)
treed951e695edf63598e5ee54aed5d40e30513421da
parentDont attempt to drain disconnected clients (diff)
downloadwireguard-openbsd-f7f6d88adf3f9e9fe610261ee9df8cb0cd7f9535.tar.xz
wireguard-openbsd-f7f6d88adf3f9e9fe610261ee9df8cb0cd7f9535.zip
When an audio device is disconnected, drop MIDI clients controlling it
-rw-r--r--usr.bin/sndiod/dev.c4
-rw-r--r--usr.bin/sndiod/midi.c35
-rw-r--r--usr.bin/sndiod/midi.h4
-rw-r--r--usr.bin/sndiod/miofile.c9
4 files changed, 28 insertions, 24 deletions
diff --git a/usr.bin/sndiod/dev.c b/usr.bin/sndiod/dev.c
index 06412ae6ade..1a98fa39fc7 100644
--- a/usr.bin/sndiod/dev.c
+++ b/usr.bin/sndiod/dev.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dev.c,v 1.82 2021/01/28 11:15:31 ratchov Exp $ */
+/* $OpenBSD: dev.c,v 1.83 2021/01/28 11:17:58 ratchov Exp $ */
/*
* Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
*
@@ -1274,6 +1274,8 @@ dev_abort(struct dev *d)
c->ops = NULL;
}
+ midi_abort(d->midi);
+
if (d->pstate != DEV_CFG)
dev_close(d);
}
diff --git a/usr.bin/sndiod/midi.c b/usr.bin/sndiod/midi.c
index 5a2d0daa2bf..916d94c0a59 100644
--- a/usr.bin/sndiod/midi.c
+++ b/usr.bin/sndiod/midi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: midi.c,v 1.26 2021/01/12 15:46:53 naddy Exp $ */
+/* $OpenBSD: midi.c,v 1.27 2021/01/28 11:17:58 ratchov Exp $ */
/*
* Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
*
@@ -417,6 +417,22 @@ midi_out(struct midi *oep, unsigned char *idata, int icount)
}
}
+/*
+ * disconnect clients attached to this end-point
+ */
+void
+midi_abort(struct midi *p)
+{
+ int i;
+ struct midi *ep;
+
+ for (i = 0; i < MIDI_NEP; i++) {
+ ep = midi_ep + i;
+ if ((ep->txmask & p->self) || (p->txmask & ep->self))
+ ep->ops->exit(ep->arg);
+ }
+}
+
void
port_log(struct port *p)
{
@@ -562,23 +578,6 @@ port_open(struct port *c)
return 1;
}
-void
-port_abort(struct port *c)
-{
- int i;
- struct midi *ep;
-
- for (i = 0; i < MIDI_NEP; i++) {
- ep = midi_ep + i;
- if ((ep->txmask & c->midi->self) ||
- (c->midi->txmask & ep->self))
- ep->ops->exit(ep->arg);
- }
-
- if (c->state != PORT_CFG)
- port_close(c);
-}
-
int
port_close(struct port *c)
{
diff --git a/usr.bin/sndiod/midi.h b/usr.bin/sndiod/midi.h
index 8c51a6e9975..c8b7d1ed627 100644
--- a/usr.bin/sndiod/midi.h
+++ b/usr.bin/sndiod/midi.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: midi.h,v 1.13 2020/06/12 15:40:18 ratchov Exp $ */
+/* $OpenBSD: midi.h,v 1.14 2021/01/28 11:17:58 ratchov Exp $ */
/*
* Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
*
@@ -112,6 +112,7 @@ void midi_fill(struct midi *);
void midi_tag(struct midi *, unsigned int);
unsigned int midi_tags(struct midi *);
void midi_link(struct midi *, struct midi *);
+void midi_abort(struct midi *);
void port_log(struct port *);
struct port *port_new(char *, unsigned int, int);
@@ -124,6 +125,5 @@ void port_done(struct port *);
void port_drain(struct port *);
int port_close(struct port *);
int port_reopen(struct port *);
-void port_abort(struct port *);
#endif /* !defined(MIDI_H) */
diff --git a/usr.bin/sndiod/miofile.c b/usr.bin/sndiod/miofile.c
index 6da4ecdb996..dbfacc4ab1b 100644
--- a/usr.bin/sndiod/miofile.c
+++ b/usr.bin/sndiod/miofile.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: miofile.c,v 1.7 2020/06/12 15:40:18 ratchov Exp $ */
+/* $OpenBSD: miofile.c,v 1.8 2021/01/28 11:17:58 ratchov Exp $ */
/*
* Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
*
@@ -187,6 +187,9 @@ port_mio_hup(void *arg)
{
struct port *p = arg;
- if (!port_reopen(p))
- port_abort(p);
+ if (!port_reopen(p)) {
+ midi_abort(p->midi);
+ if (p->state != PORT_CFG)
+ port_close(p);
+ }
}