path-lookup: if $HOME can be determined but $XDG_RUNTIME_DIR can't, is it
So far, if either $HOME or $XDG_RUNTIME_DIR is not set we wouldn't use either, and fail acquire_config_dirs() and acquire_control_dirs() in their entireties. With this change, let's make use of the variables we can acquire, and don't bother with the other. Specifically this means: in both acquire_config_dirs() and acquire_control_dirs() handle ENXIO from user_config_dir() and user_runtime_dir() directly, instead of propagating it up and handling it in the caller.
This commit is contained in:
@@ -329,12 +329,18 @@ static int acquire_config_dirs(UnitFileScope scope, char **persistent, char **ru
|
||||
|
||||
case UNIT_FILE_USER:
|
||||
r = user_config_dir(&a, "/systemd/user");
|
||||
if (r < 0)
|
||||
if (r < 0 && r != -ENXIO)
|
||||
return r;
|
||||
|
||||
r = user_runtime_dir(runtime, "/systemd/user");
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r < 0) {
|
||||
if (r != -ENXIO)
|
||||
return r;
|
||||
|
||||
/* If XDG_RUNTIME_DIR is not set, don't consider that fatal, simply initialize the runtime
|
||||
* directory to NULL */
|
||||
*runtime = NULL;
|
||||
}
|
||||
|
||||
*persistent = a;
|
||||
a = NULL;
|
||||
@@ -383,12 +389,18 @@ static int acquire_control_dirs(UnitFileScope scope, char **persistent, char **r
|
||||
|
||||
case UNIT_FILE_USER:
|
||||
r = user_config_dir(&a, "/systemd/system.control");
|
||||
if (r < 0)
|
||||
if (r < 0 && r != -ENXIO)
|
||||
return r;
|
||||
|
||||
r = user_runtime_dir(runtime, "/systemd/system.control");
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r < 0) {
|
||||
if (r != -ENXIO)
|
||||
return r;
|
||||
|
||||
/* If XDG_RUNTIME_DIR is not set, don't consider this fatal, simply initialize the directory to
|
||||
* NULL */
|
||||
*runtime = NULL;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -475,22 +487,26 @@ int lookup_paths_init(
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
/* Note: when XDG_RUNTIME_DIR is not set this will not return -ENXIO, but simply set runtime_config to NULL */
|
||||
r = acquire_config_dirs(scope, &persistent_config, &runtime_config);
|
||||
if (r < 0 && r != -ENXIO)
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if ((flags & LOOKUP_PATHS_EXCLUDE_GENERATED) == 0) {
|
||||
/* Note: if XDG_RUNTIME_DIR is not set, this will fail completely with ENXIO */
|
||||
r = acquire_generator_dirs(scope, &generator, &generator_early, &generator_late);
|
||||
if (r < 0 && r != -EOPNOTSUPP && r != -ENXIO)
|
||||
return r;
|
||||
}
|
||||
|
||||
/* Note: if XDG_RUNTIME_DIR is not set, this will fail completely with ENXIO */
|
||||
r = acquire_transient_dir(scope, &transient);
|
||||
if (r < 0 && r != -EOPNOTSUPP && r != -ENXIO)
|
||||
return r;
|
||||
|
||||
/* Note: when XDG_RUNTIME_DIR is not set this will not return -ENXIO, but simply set runtime_control to NULL */
|
||||
r = acquire_control_dirs(scope, &persistent_control, &runtime_control);
|
||||
if (r < 0 && r != -EOPNOTSUPP && r != -ENXIO)
|
||||
if (r < 0 && r != -EOPNOTSUPP)
|
||||
return r;
|
||||
|
||||
/* First priority is whatever has been passed to us via env vars */
|
||||
|
||||
Reference in New Issue
Block a user