-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add support for connecting via UNIX socket #63
Conversation
|
||
fifodir=$(mktemp -d) && \ | ||
mkfifo "$fifodir/in" "$fifodir/out" && \ | ||
( (nc -U "$unix" < "$fifodir/in" > "$fifodir/out" &) &) && \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if I should be doing something smarter than nothing with the stderr of nc
; maybe direct it to a file in the fifodir
and cat it out if there's a connection error?
exit 1 | ||
connect_status=$? | ||
|
||
[ -d "$fifodir" ] && rm -rf "$fifodir" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After everything is connected we can just trash the fifodir
immediately, as everything has its file descriptors open and nothing else will need to refer to anything there by name again.
exit 1 | ||
fi | ||
else | ||
exec 3<> "/dev/tcp/$host/$port" && exec 4>&3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately I wasn't able to figure out how to get read and write to the socket happening on the same file descriptor, so I had to split them, and that meant splitting them even in the TCP case :(
Nice! Thank you! I have to play around with this a little before merging :-) |
Cool, I might iterate a bit more on this later tonight to tighten up the error checking and add |
Btw.: what i am always wondering when writing a shell script -- is there a "best-practice" to check command compatibility? Eg. to verify that |
@aurora I'm not sure what the best way to detect a
If you don't think that's too big of a chunk of Perl to embed, I think a lot more systems are going to have |
Cool. I am undecided whether to include it, though: someone could come up with the question, why rmate wasn't implemented as perl script, instead ;) ... i have to think about this ... too bad, that this can't be done in 100% bash :( ... |
Yeah I was really surprised that bash can connect to TCP sockets on its own but not UNIX ones. If you'd like, I could rework this as a sort of "generic proxy command" support, and leave out any opinions on what that proxy command should be. I could then document examples of how to use |
@jordemort thought a little more on this, yes i think if you could rework this as "generic proxy command" support and would write an example in the README, that would be awesome. I think in this case we could also include your perl-client as example as standalone script in this repository. Would this be ok for you? |
Sounds good! |
@jordemort cool! looking forward to it ... |
@aurora Hey I do intend to come back to this, just have a lot of different things I'm hacking on right now. Hopefully by the end of August :D |
@jordemort no problem, i fully understand -- so i am looking forward to end of august or early september ;) |
@jordemort Textmate does support unix socket, see textmate/rmate#38 Is this compatible with it? |
@randy3k Should be; same protocol, different transport |
@jordemort Hey, ... i am still interested in having this feature in rmate :). I think i could also help with this, if you do not have time for further development regarding this. Am i right, that it would be "just" a matter of replacing the |
@aurora Sorry, I have really still been intending to get back to this, but there are a great many things going on for me right now. You're correct, all that would be needed is to replace |
@jordemort no worries, i totally understand. No need to hurry, I am currently just between two projects, so i have some spare time to work on rmate. Thanks! |
This adds support for connecting via a UNIX socket. I am not aware of any editors that actually implement listening on a UNIX socket, but recent versions of OpenSSH are capable of forwarding a remote socket to a local TCP port, which is how I'm using it. It's nice to have the option for a bit more privacy if you're SSHing into a shared machine, and a bit easier to script around contention between multiple sessions all wanting to forward the same socket.
The socket path can be specified via
unix
in the config file,-u
or--unix
on the command-line, or in theRMATE_UNIX
environment variable.This implementation requires that a version of
nc
that understands the-U
option is installed; unfortunately,bash
doesn't seem to have a facility for connecting to UNIX sockets like it does for TCP sockets. It could also be implemented in terms ofsocat
or possibly other tools. I'm not sure if it's worth implementing a fallback or some way to customize the command used to connect to the socket; I'd be willing to look into that if there's interest.