diff --git a/Makefile.am b/Makefile.am index f955c6d9b..bd5c23360 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 +# Keep sorted in byte order, as "LC_ALL=C sort" does. +EXTRA_DIST = \ + ANNOUNCE \ + BUGS \ + COPYING.GPL-2 \ + COPYING.GPL-3 \ + COPYING.LGPL \ + FAQ \ + README.md \ + README.overview.md \ + README.packagers \ + README.style.md \ + README.translators \ + build.sh \ + config.rpath \ + po/Makevars.in \ + po/README \ + speech-dispatcher.service.in \ + speech-dispatcherd.service.in CLEANFILES= DISTCLEANFILES= diff --git a/configure.ac b/configure.ac index 2a6dd28c9..106218d48 100644 --- a/configure.ac +++ b/configure.ac @@ -643,6 +643,21 @@ 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, 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"], + [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]) +AC_SUBST([spd_socket_path]) + # Paths for configuration files: spdconfdir='${sysconfdir}/speech-dispatcher' AC_SUBST([spdconfdir]) @@ -718,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/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/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@" 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; }