summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorratchov <ratchov@openbsd.org>2020-01-23 05:40:09 +0000
committerratchov <ratchov@openbsd.org>2020-01-23 05:40:09 +0000
commitf5092d39e9bbef1a753c3dc5ea793c51fa68eb2e (patch)
tree2d633c194208fa989f30840ebf809f74e423cd59
parentAccept MIDI clients that don't reset status during sysex messages. (diff)
downloadwireguard-openbsd-f5092d39e9bbef1a753c3dc5ea793c51fa68eb2e.tar.xz
wireguard-openbsd-f5092d39e9bbef1a753c3dc5ea793c51fa68eb2e.zip
When opening a device, loop over the alternate devices list in the
worker process instead of the helper process. It is simpler this way and allows the worker to properly log which device is being used.
-rw-r--r--usr.bin/sndiod/fdpass.c49
-rw-r--r--usr.bin/sndiod/fdpass.h6
-rw-r--r--usr.bin/sndiod/miofile.c37
-rw-r--r--usr.bin/sndiod/siofile.c41
-rw-r--r--usr.bin/sndiod/utils.c19
-rw-r--r--usr.bin/sndiod/utils.h3
6 files changed, 122 insertions, 33 deletions
diff --git a/usr.bin/sndiod/fdpass.c b/usr.bin/sndiod/fdpass.c
index 30ed39f1e14..86849110880 100644
--- a/usr.bin/sndiod/fdpass.c
+++ b/usr.bin/sndiod/fdpass.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fdpass.c,v 1.7 2019/09/21 04:42:46 ratchov Exp $ */
+/* $OpenBSD: fdpass.c,v 1.8 2020/01/23 05:40:09 ratchov Exp $ */
/*
* Copyright (c) 2015 Alexandre Ratchov <alex@caoua.org>
*
@@ -35,6 +35,7 @@ struct fdpass_msg {
#define FDPASS_RETURN 3 /* return after above commands */
unsigned int cmd; /* one of above */
unsigned int num; /* audio device or midi port number */
+ unsigned int idx; /* index in the path list */
unsigned int mode; /* SIO_PLAY, SIO_REC, MIO_IN, ... */
};
@@ -75,7 +76,7 @@ fdpass_log(struct fdpass *f)
}
static int
-fdpass_send(struct fdpass *f, int cmd, int num, int mode, int fd)
+fdpass_send(struct fdpass *f, int cmd, int num, int idx, int mode, int fd)
{
struct fdpass_msg data;
struct msghdr msg;
@@ -89,6 +90,7 @@ fdpass_send(struct fdpass *f, int cmd, int num, int mode, int fd)
data.cmd = cmd;
data.num = num;
+ data.idx = idx;
data.mode = mode;
iov.iov_base = &data;
iov.iov_len = sizeof(struct fdpass_msg);
@@ -128,6 +130,8 @@ fdpass_send(struct fdpass *f, int cmd, int num, int mode, int fd)
log_puti(cmd);
log_puts(", num = ");
log_puti(num);
+ log_puts(", idx = ");
+ log_puti(idx);
log_puts(", mode = ");
log_puti(mode);
log_puts(", fd = ");
@@ -141,7 +145,7 @@ fdpass_send(struct fdpass *f, int cmd, int num, int mode, int fd)
}
static int
-fdpass_recv(struct fdpass *f, int *cmd, int *num, int *mode, int *fd)
+fdpass_recv(struct fdpass *f, int *cmd, int *num, int *idx, int *mode, int *fd)
{
struct fdpass_msg data;
struct msghdr msg;
@@ -212,6 +216,7 @@ fdpass_recv(struct fdpass *f, int *cmd, int *num, int *mode, int *fd)
}
*cmd = data.cmd;
*num = data.num;
+ *idx = data.idx;
*mode = data.mode;
#ifdef DEBUG
if (log_level >= 3) {
@@ -220,6 +225,8 @@ fdpass_recv(struct fdpass *f, int *cmd, int *num, int *mode, int *fd)
log_puti(*cmd);
log_puts(", num = ");
log_puti(*num);
+ log_puts(", idx = ");
+ log_puti(*idx);
log_puts(", mode = ");
log_puti(*mode);
log_puts(", fd = ");
@@ -235,7 +242,7 @@ fdpass_waitret(struct fdpass *f, int *retfd)
{
int cmd, unused;
- if (!fdpass_recv(fdpass_peer, &cmd, &unused, &unused, retfd))
+ if (!fdpass_recv(fdpass_peer, &cmd, &unused, &unused, &unused, retfd))
return 0;
if (cmd != FDPASS_RETURN) {
if (log_level >= 1) {
@@ -249,13 +256,13 @@ fdpass_waitret(struct fdpass *f, int *retfd)
}
struct sio_hdl *
-fdpass_sio_open(int num, unsigned int mode)
+fdpass_sio_open(int num, int idx, unsigned int mode)
{
int fd;
if (fdpass_peer == NULL)
return NULL;
- if (!fdpass_send(fdpass_peer, FDPASS_OPEN_SND, num, mode, -1))
+ if (!fdpass_send(fdpass_peer, FDPASS_OPEN_SND, num, idx, mode, -1))
return NULL;
if (!fdpass_waitret(fdpass_peer, &fd))
return NULL;
@@ -265,13 +272,13 @@ fdpass_sio_open(int num, unsigned int mode)
}
struct mio_hdl *
-fdpass_mio_open(int num, unsigned int mode)
+fdpass_mio_open(int num, int idx, unsigned int mode)
{
int fd;
if (fdpass_peer == NULL)
return NULL;
- if (!fdpass_send(fdpass_peer, FDPASS_OPEN_MIDI, num, mode, -1))
+ if (!fdpass_send(fdpass_peer, FDPASS_OPEN_MIDI, num, idx, mode, -1))
return NULL;
if (!fdpass_waitret(fdpass_peer, &fd))
return NULL;
@@ -296,13 +303,13 @@ fdpass_in_worker(void *arg)
void
fdpass_in_helper(void *arg)
{
- int cmd, num, mode, fd;
+ int cmd, num, idx, mode, fd;
struct fdpass *f = arg;
struct dev *d;
struct port *p;
- struct name *path;
+ char *path;
- if (!fdpass_recv(f, &cmd, &num, &mode, &fd))
+ if (!fdpass_recv(f, &cmd, &num, &idx, &mode, &fd))
return;
switch (cmd) {
case FDPASS_OPEN_SND:
@@ -315,11 +322,12 @@ fdpass_in_helper(void *arg)
fdpass_close(f);
return;
}
- for (path = d->path_list; path != NULL; path = path->next) {
- fd = sio_sun_getfd(path->str, mode, 1);
- if (fd != -1)
- break;
+ path = namelist_byindex(&d->path_list, idx);
+ if (path == NULL) {
+ fdpass_close(f);
+ return;
}
+ fd = sio_sun_getfd(path, mode, 1);
break;
case FDPASS_OPEN_MIDI:
p = port_bynum(num);
@@ -331,17 +339,18 @@ fdpass_in_helper(void *arg)
fdpass_close(f);
return;
}
- for (path = p->path_list; path != NULL; path = path->next) {
- fd = mio_rmidi_getfd(path->str, mode, 1);
- if (fd != -1)
- break;
+ path = namelist_byindex(&p->path_list, idx);
+ if (path == NULL) {
+ fdpass_close(f);
+ return;
}
+ fd = mio_rmidi_getfd(path, mode, 1);
break;
default:
fdpass_close(f);
return;
}
- fdpass_send(f, FDPASS_RETURN, 0, 0, fd);
+ fdpass_send(f, FDPASS_RETURN, 0, 0, 0, fd);
}
void
diff --git a/usr.bin/sndiod/fdpass.h b/usr.bin/sndiod/fdpass.h
index 7dd59279fbd..29819b5b71e 100644
--- a/usr.bin/sndiod/fdpass.h
+++ b/usr.bin/sndiod/fdpass.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: fdpass.h,v 1.1 2015/12/20 11:38:33 ratchov Exp $ */
+/* $OpenBSD: fdpass.h,v 1.2 2020/01/23 05:40:09 ratchov Exp $ */
/*
* Copyright (c) 2015 Alexandre Ratchov <alex@caoua.org>
*
@@ -25,7 +25,7 @@ void fdpass_close(struct fdpass *f);
extern struct fileops worker_fileops, helper_fileops;
extern struct fdpass *fdpass_peer;
-struct sio_hdl *fdpass_sio_open(int, unsigned int);
-struct mio_hdl *fdpass_mio_open(int, unsigned int);
+struct sio_hdl *fdpass_sio_open(int, int, unsigned int);
+struct mio_hdl *fdpass_mio_open(int, int, unsigned int);
#endif /* !defined(FDPASS_H) */
diff --git a/usr.bin/sndiod/miofile.c b/usr.bin/sndiod/miofile.c
index 3c2d56db4aa..bf6feb8071b 100644
--- a/usr.bin/sndiod/miofile.c
+++ b/usr.bin/sndiod/miofile.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: miofile.c,v 1.5 2019/09/21 04:42:46 ratchov Exp $ */
+/* $OpenBSD: miofile.c,v 1.6 2020/01/23 05:40:09 ratchov Exp $ */
/*
* Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
*
@@ -45,10 +45,41 @@ struct fileops port_mio_ops = {
port_mio_hup
};
+/*
+ * open the port using one of the provided paths
+ */
+static struct mio_hdl *
+port_mio_openlist(struct port *c, unsigned int mode)
+{
+ struct mio_hdl *hdl;
+ struct name *n;
+ int idx;
+
+ idx = 0;
+ n = c->path_list;
+ while (1) {
+ if (n == NULL)
+ break;
+ hdl = fdpass_mio_open(c->num, idx, mode);
+ if (hdl != NULL) {
+ if (log_level >= 2) {
+ port_log(c);
+ log_puts(": using ");
+ log_puts(n->str);
+ log_puts("\n");
+ }
+ return hdl;
+ }
+ n = n->next;
+ idx++;
+ }
+ return NULL;
+}
+
int
port_mio_open(struct port *p)
{
- p->mio.hdl = fdpass_mio_open(p->num, p->midi->mode);
+ p->mio.hdl = port_mio_openlist(p, p->midi->mode);
if (p->mio.hdl == NULL)
return 0;
p->mio.file = file_new(&port_mio_ops, p, "port", mio_nfds(p->mio.hdl));
@@ -64,7 +95,7 @@ port_mio_reopen(struct port *p)
{
struct mio_hdl *hdl;
- hdl = fdpass_mio_open(p->num, p->midi->mode);
+ hdl = port_mio_openlist(p, p->midi->mode);
if (hdl == NULL) {
if (log_level >= 1) {
port_log(p);
diff --git a/usr.bin/sndiod/siofile.c b/usr.bin/sndiod/siofile.c
index c720c61bab6..2579e7d0ce1 100644
--- a/usr.bin/sndiod/siofile.c
+++ b/usr.bin/sndiod/siofile.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: siofile.c,v 1.16 2019/09/21 04:42:46 ratchov Exp $ */
+/* $OpenBSD: siofile.c,v 1.17 2020/01/23 05:40:09 ratchov Exp $ */
/*
* Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
*
@@ -85,6 +85,37 @@ dev_sio_timeout(void *arg)
}
/*
+ * open the device using one of the provided paths
+ */
+static struct sio_hdl *
+dev_sio_openlist(struct dev *d, unsigned int mode)
+{
+ struct name *n;
+ struct sio_hdl *hdl;
+ int idx;
+
+ idx = 0;
+ n = d->path_list;
+ while (1) {
+ if (n == NULL)
+ break;
+ hdl = fdpass_sio_open(d->num, idx, mode);
+ if (hdl != NULL) {
+ if (log_level >= 2) {
+ dev_log(d);
+ log_puts(": using ");
+ log_puts(n->str);
+ log_puts("\n");
+ }
+ return hdl;
+ }
+ n = n->next;
+ idx++;
+ }
+ return NULL;
+}
+
+/*
* open the device.
*/
int
@@ -93,15 +124,15 @@ dev_sio_open(struct dev *d)
struct sio_par par;
unsigned int mode = d->mode & (MODE_PLAY | MODE_REC);
- d->sio.hdl = fdpass_sio_open(d->num, mode);
+ d->sio.hdl = dev_sio_openlist(d, mode);
if (d->sio.hdl == NULL) {
if (mode != (SIO_PLAY | SIO_REC))
return 0;
- d->sio.hdl = fdpass_sio_open(d->num, SIO_PLAY);
+ d->sio.hdl = dev_sio_openlist(d, SIO_PLAY);
if (d->sio.hdl != NULL)
mode = SIO_PLAY;
else {
- d->sio.hdl = fdpass_sio_open(d->num, SIO_REC);
+ d->sio.hdl = dev_sio_openlist(d, SIO_REC);
if (d->sio.hdl != NULL)
mode = SIO_REC;
else
@@ -231,7 +262,7 @@ dev_sio_reopen(struct dev *d)
struct sio_par par;
struct sio_hdl *hdl;
- hdl = fdpass_sio_open(d->num, d->mode & (MODE_PLAY | MODE_REC));
+ hdl = dev_sio_openlist(d, d->mode & (MODE_PLAY | MODE_REC));
if (hdl == NULL) {
if (log_level >= 1) {
dev_log(d);
diff --git a/usr.bin/sndiod/utils.c b/usr.bin/sndiod/utils.c
index 75b709ed612..118f2366b84 100644
--- a/usr.bin/sndiod/utils.c
+++ b/usr.bin/sndiod/utils.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: utils.c,v 1.6 2019/09/21 04:42:46 ratchov Exp $ */
+/* $OpenBSD: utils.c,v 1.7 2020/01/23 05:40:09 ratchov Exp $ */
/*
* Copyright (c) 2003-2012 Alexandre Ratchov <alex@caoua.org>
*
@@ -215,3 +215,20 @@ namelist_clear(struct name **list)
xfree(n);
}
}
+
+char *
+namelist_byindex(struct name **list, unsigned int idx)
+{
+ struct name *n;
+
+ n = *list;
+ while (1) {
+ if (n == NULL)
+ return NULL;
+ if (idx == 0)
+ break;
+ n = n->next;
+ idx--;
+ }
+ return n->str;
+}
diff --git a/usr.bin/sndiod/utils.h b/usr.bin/sndiod/utils.h
index 62042c96164..ef589f673b7 100644
--- a/usr.bin/sndiod/utils.h
+++ b/usr.bin/sndiod/utils.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: utils.h,v 1.4 2019/09/21 04:42:46 ratchov Exp $ */
+/* $OpenBSD: utils.h,v 1.5 2020/01/23 05:40:09 ratchov Exp $ */
/*
* Copyright (c) 2003-2012 Alexandre Ratchov <alex@caoua.org>
*
@@ -38,6 +38,7 @@ void xfree(void *);
void namelist_add(struct name **, char *);
void namelist_clear(struct name **);
+char *namelist_byindex(struct name **, unsigned int);
/*
* Log levels: