From: ratchov Date: Thu, 28 Jan 2021 11:15:31 +0000 (+0000) Subject: Dont attempt to drain disconnected clients X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=dff6ad497000e39449fa9bf70b979d1009237eb8;p=openbsd 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 --- 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) { diff --git a/usr.bin/sndiod/dev.h b/usr.bin/sndiod/dev.h index 74408313124..564f8caea17 100644 --- a/usr.bin/sndiod/dev.h +++ b/usr.bin/sndiod/dev.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dev.h,v 1.30 2021/01/28 11:02:28 ratchov Exp $ */ +/* $OpenBSD: dev.h,v 1.31 2021/01/28 11:15:31 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov * @@ -306,7 +306,7 @@ struct slot *slot_new(struct dev *, struct opt *, unsigned int, char *, void slot_del(struct slot *); void slot_setvol(struct slot *, unsigned int); void slot_start(struct slot *); -void slot_stop(struct slot *); +void slot_stop(struct slot *, int); void slot_read(struct slot *); void slot_write(struct slot *); void slot_initconv(struct slot *); diff --git a/usr.bin/sndiod/sock.c b/usr.bin/sndiod/sock.c index fb50a4bd99a..6f7cea4c926 100644 --- a/usr.bin/sndiod/sock.c +++ b/usr.bin/sndiod/sock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sock.c,v 1.35 2020/04/26 14:13:22 ratchov Exp $ */ +/* $OpenBSD: sock.c,v 1.36 2021/01/28 11:15:31 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov * @@ -1141,7 +1141,7 @@ sock_execmsg(struct sock *f) f->ralign = s->round * s->mix.bpf; } } - slot_stop(s); + slot_stop(s, 1); break; case AMSG_SETPAR: #ifdef DEBUG