From: Luca Boccassi Date: Fri, 13 Sep 2024 17:42:11 +0000 (+0200) Subject: bus: search for system-services in /etc/ and /run/ by default X-Git-Tag: dbus-1.15.12~10^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=776e6e0b04a14de4cafc13cc74ffb4a55a23a074;p=thirdparty%2Fdbus.git bus: search for system-services in /etc/ and /run/ by default Tthis is useful when an asset manager wants to install a system service while /usr/ is read-only (e.g.: portable services running on a different namespaced image). Unlike other directories, enforce strict naming and do not set up an inotify, as the directories might not even exist until much later. Also search in /run/ for ephemeral services that will disappear after a reboot. Signed-off-by: Luca Boccassi --- diff --git a/bus/config-parser.c b/bus/config-parser.c index de9a1398d..2b630d181 100644 --- a/bus/config-parser.c +++ b/bus/config-parser.c @@ -943,6 +943,24 @@ start_busconfig_child (BusConfigParser *parser, return FALSE; } + /* /etc/ and /run/ are a recent addition, so we treat them differently + * than the other directories: strict naming is enforced, and we do not + * set up an inotify as it might very well not exist until much later at + * boot. */ + if (!_dbus_get_local_system_servicedirs (&dirs)) + { + BUS_SET_OOM (error); + return FALSE; + } + + if (!service_dirs_absorb_string_list (&parser->service_dirs, &dirs, + BUS_SERVICE_DIR_FLAGS_NO_WATCH|BUS_SERVICE_DIR_FLAGS_STRICT_NAMING)) + { + BUS_SET_OOM (error); + _dbus_list_clear_full (&dirs, dbus_free); + return FALSE; + } + if (!_dbus_get_standard_system_servicedirs (&dirs)) { BUS_SET_OOM (error); diff --git a/dbus/dbus-sysdeps-util-unix.c b/dbus/dbus-sysdeps-util-unix.c index ce127388d..c1158c377 100644 --- a/dbus/dbus-sysdeps-util-unix.c +++ b/dbus/dbus-sysdeps-util-unix.c @@ -1478,6 +1478,34 @@ _dbus_get_standard_system_servicedirs (DBusList **dirs) dirs); } + +/** + * Returns the local admin directories for a system bus to look for service + * activation files + * + * On UNIX this should be the /etc/ and /run/ directories. + * + * On Windows there is no system bus and this function can return nothing. + * + * @param dirs the directory list we are returning + * @returns #FALSE on OOM + */ + +dbus_bool_t +_dbus_get_local_system_servicedirs (DBusList **dirs) +{ + static const char standard_search_path[] = + "/etc:" + "/run"; + DBusString servicedir_path; + + _dbus_string_init_const (&servicedir_path, standard_search_path); + + return _dbus_split_paths_and_append (&servicedir_path, + DBUS_UNIX_STANDARD_SYSTEM_SERVICEDIR, + dirs); +} + /** * Get the absolute path of the system.conf file * (there is no system bus on Windows so this can just diff --git a/dbus/dbus-sysdeps-util-win.c b/dbus/dbus-sysdeps-util-win.c index bb185f052..6dd945665 100644 --- a/dbus/dbus-sysdeps-util-win.c +++ b/dbus/dbus-sysdeps-util-win.c @@ -1614,6 +1614,26 @@ _dbus_get_standard_system_servicedirs (DBusList **dirs) return TRUE; } + +/** + * Returns the local admin directories for a system bus to look for service + * activation files + * + * On UNIX this should be the /etc/ and /run/ directories. + * + * On Windows there is no system bus and this function can return nothing. + * + * @param dirs the directory list we are returning + * @returns #FALSE on OOM + */ + +dbus_bool_t +_dbus_get_local_system_servicedirs (DBusList **dirs) +{ + *dirs = NULL; + return TRUE; +} + static dbus_bool_t _dbus_get_config_file_name (DBusString *str, const char *basename) diff --git a/dbus/dbus-sysdeps.h b/dbus/dbus-sysdeps.h index 27053a43e..e022d4f57 100644 --- a/dbus/dbus-sysdeps.h +++ b/dbus/dbus-sysdeps.h @@ -493,6 +493,7 @@ dbus_bool_t _dbus_path_is_absolute (const DBusString *filename); dbus_bool_t _dbus_get_standard_session_servicedirs (DBusList **dirs); dbus_bool_t _dbus_get_standard_system_servicedirs (DBusList **dirs); +dbus_bool_t _dbus_get_local_system_servicedirs (DBusList **dirs); dbus_bool_t _dbus_set_up_transient_session_servicedirs (DBusList **dirs, DBusError *error); diff --git a/doc/dbus-daemon.1.xml.in b/doc/dbus-daemon.1.xml.in index ae9b5aa3b..5bf93b93d 100644 --- a/doc/dbus-daemon.1.xml.in +++ b/doc/dbus-daemon.1.xml.in @@ -725,6 +725,22 @@ configuration file would probably be nonsense. On Unix, the standard system service directories are: + + + /etc/dbus-1/system-services: this location is specified + by the D-Bus Specification, and is suitable for software + installed locally by the system administrator, + or by an asset manager deploying services that are + not part of the OS (perhaps while /usr/ is read-only) + + + + + /run/dbus-1/system-services: this location is specified + by the D-Bus Specification, and is suitable for ephemeral + services that will disappear after a reboot + + /usr/local/share/dbus-1/system-services: this location is