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

conn: do not chdir for conn.sock #581

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Open

Conversation

mrdomino
Copy link
Contributor

@mrdomino mrdomino commented Jan 5, 2024

Instead, we create the socket in a temporary directory - TMPDIR if it is not too long, or else /tmp. The directory is made via mkdtemp with the template urbit-XXXXXX. The socket is located there (getting around the length limit) and $pier/.urb/conn.sock is symlinked to it.

This fixes an issue where if urbit is started with sudo -u pieruser from a directory that the pier user doesn't have access to (e.g. a different user's home directory that is chmod 0750), the process would die trying to chdir back to the old directory.

It also gives clients more flexibility; previously, they would have had to chdir to the pier directory to connect to the socket without risking overrunning the length limit. They can still do that (and use ".urb/conn.sock" as their sun_path), but they now also have the option of using readlink and connecting to the full absolute path of the socket without changing directories.

Replaces calls to uv_strerror with strerror for system calls; the former does not print system call errors properly.

Supersedes #580.

Instead, we create the socket in a temporary directory - TMPDIR if it is
not too long, or else /tmp. The directory is made via `mkdtemp` with the
template `urbit-XXXXXX`. The socket is located there (getting around the
length limit) and `$pier/.urb/conn.sock` is symlinked to it.

Replaces calls to uv_strerror with strerror for system calls; the former
does not print system call errors properly.
@mrdomino mrdomino requested a review from a team as a code owner January 5, 2024 02:12
The pier socket link is predictable; no information is conveyed by
printing it.
@mrdomino
Copy link
Contributor Author

mrdomino commented Jan 5, 2024

I'm actually indifferent as to whether this or #580 is taken. I think this is a slightly better solution, since it allows clients to always be able to specify the full absolute path to the socket when connecting to it. But either way is fine.

@mrdomino
Copy link
Contributor Author

mrdomino commented Jan 8, 2024

@pkova Are you the right person to review this?

Now uv_close is never needed as part of failure cleanup. N.B. this can
be moved before the close to keep the cleanup logic stacked.
Also handles 0-length TMPDIR.
@mrdomino
Copy link
Contributor Author

mrdomino commented Jan 8, 2024

Oh, I guess now there's also lick.c.

In that case the temporary directory should probably be stored on u3_Host or u3C or something and created in main.c. Right?

@mrdomino
Copy link
Contributor Author

@mopfel-winrux how do you want to handle %lick? I don't have much insight yet into what it's doing. Would it make sense for it to follow suit with this change and use a tmp directory for its sockets?

If not, then the next best thing is probably to reopen #580 and also apply that to lick.c.

Copy link
Contributor

@ashelkovnykov ashelkovnykov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but flagged one thing

}
memcpy(tad_c + len_w + sizeof("/urbit-XXXXXX") - 1, "/conn.sock",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The string "/urbit-XXXXXX" gets reused a lot, we should make it a constant or macro

@mopfel-winrux
Copy link
Contributor

@mrdomino I'm sorry I completely missed this. We should also do this for lick.c

@mrdomino
Copy link
Contributor Author

mrdomino commented Mar 11, 2024 via email

@mopfel-winrux
Copy link
Contributor

It makes multiple sockets. One per [%spin name=path] card it is given. It puts them in `.urb/dev/ folder under the name path. we could use that directory

@mrdomino
Copy link
Contributor Author

mrdomino commented Mar 11, 2024 via email

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.

3 participants