Skip to content

Toy project to mess with passing file descriptors over UNIX-domain sockets

Notifications You must be signed in to change notification settings

awiddersheim/fd-pass

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fd-pass

Project to mess around with passing file descriptors between applications using UNIX-domain sockets and SCM_RIGHTS. Some of the C code was taken from this amazing Cloudflare blog article. The Python code was inspired by the Python docs as well as bits from the standard library. Also, credit to Cindy Sridharan for inspiring me to mess around with this.

It was interesting to discover that Python 3.9 added support for this into the core socket module. It has also existed for some time in the multiprocessing.reduction module but is not very well documented.

This implementation is pretty naive and more of a toy than anything so I'm sure it has quite a few sharp edges that weren't accounted for or were not evident when writing.

      -----------------------------------
      |             |                   |
      V     +-------------+     +---------------+
      o/    |             |     |               |
User /| --> | Quarterback | --> | Wide Receiver |
     / \    |             |     |               |
            +-------------+     +---------------+

Table of Contents

Quickstart

Start by running the Wide Receiver first. This is the last element depicted in the flow above. It gets passed the user's file descriptor from Quarterback.

$ python3 wr.py

Now, start Quarterback.

$ ./qb

Finally, connect with nc to see the magic. Whatever is typed should be echoed back.

$ nc localhost 8000

Output should look like the following:

User

$ nc localhost 8000
Hello from Quarterback on PID (373)!
Hello from Wide Receiver on PID (520)!
foo
foo
bar
bar

Quarterback

$ ./qb
Starting Quarterback with PID (373)
Connecting to UNIX socket (fd-pass.sock)
Connected to UNIX socket (fd-pass.sock)
Listening on 0.0.0.0:8000
Handling connection from (127.0.0.1:60316)
Closing connection from (127.0.0.1:60316)
^CProcessing signal (Interrupt: 2)
Shutting down

Wide Receiver

$ python wr.py
Starting Wide Receiver on PID (520)
Listening for messages on (fd-pass.sock)
Handling connection from (fd-pass.sock)
Handling connection from (127.0.0.1:60316)
Closing connection from (127.0.0.1:60316)
Connection on (fd-pass.sock) closed
^CProcessing signal (SIGINT)
Shutting down

Building

Docker

TODO

Manual

Builds use gcc.

$ make

Developing

TODO

Testing

TODO

Communication

TODO

Contributing

TODO

About

Toy project to mess with passing file descriptors over UNIX-domain sockets

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published