From 305dfd425594dfa4017b1fc81e45ad43a7fd2b08 Mon Sep 17 00:00:00 2001 From: Alexandre Ratchov Date: Thu, 28 Jan 2021 11:15:32 +0000 Subject: Dont attempt to drain disconnected clients Clients are always drained before they disconnect, so this change affects programs that die unexpectedly or loose thier network connection. Besides the bad style, this change fixes a theoretical bug when the disconnected client slot could be recycled and given to another client while it's being drained --- usr.bin/sndiod/dev.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'usr.bin/sndiod/dev.c') diff --git a/usr.bin/sndiod/dev.c b/usr.bin/sndiod/dev.c index e3ce842711d..06412ae6ade 100644 --- a/usr.bin/sndiod/dev.c +++ b/usr.bin/sndiod/dev.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dev.c,v 1.81 2021/01/28 11:10:00 ratchov Exp $ */ +/* $OpenBSD: dev.c,v 1.82 2021/01/28 11:15:31 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov * @@ -1972,9 +1972,8 @@ slot_del(struct slot *s) case SLOT_START: case SLOT_READY: case SLOT_RUN: - slot_stop(s); - /* PASSTHROUGH */ case SLOT_STOP: + slot_stop(s, 0); break; } dev_unref(s->dev); @@ -2195,7 +2194,7 @@ slot_detach(struct slot *s) * stop & detach if no data to drain. */ void -slot_stop(struct slot *s) +slot_stop(struct slot *s, int drain) { #ifdef DEBUG if (log_level >= 3) { @@ -2214,7 +2213,7 @@ slot_stop(struct slot *s) } if (s->pstate == SLOT_RUN) { - if (s->mode & MODE_PLAY) { + if ((s->mode & MODE_PLAY) && drain) { /* * Don't detach, dev_cycle() will do it for us * when the buffer is drained. @@ -2223,6 +2222,8 @@ slot_stop(struct slot *s) return; } slot_detach(s); + } else if (s->pstate == SLOT_STOP) { + slot_detach(s); } else { #ifdef DEBUG if (log_level >= 3) { -- cgit v1.2.3