path-lookup.c   path-lookup.c 
skipping to change at line 35 skipping to change at line 35
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#include "util.h" #include "util.h"
#include "mkdir.h" #include "mkdir.h"
#include "strv.h" #include "strv.h"
#include "path-util.h" #include "path-util.h"
#include "path-lookup.h" #include "path-lookup.h"
static const char* const systemd_running_as_table[_SYSTEMD_RUNNING_AS_MAX]
= {
[SYSTEMD_SYSTEM] = "system",
[SYSTEMD_USER] = "user"
};
DEFINE_STRING_TABLE_LOOKUP(systemd_running_as, SystemdRunningAs);
int user_config_home(char **config_home) { int user_config_home(char **config_home) {
const char *e; const char *e;
char *r; char *r;
e = getenv("XDG_CONFIG_HOME"); e = getenv("XDG_CONFIG_HOME");
if (e) { if (e) {
r = strappend(e, "/systemd/user"); r = strappend(e, "/systemd/user");
if (!r) if (!r)
return -ENOMEM; return -ENOMEM;
skipping to change at line 128 skipping to change at line 121
/* We don't treat /etc/xdg/systemd here as the spec /* We don't treat /etc/xdg/systemd here as the spec
* suggests because we assume that that is a link to * suggests because we assume that that is a link to
* /etc/systemd/ anyway. */ * /etc/systemd/ anyway. */
e = getenv("XDG_DATA_HOME"); e = getenv("XDG_DATA_HOME");
if (e) { if (e) {
if (asprintf(&data_home, "%s/systemd/user", e) < 0) if (asprintf(&data_home, "%s/systemd/user", e) < 0)
goto fail; goto fail;
} else if (home) { } else if (home) {
_cleanup_free_ char *data_home_parent = NULL;
if (asprintf(&data_home, "%s/.local/share/systemd/user", ho me) < 0) if (asprintf(&data_home, "%s/.local/share/systemd/user", ho me) < 0)
goto fail; goto fail;
/* There is really no need for two unit dirs in $HOME,
* except to be fully compliant with the XDG spec. We
* now try to link the two dirs, so that we can
* minimize disk seeks a little. Further down we'll
* then filter out this link, if it is actually is
* one. */
if (path_get_parent(data_home, &data_home_parent) >= 0) {
_cleanup_free_ char *config_home_relative = NULL;
if (path_make_relative(data_home_parent, config_hom
e, &config_home_relative) >= 0) {
mkdir_parents_label(data_home, 0777);
(void) symlink(config_home_relative, data_h
ome);
}
}
} }
e = getenv("XDG_DATA_DIRS"); e = getenv("XDG_DATA_DIRS");
if (e) if (e)
data_dirs = strv_split(e, ":"); data_dirs = strv_split(e, ":");
else else
data_dirs = strv_new("/usr/local/share", data_dirs = strv_new("/usr/local/share",
"/usr/share", "/usr/share",
NULL); NULL);
if (!data_dirs) if (!data_dirs)
skipping to change at line 215 skipping to change at line 190
int lookup_paths_init( int lookup_paths_init(
LookupPaths *p, LookupPaths *p,
SystemdRunningAs running_as, SystemdRunningAs running_as,
bool personal, bool personal,
const char *root_dir, const char *root_dir,
const char *generator, const char *generator,
const char *generator_early, const char *generator_early,
const char *generator_late) { const char *generator_late) {
const char *e; const char *e;
bool append = false; /* Add items from SYSTEMD_UNIT_PATH before nor mal directories */
assert(p); assert(p);
/* First priority is whatever has been passed to us via env /* First priority is whatever has been passed to us via env
* vars */ * vars */
e = getenv("SYSTEMD_UNIT_PATH"); e = getenv("SYSTEMD_UNIT_PATH");
if (e) { if (e) {
if (endswith(e, ":")) {
e = strndupa(e, strlen(e) - 1);
append = true;
}
/* FIXME: empty components in other places should be
* rejected. */
p->unit_path = path_split_and_make_absolute(e); p->unit_path = path_split_and_make_absolute(e);
if (!p->unit_path) if (!p->unit_path)
return -ENOMEM; return -ENOMEM;
} else } else
p->unit_path = NULL; p->unit_path = NULL;
if (strv_isempty(p->unit_path)) { if (!p->unit_path || append) {
/* Nothing is set, so let's figure something out. */ /* Let's figure something out. */
strv_free(p->unit_path);
_cleanup_strv_free_ char **unit_path;
int r;
/* For the user units we include share/ in the search /* For the user units we include share/ in the search
* path in order to comply with the XDG basedir * path in order to comply with the XDG basedir spec.
* spec. For the system stuff we avoid such * For the system stuff we avoid such nonsense. OTOH
* nonsense. OTOH we include /lib in the search path * we include /lib in the search path for the system
* for the system stuff but avoid it for user * stuff but avoid it for user stuff. */
* stuff. */
if (running_as == SYSTEMD_USER) { if (running_as == SYSTEMD_USER) {
if (personal) if (personal)
p->unit_path = user_dirs(generator, generat or_early, generator_late); unit_path = user_dirs(generator, generator_ early, generator_late);
else else
p->unit_path = strv_new( unit_path = strv_new(
/* If you modify this you a
lso want to modify
* systemduserunitpath= in
systemd.pc.in, and
* the arrays in user_dirs(
) above! */
STRV_IFNOTNULL(generator_ea
rly),
USER_CONFIG_UNIT_PATH,
"/etc/systemd/user",
"/run/systemd/user",
STRV_IFNOTNULL(generator),
"/usr/local/lib/systemd/use
r",
"/usr/local/share/systemd/u
ser",
USER_DATA_UNIT_PATH,
"/usr/lib/systemd/user",
"/usr/share/systemd/user",
STRV_IFNOTNULL(generator_la
te),
NULL);
if (!p->unit_path)
return -ENOMEM;
} else {
p->unit_path = strv_new(
/* If you modify this you also want to modify /* If you modify this you also want to modify
* systemdsystemunitpath= in system * systemduserunitpath= in systemd.
d.pc.in! */ pc.in, and
* the arrays in user_dirs() above!
*/
STRV_IFNOTNULL(generator_early), STRV_IFNOTNULL(generator_early),
SYSTEM_CONFIG_UNIT_PATH, USER_CONFIG_UNIT_PATH,
"/etc/systemd/system", "/etc/systemd/user",
"/run/systemd/system", "/run/systemd/user",
STRV_IFNOTNULL(generator), STRV_IFNOTNULL(generator),
"/usr/local/lib/systemd/system", "/usr/local/lib/systemd/user",
SYSTEM_DATA_UNIT_PATH, "/usr/local/share/systemd/user",
"/usr/lib/systemd/system", USER_DATA_UNIT_PATH,
#ifdef HAVE_SPLIT_USR "/usr/lib/systemd/user",
"/lib/systemd/system", "/usr/share/systemd/user",
#endif
STRV_IFNOTNULL(generator_late), STRV_IFNOTNULL(generator_late),
NULL); NULL);
} else
unit_path = strv_new(
/* If you modify this you also want to modi
fy
* systemdsystemunitpath= in systemd.pc.in!
*/
STRV_IFNOTNULL(generator_early),
SYSTEM_CONFIG_UNIT_PATH,
"/etc/systemd/system",
"/run/systemd/system",
STRV_IFNOTNULL(generator),
"/usr/local/lib/systemd/system",
SYSTEM_DATA_UNIT_PATH,
"/usr/lib/systemd/system",
#ifdef HAVE_SPLIT_USR
"/lib/systemd/system",
#endif
STRV_IFNOTNULL(generator_late),
NULL);
if (!p->unit_path) if (!unit_path)
return -ENOMEM; return -ENOMEM;
}
r = strv_extend_strv(&p->unit_path, unit_path);
if (r < 0)
return r;
} }
if (!path_strv_resolve_uniq(p->unit_path, root_dir)) if (!path_strv_resolve_uniq(p->unit_path, root_dir))
return -ENOMEM; return -ENOMEM;
if (!strv_isempty(p->unit_path)) { if (!strv_isempty(p->unit_path)) {
_cleanup_free_ char *t = strv_join(p->unit_path, "\n\t"); _cleanup_free_ char *t = strv_join(p->unit_path, "\n\t");
if (!t) if (!t)
return -ENOMEM; return -ENOMEM;
log_debug("Looking for unit files in (higher priority first ):\n\t%s", t); log_debug("Looking for unit files in (higher priority first ):\n\t%s", t);
 End of changes. 15 change blocks. 
81 lines changed or deleted 57 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/