launch: indent data-dirs parsers
We have several different data-dir sources for the standard session
service dirs. Indent each one in a separate block, to allow local
variable definitions and make them easier to read. At the same time,
rework the comments to reflect the current state.
No functional change.
@@ -977,21 +977,9 @@ static const char *default_data_dirs[] = {
};
static int manager_load_standard_session_services(Manager *manager, NSSCache *nss_cache) {
- _c_cleanup_(c_freep) char *data_home_dir = NULL;
- const char *dir, *suffix = "dbus-1/services", *runtime_dir = NULL;
- struct passwd *passwd;
- size_t i;
+ const char *suffix = "dbus-1/services";
int r;
- /*
- * dbus-daemon(1) allows the default search path to be modified
- * via the XDG_DATA_DIRS env-variable. We do not implement this
- * so far. If there is need, we can add it later.
- *
- * The order in which the directories are parsed follows the order
- * of dbus-daemon(1).
- */
-
/*
* $XDG_RUNTIME_DIR/dbus-1/services is used in user-scope to
* load transient units. dbus-daemon(1) actually creates this
@@ -1000,12 +988,14 @@ static int manager_load_standard_session_services(Manager *manager, NSSCache *ns
* creating the directory yourself. But if the directory is
* there, we load units from it.
*/
+ {
+ _c_cleanup_(c_freep) char *dirpath = NULL;
+ const char *runtime_dir;
+
runtime_dir = secure_getenv("XDG_RUNTIME_DIR");
if (!runtime_dir) {
fprintf(stderr, "Cannot figure out service runtime directory\n");
} else {
- _c_cleanup_(c_freep) char *dirpath = NULL;
-
r = asprintf(&dirpath, "%s/%s", runtime_dir, suffix);
if (r < 0)
return error_origin(-ENOMEM);
@@ -1014,12 +1004,18 @@ static int manager_load_standard_session_services(Manager *manager, NSSCache *ns
if (r)
return error_trace(r);
}
+ }
/*
* $HOME/.local/share/dbus-1/services is used for user buses
* additionally to the above mentioned directories. Note that
* it can be modified via the XDG_DATA_HOME env-variable.
*/
+ {
+ _c_cleanup_(c_freep) char *data_home_dir = NULL;
+ struct passwd *passwd;
+ const char *dir;
+
dir = secure_getenv("XDG_DATA_HOME");
if (dir) {
r = asprintf(&data_home_dir, "%s/%s", dir, suffix);
@@ -1040,6 +1036,18 @@ static int manager_load_standard_session_services(Manager *manager, NSSCache *ns
if (r)
return error_trace(r);
}
+ }
+
+ /*
+ * As last step, XDG_DATA_DIRS (or its default) are searched for
+ * service files. ./dbus-1/services/ is appended to each path found in
+ * XDG_DATA_DIRS.
+ *
+ * XXX: We only support the default, so far. We should actuall read
+ * XDG_DATA_DIRS and use it.
+ */
+ {
+ size_t i;
for (i = 0; default_data_dirs[i]; ++i) {
_c_cleanup_(c_freep) char *dirpath = NULL;
@@ -1052,6 +1060,7 @@ static int manager_load_standard_session_services(Manager *manager, NSSCache *ns
if (r)
return error_trace(r);
}
+ }
return 0;
}
