Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why is it not recommended to just run tmux under reattach-to-user-namespace? #59

Closed
casey opened this issue Feb 20, 2017 · 3 comments
Closed

Comments

@casey
Copy link

casey commented Feb 20, 2017

Instead of changing the default-command to wrap ones shell in reattach-to-user-namespace, as well as wrapping pbcopy and pbpaste in reattach-to-user-namespace, would it instead be possible to just invoke tmux as reattach-to-user-namespace tmux?

@ChrisJohnsen
Copy link
Owner

Access to the per-user bootstrap namespace is revoked when tmux uses the daemon(3) library function to put itself into the background. The “reattaching” needs to happen after the daemonization, but before programs try to access services through the per-user bootstrap namespace. The earliest user-configurable place to do this is default-command (and copy-pipe, and programs started by run-shell, et cetera).

There is no need to “reattach” before the tmux server is started, and “reattaching” individual clients will not help because the tmux server is what starts programs for the panes/windows/sessions/copy-pipe/run-shell/et cetera.

It might be possible to have the tmux server “reattach” itself. This would certainly be cleaner and easier for the user. But (as describe in #17) I do not recommend this since the required API calls are undocumented and unsupported (and change in various ways from release to release of Mac OS).

@casey
Copy link
Author

casey commented Feb 20, 2017

Thanks for the detailed explanation!

Do you think it would be worth while for tmux to provide some kind of hook which allows for running the server inside of a user specified wrapper?

I understand not wanting to upstream to tmux, given that the API calls are undocumented and unsupported, so this could be a nice compromise.

For example, you could then have in your tmux config:

set -g start-server-command 'reattach-to-user-namespace tmux start-server'

Which would solve the problem in one place.

@ChrisJohnsen
Copy link
Owner

It would probably be complicated to arrange for tmux (or any other arbitrary program) to do something like that while still using the exec-based interface.

The exec-based wrapper slots into an area of starting a new process where nearly all the information that needs to be passed along is in well defined locations that are easy to give to a new process: the command line arguments, the environment, previously-opened file descriptors (e.g. stdin/out/err), et cetera. But inserting an exec-based “wrapper” into the middle of a program would potentially require serialization and deserialization of much more information (e.g. memory state and an indication of where to resume execution). Specially designed programs could make it easier to do this by minimizing the amount of state that needed to be serialized and deserialized, but I doubt it would be worth it to try to retrofit tmux to work like this.

Some sort of dynamically loadable “plugin“ system would seem like a better fit. tmux could dynamically load user-configured shared libraries (e.g. a tmux_reattach_to_user_namespace.dylib) and later directly execute functions from them (e.g. _tmux_after_server_daemonized, or _tmux_after_session_attached, et cetera). Unless there were other strong use cases though, I doubt that this Mac OS–only issue would be reason enough to implement such a system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants