From a7cb8fc1f4ce602b571a3f6189c7d049dbc83f10 Mon Sep 17 00:00:00 2001 From: Seb Hinderer Date: Sun, 15 Nov 2026 13:46:03 +0100 Subject: [PATCH 1/4] Share the socket path definition between speechd and libspeechd The per-user socket, /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. --- configure.ac | 13 +++++++++++++ src/api/c/libspeechd.c | 11 +---------- src/server/speechd.c | 15 +++------------ src/tests/run_test.c | 4 +--- 4 files changed, 18 insertions(+), 25 deletions(-) diff --git a/configure.ac b/configure.ac index 2a6dd28c9..c0c8eb069 100644 --- a/configure.ac +++ b/configure.ac @@ -643,6 +643,19 @@ AC_SUBST([LIB_SPD_AGE]) GETTEXT_PACKAGE=speech-dispatcher AC_SUBST([GETTEXT_PACKAGE]) +# Default location of the per-user server socket, shared by the +# server and libspeechd: /, in the +# server's directory / +spd_runtime_subdir=speech-dispatcher +spd_socket_path=$spd_runtime_subdir/speechd.sock +AC_DEFINE_UNQUOTED([SPD_RUNTIME_SUBDIR], ["$spd_runtime_subdir"], + [Directory of the server in the user's runtime directory]) +AC_DEFINE_UNQUOTED([SPD_SOCKET_PATH], ["$spd_socket_path"], + [Default server socket, relative to the user's runtime directory]) +AC_DEFINE([SPD_BUILD_SOCKET_PATH(runtime_dir)], + [g_build_filename((runtime_dir), SPD_SOCKET_PATH, NULL)], + [Default server socket in runtime_dir, as a string to free with g_free]) + # Paths for configuration files: spdconfdir='${sysconfdir}/speech-dispatcher' AC_SUBST([spdconfdir]) diff --git a/src/api/c/libspeechd.c b/src/api/c/libspeechd.c index dc6d2f5b1..21bce5857 100644 --- a/src/api/c/libspeechd.c +++ b/src/api/c/libspeechd.c @@ -183,16 +183,7 @@ char *get_line(SPDConnection * conn, int *n) /* Determine address for the unix socket */ static char *_get_default_unix_socket_name(void) { - GString *socket_filename; - char *h; - const char *rundir = g_get_user_runtime_dir(); - socket_filename = g_string_new(""); - g_string_printf(socket_filename, "%s/speech-dispatcher/speechd.sock", - rundir); - // Do not return glib string, but glibc string... - h = strdup(socket_filename->str); - g_string_free(socket_filename, 1); - return h; + return SPD_BUILD_SOCKET_PATH(g_get_user_runtime_dir()); } void SPDConnectionAddress__free(SPDConnectionAddress * address) diff --git a/src/server/speechd.c b/src/server/speechd.c index 30fdb99d3..c37947110 100644 --- a/src/server/speechd.c +++ b/src/server/speechd.c @@ -1181,7 +1181,7 @@ int main(int argc, char *argv[]) /* Setup a speechd-dispatcher directory or create a new one */ SpeechdOptions.runtime_speechd_dir = - g_strdup_printf("%s/speech-dispatcher", user_runtime_dir); + g_build_filename(user_runtime_dir, SPD_RUNTIME_SUBDIR, NULL); MSG(4, "Trying to find %s", SpeechdOptions.runtime_speechd_dir); g_mkdir_with_parents(SpeechdOptions.runtime_speechd_dir, S_IRWXU); @@ -1271,18 +1271,9 @@ int main(int argc, char *argv[]) if (!strcmp(SpeechdOptions.socket_path, "default")) { /* This code cannot be moved above next to conf_dir and pidpath resolution because we need to also consider the DotConf configuration, which is read in speechd_init() */ - GString *socket_filename; - socket_filename = g_string_new(""); - if (SpeechdOptions.runtime_speechd_dir) { - g_string_printf(socket_filename, "%s/speechd.sock", - SpeechdOptions.runtime_speechd_dir); - } else { - FATAL - ("Socket name file not set and user has no runtime directory"); - } g_free(SpeechdOptions.socket_path); - SpeechdOptions.socket_path = g_strdup(socket_filename->str); - g_string_free(socket_filename, 1); + SpeechdOptions.socket_path = + SPD_BUILD_SOCKET_PATH(g_get_user_runtime_dir()); } /* Check if the communication method corresponds to the spawn request */ diff --git a/src/tests/run_test.c b/src/tests/run_test.c index 18c60eed3..9e858afe8 100644 --- a/src/tests/run_test.c +++ b/src/tests/run_test.c @@ -118,9 +118,7 @@ void set_socket_path(struct sockaddr_un *address) path = g_getenv("SPEECHD_SOCKET"); if (path == NULL || path[0] == '\0') { - pathcopy = g_build_filename(g_get_user_runtime_dir(), - "speech-dispatcher", - "speechd.sock", NULL); + pathcopy = SPD_BUILD_SOCKET_PATH(g_get_user_runtime_dir()); path = pathcopy; } From 671b1c6b1c7e9c1a874198d8e2b4145e5d25e243 Mon Sep 17 00:00:00 2001 From: Seb Hinderer Date: Sun, 15 Nov 2026 21:59:13 +0100 Subject: [PATCH 2/4] List the top-level distributed files one per line EXTRA_DIST in the top-level Makefile.am now lists one file per line, using line continuations, in the same order as before. --- Makefile.am | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index f955c6d9b..7f932b233 100644 --- a/Makefile.am +++ b/Makefile.am @@ -31,7 +31,25 @@ if ENABLE_DOC SUBDIRS += doc endif -EXTRA_DIST= config.rpath COPYING.LGPL COPYING.GPL-2 COPYING.GPL-3 ANNOUNCE BUGS FAQ README.md README.packagers README.translators README.overview.md README.style.md build.sh speech-dispatcherd.service.in speech-dispatcher.socket speech-dispatcher.service.in po/Makevars.in po/README +EXTRA_DIST = \ + config.rpath \ + COPYING.LGPL \ + COPYING.GPL-2 \ + COPYING.GPL-3 \ + ANNOUNCE \ + BUGS \ + FAQ \ + README.md \ + README.packagers \ + README.translators \ + README.overview.md \ + README.style.md \ + build.sh \ + speech-dispatcherd.service.in \ + speech-dispatcher.socket \ + speech-dispatcher.service.in \ + po/Makevars.in \ + po/README CLEANFILES= DISTCLEANFILES= From b5898e909984f54e1a663b043aa156811e05ba79 Mon Sep 17 00:00:00 2001 From: Seb Hinderer Date: Sun, 15 Nov 2026 21:59:17 +0100 Subject: [PATCH 3/4] Sort the top-level distributed files EXTRA_DIST in the top-level Makefile.am is now sorted in byte order, and a comment above it asks to keep it so. --- Makefile.am | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Makefile.am b/Makefile.am index 7f932b233..212b3f1ef 100644 --- a/Makefile.am +++ b/Makefile.am @@ -31,25 +31,26 @@ if ENABLE_DOC SUBDIRS += doc endif +# Keep sorted in byte order, as "LC_ALL=C sort" does. EXTRA_DIST = \ - config.rpath \ - COPYING.LGPL \ - COPYING.GPL-2 \ - COPYING.GPL-3 \ ANNOUNCE \ BUGS \ + COPYING.GPL-2 \ + COPYING.GPL-3 \ + COPYING.LGPL \ FAQ \ README.md \ - README.packagers \ - README.translators \ README.overview.md \ + README.packagers \ README.style.md \ + README.translators \ build.sh \ - speech-dispatcherd.service.in \ - speech-dispatcher.socket \ - speech-dispatcher.service.in \ + config.rpath \ po/Makevars.in \ - po/README + po/README \ + speech-dispatcher.service.in \ + speech-dispatcher.socket \ + speech-dispatcherd.service.in CLEANFILES= DISTCLEANFILES= From c9e02da3d9b3b83b5f3401b710c8a3fd36d509b9 Mon Sep 17 00:00:00 2001 From: Seb Hinderer Date: Sun, 15 Nov 2026 14:06:25 +0100 Subject: [PATCH 4/4] Generate the user socket unit and the Python default from configure 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. --- Makefile.am | 1 - configure.ac | 7 +++++-- speech-dispatcher.socket => speech-dispatcher.socket.in | 2 +- src/api/python/speechd/Makefile.am | 1 + src/api/python/speechd/client.py | 2 +- src/api/python/speechd/paths.py.in | 1 + 6 files changed, 9 insertions(+), 5 deletions(-) rename speech-dispatcher.socket => speech-dispatcher.socket.in (65%) diff --git a/Makefile.am b/Makefile.am index 212b3f1ef..bd5c23360 100644 --- a/Makefile.am +++ b/Makefile.am @@ -49,7 +49,6 @@ EXTRA_DIST = \ po/Makevars.in \ po/README \ speech-dispatcher.service.in \ - speech-dispatcher.socket \ speech-dispatcherd.service.in CLEANFILES= diff --git a/configure.ac b/configure.ac index c0c8eb069..106218d48 100644 --- a/configure.ac +++ b/configure.ac @@ -644,8 +644,9 @@ GETTEXT_PACKAGE=speech-dispatcher AC_SUBST([GETTEXT_PACKAGE]) # Default location of the per-user server socket, shared by the -# server and libspeechd: /, in the -# server's directory / +# server, libspeechd, the Python client and the systemd user socket: +# /, in the server's directory +# / spd_runtime_subdir=speech-dispatcher spd_socket_path=$spd_runtime_subdir/speechd.sock AC_DEFINE_UNQUOTED([SPD_RUNTIME_SUBDIR], ["$spd_runtime_subdir"], @@ -655,6 +656,7 @@ AC_DEFINE_UNQUOTED([SPD_SOCKET_PATH], ["$spd_socket_path"], AC_DEFINE([SPD_BUILD_SOCKET_PATH(runtime_dir)], [g_build_filename((runtime_dir), SPD_SOCKET_PATH, NULL)], [Default server socket in runtime_dir, as a string to free with g_free]) +AC_SUBST([spd_socket_path]) # Paths for configuration files: spdconfdir='${sysconfdir}/speech-dispatcher' @@ -731,6 +733,7 @@ AC_CONFIG_FILES([Makefile run-speechd run-spd-say speech-dispatcher.pc + speech-dispatcher.socket config/Makefile config/clients/Makefile config/modules/Makefile diff --git a/speech-dispatcher.socket b/speech-dispatcher.socket.in similarity index 65% rename from speech-dispatcher.socket rename to speech-dispatcher.socket.in index a9475e768..2eae1796f 100644 --- a/speech-dispatcher.socket +++ b/speech-dispatcher.socket.in @@ -2,7 +2,7 @@ Description=Speech Dispatcher Socket [Socket] -ListenStream=%t/speech-dispatcher/speechd.sock +ListenStream=%t/@spd_socket_path@ [Install] WantedBy=sockets.target diff --git a/src/api/python/speechd/Makefile.am b/src/api/python/speechd/Makefile.am index 08407c144..543ee3e19 100644 --- a/src/api/python/speechd/Makefile.am +++ b/src/api/python/speechd/Makefile.am @@ -23,6 +23,7 @@ speechd_python_PYTHON = __init__.py _test.py client.py nodist_speechd_python_PYTHON = paths.py edit = sed \ + -e 's:@spd_socket_path[@]:$(spd_socket_path):g' \ -e 's:@bindir[@]:$(bindir):g' all: paths.py diff --git a/src/api/python/speechd/client.py b/src/api/python/speechd/client.py index 22835e291..75611faa4 100644 --- a/src/api/python/speechd/client.py +++ b/src/api/python/speechd/client.py @@ -504,7 +504,7 @@ class SSIPClient(object): """Default host for server connections.""" DEFAULT_PORT = 6560 """Default port number for server connections.""" - DEFAULT_SOCKET_PATH = "speech-dispatcher/speechd.sock" + DEFAULT_SOCKET_PATH = paths.DEFAULT_SOCKET_PATH """Default name of the communication unix socket""" def __init__(self, name, component='default', user='unknown', address=None, diff --git a/src/api/python/speechd/paths.py.in b/src/api/python/speechd/paths.py.in index a2a96965c..2e6add792 100644 --- a/src/api/python/speechd/paths.py.in +++ b/src/api/python/speechd/paths.py.in @@ -1 +1,2 @@ SPD_SPAWN_CMD = "@bindir@/speech-dispatcher" +DEFAULT_SOCKET_PATH = "@spd_socket_path@"