summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandre Ratchov <ratchov@cvs.openbsd.org>2021-03-08 09:42:51 +0000
committerAlexandre Ratchov <ratchov@cvs.openbsd.org>2021-03-08 09:42:51 +0000
commit379ffaaa32694d54d95b6f65f656177c97d6cc07 (patch)
treeb14801bace403d380e116fac6b01ca03ce854a39
parent414ac93b71ae716bfc8a41ca33bd7ed0c8e34f54 (diff)
sndiod: Use chronological order for {dev,port}_list
This simplifies the logic of the initialization code, makes debug printfs nicer and could slightly ease futur development. No behavior change.
-rw-r--r--usr.bin/sndiod/dev.c10
-rw-r--r--usr.bin/sndiod/midi.c10
-rw-r--r--usr.bin/sndiod/sndiod.c31
3 files changed, 29 insertions, 22 deletions
diff --git a/usr.bin/sndiod/dev.c b/usr.bin/sndiod/dev.c
index 725732c91ba..8754bfb422c 100644
--- a/usr.bin/sndiod/dev.c
+++ b/usr.bin/sndiod/dev.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dev.c,v 1.96 2021/03/08 09:38:36 ratchov Exp $ */
+/* $OpenBSD: dev.c,v 1.97 2021/03/08 09:42:50 ratchov Exp $ */
/*
* Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
*
@@ -916,7 +916,7 @@ dev_new(char *path, struct aparams *par,
unsigned int mode, unsigned int bufsz, unsigned int round,
unsigned int rate, unsigned int hold, unsigned int autovol)
{
- struct dev *d;
+ struct dev *d, **pd;
if (dev_sndnum == DEV_NMAX) {
if (log_level >= 1)
@@ -943,8 +943,10 @@ dev_new(char *path, struct aparams *par,
d->master = MIDI_MAXCTL;
d->master_enabled = 0;
snprintf(d->name, CTL_NAMEMAX, "%u", d->num);
- d->next = dev_list;
- dev_list = d;
+ for (pd = &dev_list; *pd != NULL; pd = &(*pd)->next)
+ ;
+ d->next = *pd;
+ *pd = d;
return d;
}
diff --git a/usr.bin/sndiod/midi.c b/usr.bin/sndiod/midi.c
index 916d94c0a59..fea9441b2e2 100644
--- a/usr.bin/sndiod/midi.c
+++ b/usr.bin/sndiod/midi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: midi.c,v 1.27 2021/01/28 11:17:58 ratchov Exp $ */
+/* $OpenBSD: midi.c,v 1.28 2021/03/08 09:42:50 ratchov Exp $ */
/*
* Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
*
@@ -482,7 +482,7 @@ port_exit(void *arg)
struct port *
port_new(char *path, unsigned int mode, int hold)
{
- struct port *c;
+ struct port *c, **pc;
c = xmalloc(sizeof(struct port));
c->path_list = NULL;
@@ -491,8 +491,10 @@ port_new(char *path, unsigned int mode, int hold)
c->hold = hold;
c->midi = midi_new(&port_midiops, c, mode);
c->num = midi_portnum++;
- c->next = port_list;
- port_list = c;
+ for (pc = &port_list; *pc != NULL; pc = &(*pc)->next)
+ ;
+ c->next = *pc;
+ *pc = c;
return c;
}
diff --git a/usr.bin/sndiod/sndiod.c b/usr.bin/sndiod/sndiod.c
index c0b7862888c..9a7daeb9e63 100644
--- a/usr.bin/sndiod/sndiod.c
+++ b/usr.bin/sndiod/sndiod.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sndiod.c,v 1.44 2021/02/05 17:59:33 jcs Exp $ */
+/* $OpenBSD: sndiod.c,v 1.45 2021/03/08 09:42:50 ratchov Exp $ */
/*
* Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
*
@@ -456,7 +456,7 @@ stop_helper(void)
int
main(int argc, char **argv)
{
- int c, i, background, unit, devindex;
+ int c, i, background, unit;
int pmin, pmax, rmin, rmax;
char base[SOCKPATH_MAX], path[SOCKPATH_MAX];
unsigned int mode, dup, mmc, vol;
@@ -494,7 +494,8 @@ main(int argc, char **argv)
aparams_init(&par);
mode = MODE_PLAY | MODE_REC;
tcpaddr_list = NULL;
- devindex = 0;
+ d = NULL;
+ p = NULL;
slot_array_init();
@@ -545,21 +546,24 @@ main(int argc, char **argv)
errx(1, "%s: volume is %s", optarg, str);
break;
case 's':
- if ((d = dev_list) == NULL) {
- d = mkdev(default_devs[devindex++], &par, 0,
- bufsz, round, rate, hold, autovol);
+ if (d == NULL) {
+ for (i = 0; default_devs[i] != NULL; i++) {
+ mkdev(default_devs[i], &par, 0,
+ bufsz, round, rate, 0, autovol);
+ }
+ d = dev_list;
}
if (mkopt(optarg, d, pmin, pmax, rmin, rmax,
mode, vol, mmc, dup) == NULL)
return 1;
break;
case 'q':
- mkport(optarg, hold);
+ p = mkport(optarg, hold);
break;
case 'Q':
- if (port_list == NULL)
+ if (p == NULL)
errx(1, "-Q %s: no ports defined", optarg);
- namelist_add(&port_list->path_list, optarg);
+ namelist_add(&p->path_list, optarg);
break;
case 'a':
hold = opt_onoff();
@@ -578,12 +582,11 @@ main(int argc, char **argv)
errx(1, "%s: block size is %s", optarg, str);
break;
case 'f':
- mkdev(optarg, &par, 0, bufsz, round,
+ d = mkdev(optarg, &par, 0, bufsz, round,
rate, hold, autovol);
- devindex = -1;
break;
case 'F':
- if ((d = dev_list) == NULL)
+ if (d == NULL)
errx(1, "-F %s: no devices defined", optarg);
if (!dev_addname(d, optarg))
exit(1);
@@ -603,8 +606,8 @@ main(int argc, char **argv)
for (i = 0; default_ports[i] != NULL; i++)
mkport(default_ports[i], 0);
}
- if (devindex != -1) {
- for (i = devindex; default_devs[i] != NULL; i++) {
+ if (dev_list == NULL) {
+ for (i = 0; default_devs[i] != NULL; i++) {
mkdev(default_devs[i], &par, 0,
bufsz, round, rate, 0, autovol);
}