diff options
author | Peter Bridgman <git@p-b.me> | 2021-08-14 16:24:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-14 16:24:41 +0100 |
commit | 1ab3445e65ec2bfc1ba8562984822616e03fb9fe (patch) | |
tree | 82a4b91598fae8d08d541f7f95352d74fdb8db70 /macosx/JackMachUtils.h | |
parent | c742b430fb3414694eaf323be1b27a8b56f611cd (diff) | |
download | jack2-1ab3445e65ec2bfc1ba8562984822616e03fb9fe.tar.gz |
macOS: Pass JackMachSemaphore send right via mach_msg IPC (#788)
* macOS: Pass JackMachSemaphore send right via mach_msg IPC
Previously, JackMachSemaphore would communicate the send right for the
semaphore object from the server to a client via a named service
registered via `bootstrap_register`. However, to do this, it would
register the semaphore's port as the service port directly.
In theory this ought to be fine, however in practice, macOS `launchd`,
which provides the `bootstrap_register` interface, does not correctly
detect when such a port becomes dead, and incorrectly believes that the
service that it provides is forever alive, even past the end of the
`jackd` process' (and therefore the semaphore's) existence. This seems
to be *specific* to semaphore ports, as `launchd` is expecting a
standard IPC port, owned by the task, not the kernel. This prevents
`jackd` from later registering another service with the same name, as
`launchd` rejects the registration as conflicting with an active service.
To get around this, `jackd` previously added a counter to the end of the
named service registrations, allowing old services to remain in the
system until the end of the session. To prevent things getting out of
hand, this was capped at 98 service registrations for a given semaphore
name. This led to #784, in which running a client for the 99th time
resulted in the semaphore creation failing and the client failing to
connect.
As `launchd` outlives multiple runs of `jackd`, this situation persisted
across restarts of `jackd`, requiring a restart of the user's session
(i.e. a reboot) to fix.
An initial attempt at fixing this (see #785) tried passing the port
rights directly via shared memory, however mach is too clever for us and
foils that plan by having port names be looked up in a per-task table
(sensible when you think about it).
In this commit, we use mach IPC messages to transfer the send right for
the semaphore from the server to the client. By registering a standard
IPC port with the bootstrap server, the service registrations are
correctly torn down when the ports are destroyed.
It works something like this:
* Server creates IPC port and registers it globally via `bootstrap_register`
* Server listens on IPC port for messages
* Client looks up IPC port via `bootstrap_look_up`
* Client sends it a message
* Server replies with a message containing a send right to the
semaphore's port
* Client is then free to use the semaphore port as before.
This resolves #784.
* Improve error handling
* Add myself to Authors
Diffstat (limited to 'macosx/JackMachUtils.h')
-rw-r--r-- | macosx/JackMachUtils.h | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/macosx/JackMachUtils.h b/macosx/JackMachUtils.h new file mode 100644 index 00000000..b9cbf59f --- /dev/null +++ b/macosx/JackMachUtils.h @@ -0,0 +1,36 @@ +/* +Copyright (C) 2021 Peter Bridgman + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#ifndef __JackMachUtils__ +#define __JackMachUtils__ + +#define jack_mach_error_uncurried(type_name, kern_return, message) \ + jack_error(type_name "::%s: " message " - %i:%s", \ + __FUNCTION__, \ + kern_return, \ + mach_error_string(kern_return)) + +#define jack_mach_bootstrap_err_uncurried(type_name, kern_return, message, service_name) \ + jack_error(type_name "::%s: " message " [%s] - %i:%s", \ + __FUNCTION__, \ + service_name, \ + kern_return, \ + bootstrap_strerror(kern_return)) + +#endif |