diff options
author | 2019-07-12 06:30:55 +0000 | |
---|---|---|
committer | 2019-07-12 06:30:55 +0000 | |
commit | 2988007f00e101878bce0101d22306712e4f23f0 (patch) | |
tree | c24541ba8794885d06fde080a22b8651313703ea | |
parent | include SHA2-variant RSA key algorithms in KEX proposal; allows (diff) | |
download | wireguard-openbsd-2988007f00e101878bce0101d22306712e4f23f0.tar.xz wireguard-openbsd-2988007f00e101878bce0101d22306712e4f23f0.zip |
Add affinity between the program and its mixer control.
Currently, if there are two instances of the same program, sndiod will
allocate one volume control to each. If both programs disconnect and
reconnect, the information of which control is assigned to which
program is lost. This makes difficult to run two instances of a player
and crossfade between each other with a MIDI controller.
To address this, the program chooses a 32-bit "id" (for now the
process pid) and sends it to the server. The server records the id in
the client's slot structure. When the server accepts a new
connection, it uses the id to identify the slot the client used during
the previous connection; if it was not recycled yet, it's assigned to
the program.
-rw-r--r-- | lib/libsndio/amsg.h | 4 | ||||
-rw-r--r-- | lib/libsndio/aucat.c | 3 | ||||
-rw-r--r-- | usr.bin/sndiod/dev.c | 18 | ||||
-rw-r--r-- | usr.bin/sndiod/dev.h | 5 | ||||
-rw-r--r-- | usr.bin/sndiod/sock.c | 6 |
5 files changed, 26 insertions, 10 deletions
diff --git a/lib/libsndio/amsg.h b/lib/libsndio/amsg.h index 760f7ec7ad8..a22ea0e1078 100644 --- a/lib/libsndio/amsg.h +++ b/lib/libsndio/amsg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: amsg.h,v 1.11 2018/07/28 09:07:48 ratchov Exp $ */ +/* $OpenBSD: amsg.h,v 1.12 2019/07/12 06:30:55 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -99,7 +99,7 @@ struct amsg { #define AMSG_VERSION 7 uint8_t version; /* protocol version */ uint8_t devnum; /* device number */ - uint32_t _reserved[1]; /* for future use */ + uint32_t id; /* client id */ #define AMSG_OPTMAX 12 char opt[AMSG_OPTMAX]; /* profile name */ char who[12]; /* hint for leases */ diff --git a/lib/libsndio/aucat.c b/lib/libsndio/aucat.c index b418f4e0fdd..4b86ed3fdb2 100644 --- a/lib/libsndio/aucat.c +++ b/lib/libsndio/aucat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: aucat.c,v 1.76 2019/06/29 06:05:26 ratchov Exp $ */ +/* $OpenBSD: aucat.c,v 1.77 2019/07/12 06:30:55 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -486,6 +486,7 @@ _aucat_open(struct aucat *hdl, const char *str, unsigned int mode) hdl->wmsg.u.hello.version = AMSG_VERSION; hdl->wmsg.u.hello.mode = htons(mode); hdl->wmsg.u.hello.devnum = devnum; + hdl->wmsg.u.hello.id = htonl(getpid()); strlcpy(hdl->wmsg.u.hello.who, __progname, sizeof(hdl->wmsg.u.hello.who)); strlcpy(hdl->wmsg.u.hello.opt, opt, diff --git a/usr.bin/sndiod/dev.c b/usr.bin/sndiod/dev.c index fd4a8c683ed..029fefded5d 100644 --- a/usr.bin/sndiod/dev.c +++ b/usr.bin/sndiod/dev.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dev.c,v 1.53 2019/07/10 14:30:39 ratchov Exp $ */ +/* $OpenBSD: dev.c,v 1.54 2019/07/12 06:30:55 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org> * @@ -1527,7 +1527,7 @@ slot_freebufs(struct slot *s) * allocate a new slot and register the given call-backs */ struct slot * -slot_new(struct dev *d, struct opt *opt, char *who, +slot_new(struct dev *d, struct opt *opt, unsigned int id, char *who, struct slotops *ops, void *arg, int mode) { char *p; @@ -1563,12 +1563,23 @@ slot_new(struct dev *d, struct opt *opt, char *who, } /* + * find the free slot with the least unit number and same id + */ + for (i = 0; i < DEV_NSLOT; i++) { + s = unit[i]; + if (s != NULL && s->ops == NULL && s->id == id) + goto found; + } + + /* * find the free slot with the least unit number */ for (i = 0; i < DEV_NSLOT; i++) { s = unit[i]; - if (s != NULL && s->ops == NULL) + if (s != NULL && s->ops == NULL) { + s->id = id; goto found; + } } /* @@ -1594,6 +1605,7 @@ slot_new(struct dev *d, struct opt *opt, char *who, for (i = 0; unit[i] != NULL; i++) ; /* nothing */ s->unit = i; + s->id = id; goto found; } diff --git a/usr.bin/sndiod/dev.h b/usr.bin/sndiod/dev.h index 00753906b74..bd909060bdf 100644 --- a/usr.bin/sndiod/dev.h +++ b/usr.bin/sndiod/dev.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dev.h,v 1.20 2018/06/26 07:44:35 ratchov Exp $ */ +/* $OpenBSD: dev.h,v 1.21 2019/07/12 06:30:55 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org> * @@ -89,6 +89,7 @@ struct slot { unsigned int unit; /* instance of name */ unsigned int serial; /* global unique number */ unsigned int vol; /* current (midi) volume */ + unsigned int id; /* process id */ }; struct opt { @@ -231,7 +232,7 @@ void dev_midi_vol(struct dev *, struct slot *); * sio_open(3) like interface for clients */ void slot_log(struct slot *); -struct slot *slot_new(struct dev *, struct opt *, char *, +struct slot *slot_new(struct dev *, struct opt *, unsigned int, char *, struct slotops *, void *, int); void slot_del(struct slot *); void slot_setvol(struct slot *, unsigned int); diff --git a/usr.bin/sndiod/sock.c b/usr.bin/sndiod/sock.c index b11de472ce8..6bc800c4fa5 100644 --- a/usr.bin/sndiod/sock.c +++ b/usr.bin/sndiod/sock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sock.c,v 1.30 2019/06/29 21:23:18 ratchov Exp $ */ +/* $OpenBSD: sock.c,v 1.31 2019/07/12 06:30:55 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org> * @@ -768,8 +768,10 @@ sock_hello(struct sock *f) struct dev *d; struct opt *opt; unsigned int mode; + unsigned int id; mode = ntohs(p->mode); + id = ntohl(p->id); #ifdef DEBUG if (log_level >= 3) { sock_log(f); @@ -841,7 +843,7 @@ sock_hello(struct sock *f) opt = opt_byname(d, p->opt); if (opt == NULL) return 0; - f->slot = slot_new(d, opt, p->who, &sock_slotops, f, mode); + f->slot = slot_new(d, opt, id, p->who, &sock_slotops, f, mode); if (f->slot == NULL) return 0; f->midi = NULL; |