You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
sendmsg(2) and recvmsg(2) allow the exchange of out-of-band "ancillary data", such as file descriptors and errors. These messages are created and accessed using the CMSG_* macros (see the cmsg(3) man page). Some packages, such as erlang/OTP, use these messages to communicate file descriptors over unix domain sockets. The passage of file descriptors, using type SCM_RIGHTS, may require some special handling beyond simple copying, as queueing a file descriptor is actually storing a reference to the object being described, not the descriptor numbers themselves. (e.g. on a multi-process system, an fd written by one process may be read as a different fd by another process - yet both refer to the same object) Also, the writing of descriptors should count as a reference to the underlying object, as the descriptors may be closed after writing ancillary data containing them - while still allowing the receiving end to read open descriptors.
It has not been done, transfer of ancillary data through Unix domain socket is still not implemented. For example, if you try to run a Ruby application that uses the send_io or recv_iomethods of the UNIXSocket class, you will get a [BUG] rb_maygvl_fd_fix_cloexec: fcntl(-2075168, F_GETFD) failed: Bad file descriptor error message, due to the fact that the file descriptor that the application expects to receive as ancillary data in the socket is not being transferred. How to reproduce:
install Ruby on your machine
create a file named send_io.rb with these contents:
require 'socket'
s1, s2 = UNIXSocket.pair
s1.send_io STDOUT
stdout = s2.recv_io
p STDOUT.fileno #=> 1
p stdout.fileno #=> 6
stdout.puts "hello" # outputs "hello\n" to standard output.
create a file named config.json with these contents (adjust the file paths to match your Ruby installation directory):
sendmsg(2) and recvmsg(2) allow the exchange of out-of-band "ancillary data", such as file descriptors and errors. These messages are created and accessed using the CMSG_* macros (see the cmsg(3) man page). Some packages, such as erlang/OTP, use these messages to communicate file descriptors over unix domain sockets. The passage of file descriptors, using type SCM_RIGHTS, may require some special handling beyond simple copying, as queueing a file descriptor is actually storing a reference to the object being described, not the descriptor numbers themselves. (e.g. on a multi-process system, an fd written by one process may be read as a different fd by another process - yet both refer to the same object) Also, the writing of descriptors should count as a reference to the underlying object, as the descriptors may be closed after writing ancillary data containing them - while still allowing the receiving end to read open descriptors.
References:
https://www.man7.org/linux/man-pages/man3/cmsg.3.html
https://blog.cloudflare.com/know-your-scm_rights/
The text was updated successfully, but these errors were encountered: