From: ratchov Date: Fri, 24 May 2024 15:21:35 +0000 (+0000) Subject: sndiod: Set the display string of all server.device entries X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=ad73c56558478c343f8389c6b4262e708ef6549b;p=openbsd sndiod: Set the display string of all server.device entries with help from edd@ and armani@ --- diff --git a/usr.bin/sndiod/dev.c b/usr.bin/sndiod/dev.c index b96d70e0ab2..bd2489354f7 100644 --- a/usr.bin/sndiod/dev.c +++ b/usr.bin/sndiod/dev.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dev.c,v 1.115 2024/05/24 15:16:09 ratchov Exp $ */ +/* $OpenBSD: dev.c,v 1.116 2024/05/24 15:21:35 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov * @@ -1054,6 +1054,8 @@ dev_allocbufs(struct dev *d) int dev_open(struct dev *d) { + struct opt *o; + d->mode = d->reqmode; d->round = d->reqround; d->bufsz = d->reqbufsz; @@ -1076,6 +1078,18 @@ dev_open(struct dev *d) return 0; d->pstate = DEV_INIT; + + /* add server.device if device is opened after opt_ref() call */ + for (o = opt_list; o != NULL; o = o->next) { + if (o->refcnt > 0 && !ctl_find(CTL_OPT_DEV, o, d)) { + ctl_new(CTL_OPT_DEV, o, d, + CTL_SEL, dev_getdisplay(d), + o->name, "server", -1, "device", + d->name, -1, 1, o->dev == d); + d->refcnt++; + } + } + return 1; } @@ -1150,6 +1164,14 @@ dev_freebufs(struct dev *d) void dev_close(struct dev *d) { + struct opt *o; + + /* remove server.device entries */ + for (o = opt_list; o != NULL; o = o->next) { + if (ctl_del(CTL_OPT_DEV, o, d)) + d->refcnt--; + } + d->pstate = DEV_CFG; dev_sio_close(d); dev_freebufs(d); diff --git a/usr.bin/sndiod/opt.c b/usr.bin/sndiod/opt.c index 195416678d1..1c7d7ce7cae 100644 --- a/usr.bin/sndiod/opt.c +++ b/usr.bin/sndiod/opt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: opt.c,v 1.11 2024/05/24 15:16:09 ratchov Exp $ */ +/* $OpenBSD: opt.c,v 1.12 2024/05/24 15:21:35 ratchov Exp $ */ /* * Copyright (c) 2008-2011 Alexandre Ratchov * @@ -346,15 +346,6 @@ opt_del(struct opt *o) void opt_init(struct opt *o) { - struct dev *d; - - if (strcmp(o->name, o->dev->name) != 0) { - for (d = dev_list; d != NULL; d = d->next) { - ctl_new(CTL_OPT_DEV, o, d, - CTL_SEL, "", o->name, "server", -1, "device", - d->name, -1, 1, o->dev == d); - } - } } void @@ -499,6 +490,17 @@ opt_ref(struct opt *o) /* if device changed, move everything to the new one */ if (d != o->dev) opt_setdev(o, d); + + /* create server.device control */ + for (d = dev_list; d != NULL; d = d->next) { + d->refcnt++; + if (d->pstate == DEV_CFG) + dev_open(d); + ctl_new(CTL_OPT_DEV, o, d, + CTL_SEL, dev_getdisplay(d), + o->name, "server", -1, "device", + d->name, -1, 1, o->dev == d); + } } } @@ -512,7 +514,15 @@ opt_ref(struct opt *o) void opt_unref(struct opt *o) { + struct dev *d; + o->refcnt--; - if (o->refcnt == 0) + if (o->refcnt == 0) { + /* delete server.device control */ + for (d = dev_list; d != NULL; d = d->next) { + if (ctl_del(CTL_OPT_DEV, o, d)) + dev_unref(d); + } dev_unref(o->dev); + } }