Skip to content

socket.send_fds and socket.recv_fds ignore optional arguments ('flags' and 'address'). #107898

@miccoli

Description

@miccoli

Bug report

The implementation of socket.send_fds does not pass flags and address down to sock.sendmsg:

cpython/Lib/socket.py

Lines 553 to 559 in bf70774

def send_fds(sock, buffers, fds, flags=0, address=None):
""" send_fds(sock, buffers, fds[, flags[, address]]) -> integer
Send the list of file descriptors fds over an AF_UNIX socket.
"""
return sock.sendmsg(buffers, [(_socket.SOL_SOCKET,
_socket.SCM_RIGHTS, array.array("i", fds))])

The fix seems trivial, I can submit a PR.

Checklist

  • I am confident this is a bug in CPython, not a bug in a third-party project
  • I have searched the CPython issue tracker, and am confident this bug has not been reported before

A clear and concise description of the bug

import os
import socket

sock = socket.socket(family=socket.AF_UNIX, type=socket.SOCK_DGRAM)
fd = os.memfd_create("journal_entry")

socket.send_fds(sock=sock, buffers=[], fds=[fd], address="/run/systemd/journal/socket")

fails with

    return sock.sendmsg(buffers, [(_socket.SOL_SOCKET,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [Errno 107] Transport endpoint is not connected

Your environment

  • CPython versions tested on: 3.11.3
  • Operating system and architecture: Linux-6.1.43-1-rpi-ARCH-armv7l-with-glibc2.35

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions