Skip to content

Adding containerized environment support socket path communication with frontend#65

Merged
tillkamppeter merged 33 commits intoOpenPrinting:masterfrom
Souptik-De:master
Apr 27, 2026
Merged

Adding containerized environment support socket path communication with frontend#65
tillkamppeter merged 33 commits intoOpenPrinting:masterfrom
Souptik-De:master

Conversation

@Souptik-De
Copy link
Copy Markdown

@Souptik-De Souptik-De commented Apr 21, 2026

  • We start the document only after obtaining the client fd (after accept() for the legacy path, or directly for the FD path). For the FD path this is critical: the frontend receives sv[1] over D-Bus asynchronously and may not have started writing yet. Opening the CUPS HTTP POST before any data is available risks a CUPS server-side timeout ("No file in print request"). By deferring cupsStartDestDocument until the client fd is ready, the first cupsWriteRequestData call follows immediately with no gap.

  • We always try the FD-passing path first (printFd D-Bus method). This works across Snap/container sandbox boundaries because no socket file is involved. Falls back to the legacy socket-file path (printSocket) only when the backend returns G_DBUS_ERROR_UNKNOWN_METHOD, meaning it is an older backend that does not implement printFd.
    On success:
    returns an open, writable file descriptor ready for print data
    sets *jobid — job ID string, caller must g_free()
    sets *socket_path — socket file path (if socket fallback was used) NULL (if FD path was used) ;

  • Add use_fd flag in thread data

  • Add backend_obj_wait_for_print_threads function

  • Update printdatathread

  • Add print_fd function , on_handle_print_fd function

…ket and add cupsFreeOptions and g_free for failure return paths
cupsCreateDestJob() was called with a manually managed http_t* from
cupsConnectDest(). This creates a TCP connection to the printer queue
where Local peer credential auth is impossible and Kerberos is
unavailable, causing a 401 Unauthorized when the CUPS policy requires
authentication.

Fix by using CUPS_HTTP_DEFAULT for all CUPS job I/O. This causes the
CUPS library to connect to cupsd via the Unix domain socket, where the
kernel automatically vouches for the caller's UID via peer credentials
(SO_PEERCRED), satisfying the authenticated policy without a password.

Also fix a thread safety bug: cupsStartDestDocument was called on the
main thread but cupsWriteRequestData and cupsFinishDestDocument were
called on the worker thread using the same http_t*. Since
CUPS_HTTP_DEFAULT is per-thread (stored in _cups_globals_t), all three
calls must be on the same thread. Move cupsStartDestDocument and
cupsCopyDestInfo into the worker thread alongside the data transfer
calls.
Remove p->http from PrinterCUPS and replace ensure_printer_connection()
with ensure_dest_info() which only manages p->dinfo. All CUPS API calls
now use CUPS_HTTP_DEFAULT, letting the library manage its own per-thread
Unix domain socket connection to cupsd.

Also fix a memory leak in cups_get_Resolution which never
freed its dinfo or closed its http_t.
…et/print_fd signatures for thread management
@Souptik-De Souptik-De marked this pull request as ready for review April 27, 2026 07:35
@tillkamppeter tillkamppeter merged commit 1b0126b into OpenPrinting:master Apr 27, 2026
3 checks passed
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.

2 participants