diff options
-rw-r--r-- | usr.bin/sndiod/dev.c | 34 | ||||
-rw-r--r-- | usr.bin/sndiod/dev.h | 10 | ||||
-rw-r--r-- | usr.bin/sndiod/fdpass.c | 29 | ||||
-rw-r--r-- | usr.bin/sndiod/siofile.c | 23 | ||||
-rw-r--r-- | usr.bin/sndiod/sndiod.c | 18 |
5 files changed, 76 insertions, 38 deletions
diff --git a/usr.bin/sndiod/dev.c b/usr.bin/sndiod/dev.c index fe224a7f6a3..4b02f1831e2 100644 --- a/usr.bin/sndiod/dev.c +++ b/usr.bin/sndiod/dev.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dev.c,v 1.72 2020/06/12 15:40:18 ratchov Exp $ */ +/* $OpenBSD: dev.c,v 1.73 2020/06/18 05:11:13 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org> * @@ -1017,10 +1017,11 @@ dev_new(char *path, struct aparams *par, return NULL; } d = xmalloc(sizeof(struct dev)); - d->path_list = NULL; - namelist_add(&d->path_list, path); + d->alt_list = NULL; + dev_addname(d,path); d->num = dev_sndnum++; d->opt_list = NULL; + d->alt_num = 1; /* * XXX: below, we allocate a midi input buffer, since we don't @@ -1066,6 +1067,27 @@ dev_new(char *path, struct aparams *par, } /* + * add a alternate name + */ +int +dev_addname(struct dev *d, char *name) +{ + struct dev_alt *a; + + if (d->alt_list != NULL && d->alt_list->idx == DEV_NMAX - 1) { + log_puts(name); + log_puts(": too many alternate names\n"); + return 0; + } + a = xmalloc(sizeof(struct dev_alt)); + a->name = name; + a->idx = (d->alt_list == NULL) ? 0 : d->alt_list->idx + 1; + a->next = d->alt_list; + d->alt_list = a; + return 1; +} + +/* * adjust device parameters and mode */ void @@ -1418,6 +1440,7 @@ void dev_del(struct dev *d) { struct dev **p; + struct dev_alt *a; #ifdef DEBUG if (log_level >= 3) { @@ -1440,7 +1463,10 @@ dev_del(struct dev *d) } midi_del(d->midi); *p = d->next; - namelist_clear(&d->path_list); + while ((a = d->alt_list) != NULL) { + d->alt_list = a->next; + xfree(a); + } xfree(d); } diff --git a/usr.bin/sndiod/dev.h b/usr.bin/sndiod/dev.h index 0c600d793e1..73414622e5e 100644 --- a/usr.bin/sndiod/dev.h +++ b/usr.bin/sndiod/dev.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dev.h,v 1.26 2020/06/12 15:40:18 ratchov Exp $ */ +/* $OpenBSD: dev.h,v 1.27 2020/06/18 05:11:13 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org> * @@ -209,7 +209,12 @@ struct dev { #define DEV_INIT 1 /* stopped */ #define DEV_RUN 2 /* playin & recording */ unsigned int pstate; /* one of above */ - struct name *path_list; + struct dev_alt { + struct dev_alt *next; + char *name; + unsigned int idx; + } *alt_list; + int alt_num; /* * actual parameters and runtime state (i.e. once opened) @@ -265,6 +270,7 @@ int dev_reopen(struct dev *); struct dev *dev_new(char *, struct aparams *, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int); struct dev *dev_bynum(int); +int dev_addname(struct dev *, char *); void dev_del(struct dev *); void dev_adjpar(struct dev *, int, int, int); int dev_init(struct dev *); diff --git a/usr.bin/sndiod/fdpass.c b/usr.bin/sndiod/fdpass.c index 1ab493fbe35..9f97f35b7e1 100644 --- a/usr.bin/sndiod/fdpass.c +++ b/usr.bin/sndiod/fdpass.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fdpass.c,v 1.9 2020/02/26 13:53:58 ratchov Exp $ */ +/* $OpenBSD: fdpass.c,v 1.10 2020/06/18 05:11:13 ratchov Exp $ */ /* * Copyright (c) 2015 Alexandre Ratchov <alex@caoua.org> * @@ -323,6 +323,7 @@ fdpass_in_helper(void *arg) int cmd, num, idx, mode, fd; struct fdpass *f = arg; struct dev *d; + struct dev_alt *da; struct port *p; char *path; @@ -339,12 +340,15 @@ fdpass_in_helper(void *arg) fdpass_close(f); return; } - path = namelist_byindex(&d->path_list, idx); - if (path == NULL) { - fdpass_close(f); - return; + for (da = d->alt_list; ; da = da->next) { + if (da == NULL) { + fdpass_close(f); + return; + } + if (da->idx == idx) + break; } - fd = sio_sun_getfd(path, mode, 1); + fd = sio_sun_getfd(da->name, mode, 1); break; case FDPASS_OPEN_MIDI: p = port_bynum(num); @@ -373,12 +377,15 @@ fdpass_in_helper(void *arg) fdpass_close(f); return; } - path = namelist_byindex(&d->path_list, idx); - if (path == NULL) { - fdpass_close(f); - return; + for (da = d->alt_list; ; da = da->next) { + if (da == NULL) { + fdpass_close(f); + return; + } + if (da->idx == idx) + break; } - fd = sioctl_sun_getfd(path, mode, 1); + fd = sioctl_sun_getfd(da->name, mode, 1); break; default: fdpass_close(f); diff --git a/usr.bin/sndiod/siofile.c b/usr.bin/sndiod/siofile.c index 4cc0be02a49..5ae66167dfe 100644 --- a/usr.bin/sndiod/siofile.c +++ b/usr.bin/sndiod/siofile.c @@ -1,4 +1,4 @@ -/* $OpenBSD: siofile.c,v 1.20 2020/06/12 15:40:18 ratchov Exp $ */ +/* $OpenBSD: siofile.c,v 1.21 2020/06/18 05:11:13 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org> * @@ -93,25 +93,22 @@ dev_sio_timeout(void *arg) static struct sio_hdl * dev_sio_openlist(struct dev *d, unsigned int mode, struct sioctl_hdl **rctlhdl) { - struct name *n; + struct dev_alt *n; struct sio_hdl *hdl; struct sioctl_hdl *ctlhdl; - int idx; - idx = 0; - n = d->path_list; - while (1) { - if (n == NULL) - break; - hdl = fdpass_sio_open(d->num, idx, mode); + for (n = d->alt_list; n != NULL; n = n->next) { + if (d->alt_num == n->idx) + continue; + hdl = fdpass_sio_open(d->num, n->idx, mode); if (hdl != NULL) { if (log_level >= 2) { dev_log(d); log_puts(": using "); - log_puts(n->str); + log_puts(n->name); log_puts("\n"); } - ctlhdl = fdpass_sioctl_open(d->num, idx, + ctlhdl = fdpass_sioctl_open(d->num, n->idx, SIOCTL_READ | SIOCTL_WRITE); if (ctlhdl == NULL) { if (log_level >= 1) { @@ -119,11 +116,10 @@ dev_sio_openlist(struct dev *d, unsigned int mode, struct sioctl_hdl **rctlhdl) log_puts(": no control device\n"); } } + d->alt_num = n->idx; *rctlhdl = ctlhdl; return hdl; } - n = n->next; - idx++; } return NULL; } @@ -378,6 +374,7 @@ dev_sio_close(struct dev *d) sioctl_close(d->sioctl.hdl); d->sioctl.hdl = NULL; } + d->alt_num = -1; } void diff --git a/usr.bin/sndiod/sndiod.c b/usr.bin/sndiod/sndiod.c index 0e6ea7236f1..0aa175a2a64 100644 --- a/usr.bin/sndiod/sndiod.c +++ b/usr.bin/sndiod/sndiod.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sndiod.c,v 1.40 2020/04/25 05:35:52 ratchov Exp $ */ +/* $OpenBSD: sndiod.c,v 1.41 2020/06/18 05:11:13 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org> * @@ -318,8 +318,8 @@ mkdev(char *path, struct aparams *par, struct dev *d; for (d = dev_list; d != NULL; d = d->next) { - if (d->path_list->next == NULL && - strcmp(d->path_list->str, path) == 0) + if (d->alt_list->next == NULL && + strcmp(d->alt_list->name, path) == 0) return d; } if (!bufsz && !round) { @@ -385,6 +385,7 @@ static int start_helper(int background) { struct dev *d; + struct dev_alt *da; struct port *p; struct passwd *pw; struct name *n; @@ -423,9 +424,9 @@ start_helper(int background) err(1, "cannot drop privileges"); } for (d = dev_list; d != NULL; d = d->next) { - for (n = d->path_list; n != NULL; n = n->next) { - dounveil(n->str, "rsnd/", "/dev/audio"); - dounveil(n->str, "rsnd/", "/dev/audioctl"); + for (da = d->alt_list; da != NULL; da = da->next) { + dounveil(da->name, "rsnd/", "/dev/audio"); + dounveil(da->name, "rsnd/", "/dev/audioctl"); } } for (p = port_list; p != NULL; p = p->next) { @@ -580,9 +581,10 @@ main(int argc, char **argv) devindex = -1; break; case 'F': - if (dev_list == NULL) + if ((d = dev_list) == NULL) errx(1, "-F %s: no devices defined", optarg); - namelist_add(&dev_list->path_list, optarg); + if (!dev_addname(d, optarg)) + exit(1); break; default: fputs(usagestr, stderr); |