Skip to content

Share the per-user socket path definition - #1139

Merged
sthibaul merged 4 commits into
brailcom:masterfrom
shindere:share-socket-path
Nov 16, 2026
Merged

sthibaul merged 4 commits into
brailcom:masterfrom
shindere:share-socket-path

Conversation

@shindere

Copy link
Copy Markdown
Contributor

The default per-user socket, <runtime dir>/speech-dispatcher/speechd.sock, is spelled out separately in several places: the server, libspeechd, a test program, the Python client and the systemd user socket unit. Nothing but convention keeps them in agreement, yet that agreement is what lets a client reach a server started with default settings.

This PR defines the path relative to the runtime directory, speech-dispatcher/speechd.sock, once in configure.ac, and every place joins it to the runtime directory in the same way. The resulting paths are unchanged.

The first commit covers the C code. It defines SPD_SOCKET_PATH and the macro SPD_BUILD_SOCKET_PATH(runtime_dir) in config.h. The macro joins the relative path to a runtime directory with g_build_filename, and the server, libspeechd and src/tests/run_test.c all use SPD_BUILD_SOCKET_PATH(g_get_user_runtime_dir()). The server's own directory, which also holds its pid file and logs, becomes SPD_RUNTIME_SUBDIR, from which SPD_SOCKET_PATH is built.

The next three commits extend this to files that are not C:

  • The second and third commits only reformat EXTRA_DIST in the top-level Makefile.am, which the fourth commit changes: one file per line, then sorted, with a comment that fixes the order. This keeps that change, and later ones, readable in a diff, and is of use on its own.
  • The fourth commit substitutes the same value into them: configure generates speech-dispatcher.socket from the new speech-dispatcher.socket.in, and the Python client takes SSIPClient.DEFAULT_SOCKET_PATH from the generated paths.py. Unlike the .service units, which make generates because they hold an installation directory (@bindir@), the socket unit holds none, so configure can generate it.

Without the fourth commit, the unit and the Python client keep their own copy of the path.

The path remains written out in a comment of config/speechd.conf and in the documentation. Would you welcome generating them too, in this PR or a separate one?

Tested with make check, make install and make dist: the generated unit and paths.py hold the same paths as before, and a server and spd-say built from the first commit alone met at the expected socket.

@sthibaul sthibaul left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a nitpick :)

Comment thread src/api/c/libspeechd.c Outdated
// Do not return glib string, but glibc string...
h = strdup(socket_filename->str);
g_string_free(socket_filename, 1);
h = strdup(socket_filename);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to strdup any more, and can just return socket_filename?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well spotted, thanks! Indeed, since GLib 2.46 g_malloc always uses the system malloc, so the string can be released with free(). Done in the first commit, which also drops the "Do not return glib string, but glibc string" comment. With your suggestion the function body comes down from nine lines in master to a single one, a clearer gain than the PR offered before.

The per-user socket, <runtime dir>/speech-dispatcher/speechd.sock, was
spelled out in libspeechd (_get_default_unix_socket_name), in the
server (runtime_speechd_dir and the "default" socket path) and in the
run_test test program. configure.ac now builds the path relative to
the runtime directory once, as SPD_SOCKET_PATH, and defines in
config.h the macro SPD_BUILD_SOCKET_PATH(runtime_dir), which joins it
to a runtime directory with g_build_filename. All three use
SPD_BUILD_SOCKET_PATH(g_get_user_runtime_dir()). The server's own
directory under the runtime directory, which also holds its pid file
and logs, becomes SPD_RUNTIME_SUBDIR, from which SPD_SOCKET_PATH is
built, and is also joined with g_build_filename. The resulting paths
are unchanged.

The server no longer checks that runtime_speechd_dir is non-NULL
before building the default socket path, which no longer uses it. The
check could not fail anyway, since earlier in main runtime_speechd_dir
is always set from g_build_filename, which never returns NULL.
EXTRA_DIST in the top-level Makefile.am now lists one file per line,
using line continuations, in the same order as before.
EXTRA_DIST in the top-level Makefile.am is now sorted in byte order,
and a comment above it asks to keep it so.
The per-user socket path was still spelled out in the systemd user
unit speech-dispatcher.socket and in the Python client
(SSIPClient.DEFAULT_SOCKET_PATH). configure.ac now also substitutes
spd_socket_path: configure generates speech-dispatcher.socket from
the new speech-dispatcher.socket.in, and the Python client takes
DEFAULT_SOCKET_PATH from paths.py. The resulting paths are unchanged.
@sthibaul
sthibaul merged commit b4952ae into brailcom:master Nov 16, 2026
7 checks passed
@sthibaul

Copy link
Copy Markdown
Collaborator

Thanks!

@shindere
shindere deleted the share-socket-path branch November 16, 2026 06:34
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