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

feat: match p9p namespace calculation by respecting NAMESPACE and DISPLAY #62

Closed

Conversation

sternenseemann
Copy link
Contributor

With this PR, the ninep crate should default to the same namespace as plan9port utilities in all cases, i.e. match getns.c.

This entails the following, technically breaking, changes

  1. ad will now crash on startup if DISPLAY (and also NAMESPACE) is not set. This could be made a bit nicer by threading the error through which I haven't done yet.
  2. ninep uses PathBuf in some places now. This is an API breaking change, so probably needs a semver bump. I don't know how this is managed at the moment, so I haven't done anything on this front.
  3. mount-ad needs the namespace(1) utility from plan9port additionally now.

Since this is unix specific, I'm basing this on 9p(1), namespace(1) and
intro(4) from plan9port.

- The namespace is the /tmp/ns.$USER.$DISPLAY directory that consists
  of unix sockets to various 9p servers (without any nesting).
- This can be used by e.g. 9p(1) to create the illusion of a coherent
  namespace where you can 9p read foo/bar which actually dispatches
  to the singular /tmp/ns.$USER.$DISPLAY/foo socket.

I've called the first path component, which always needs to be given
`server_name`. I don't know if it has a more specific term in plan9port,
though. My main aim is to prevent a confusion with namespace which (in
plan9port) refers to the directory that contains the 9p unix sockets.
The behavior should not have changed yet, but this gives us the ability
to implement support for NAMESPACE in a central place.
The use of String for most things 9p is a good fit since its messages
use UTF-8 encoding. The namespace is a POSIX path, though, and may
theoretically be an arbitrary byte sequence, so it's better to use
PathBuf (and OsString). Doing this consistently in ninep should also
create a nice distinction between 9p paths and POSIX paths via their
types.

Additionally, we no longer need to duplicate logic between socket_path()
and unix_socket() in server because we can use PathBuf::parent().
Match plan9port's behavior for determining the namespace:

- If NAMESPACE is set, use its value.
- Otherwise, use a combination of username and the value of the
  DISPLAY variable.
- Remaining divergences:
  - ninep falls back to :0 if DISPLAY is unset.
  - ninep uses the USER environment variable for determining the user
    name whereas plan9port uses getuid(3).
This means that 9p(1) and ad will behave the same now, unless $USER and
getuid() diverge.
@sminez
Copy link
Owner

sminez commented Dec 15, 2024

@sternenseemann as with the previous PR you opened, please can you raise issues to discuss changes like this rather than opening a PR with a breaking change like this. Particularly for anything around the 9p support, if what you are after is compatibility with other implementations then that is likely going to be quite involved as the current support is pretty minimal.

I don't currently have any contribution guidelines for this repo but that is largely because (as stated quite clearly at the start of the readme) this project is very much in its early stages and not really something that is suitable for external contribution. I'll add some more explicit details about this today to make that clearer.

@sminez sminez closed this Dec 15, 2024
@sternenseemann
Copy link
Contributor Author

with a breaking change like this

Can you clarify what breaking change you have a problem with. I'm happy to redesign this change in a way that the API of the ninep crate does not change. We can also make the unix module private so that we don't commit to anything there.

The behavorial changes are unproblematic in my opinion because in cases where it'd cause ad to behave differently, ad would be partially broken without them. The changes affect situations where the 9p tool and ad would decide on different namespace directories or 9p fail to come up with any directory. Since practically all editor functionality implemented in scripts relies on 9p, much of the editor would not work properly—so nothing really breaks.

if what you are after is compatibility with other implementations then that is likely going to be quite involved

All I wanted to implement with this change is to match the behavior of plan9port for determining the namespace directory used to contain the 9p servers' unix type sockets. Here, plan9port is the canonical implementation, I'd say. This PR matches the behavior of gentns.c exactly, so there's nothing left to do as far as I'm aware.

What I'm personally after is that I can just set NAMESPACE to an arbitrary directory and have 9p and ad work properly since I'm on wayland and don't have DISPLAY set.

@sminez
Copy link
Owner

sminez commented Dec 17, 2024

I'm just referring to the changes you listed in your PR description. The ninep one around pathbufs isn't too bad as you have pointed out as there are multiple ways to modify what you have here so that it isn't a breaking change to the public API, but ad crashing on startup if those environment variables aren't set is a problem. Yes the extension functionality doesn't work without 9p but the editor as a whole should still function without it (albeit with far fewer features) so I would prefer instead to show an error in the status bar or log for the user if that is the case.

Having the mount-ad script require additional utilities from plan9port also isn't great. Having to have 9p installed for the existing helper scripts was mentioned in #51 and as I said there, I'd much rather get to a point where ad can be used as a 9p client itself than for users to have to install all of plan9port in order for things to work.

In principal I'm not against a change like this (accounting for the concerns I've outlined above) but what I'm not keen on is PRs where what is being proposed is a change to the codebase without any explanation of why that change is needed / desired.

What I'm personally after is that I can just set NAMESPACE to an arbitrary directory and have 9p and ad work properly since I'm on wayland and don't have DISPLAY set.

This is something that makes sense to me and something that I'll happily discuss in an issue if support for Wayland and compatibility with existing 9p clients is what you are after. As I have mentioned previously and as is hopefully made clear in the README, this project is very much expected to have numerous rough edges at the moment. I don't currently have things set up in a way that makes it clear to others what the ongoing work I'm doing is looking like or what aspects of the design I am / am not open to modifying at the moment. All I'm asking is that changes beyond simple bugfixes (such as #59) as first raised as issues for discussion rather opened as PRs.

I hope this all makes sense 🙂

@sternenseemann
Copy link
Contributor Author

but ad crashing on startup if those environment variables aren't set is a problem

That can easily be changed by dropping c51eb5b from this PR.

Having the mount-ad script require additional utilities from plan9port also isn't great.

I figured it would not be a big deal since we already need 9p and 9pfuse. Implementing the necessary logic with POSIX shell variable expansions should also be possible. When making the change, I just wasn't liking the idea of reimplementing the same thing another time…

I did have the idea that ad could set NAMESPACE for its child processes, so that would eliminate the need for that, actually. I'll write that up.

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

Successfully merging this pull request may close these issues.

2 participants