path-lookup.c revision aa08982d62cf45b59ea6a06c915391f5db1fb86e
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering This file is part of systemd.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering Copyright 2010 Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering systemd is free software; you can redistribute it and/or modify it
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering under the terms of the GNU Lesser General Public License as published by
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering (at your option) any later version.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering systemd is distributed in the hope that it will be useful, but
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering Lesser General Public License for more details.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering You should have received a copy of the GNU Lesser General Public License
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poetteringint user_config_home(char **config_home) {
c34255bdb217c2a1d3ac6348252437ab8be9ca46Lennart Poettering const char *e;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = strappend(home, "/.config/systemd/user");
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringint user_runtime_dir(char **runtime_dir) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering const char *e;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering const char * const config_unit_paths[] = {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering const char * const runtime_unit_path = "/run/systemd/user";
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering const char * const data_unit_paths[] = {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering const char *home, *e;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering _cleanup_free_ char *config_home = NULL, *runtime_dir = NULL, *data_home = NULL;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering _cleanup_strv_free_ char **config_dirs = NULL, **data_dirs = NULL;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering /* Implement the mechanisms defined in
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering * http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html
b87633c4b20e3221748d6c98336cf6c85123cd66Lennart Poettering * We look in both the config and the data dirs because we
b87633c4b20e3221748d6c98336cf6c85123cd66Lennart Poettering * want to encourage that distributors ship their unit files
b87633c4b20e3221748d6c98336cf6c85123cd66Lennart Poettering * as data, and allow overriding as configuration.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering /* We don't treat /etc/xdg/systemd here as the spec
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering * suggests because we assume that that is a link to
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering * /etc/systemd/ anyway. */
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering if (asprintf(&data_home, "%s/systemd/user", e) < 0)
f647962d64e844689f3e2acfce6102fc47e76df2Michal Schmidt } else if (home) {
f647962d64e844689f3e2acfce6102fc47e76df2Michal Schmidt if (asprintf(&data_home, "%s/.local/share/systemd/user", home) < 0)
ebeccf9eecf5939a2ef772c3160e89efcad96194Lennart Poettering /* Now merge everything we found. */
ebeccf9eecf5939a2ef772c3160e89efcad96194Lennart Poettering if (strv_extend(&r, generator_early) < 0)
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (strv_extend_strv_concat(&r, config_dirs, "/systemd/user") < 0)
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (strv_extend_strv(&r, (char**) config_unit_paths) < 0)
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (strv_extend(&r, runtime_unit_path) < 0)
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (strv_extend_strv_concat(&r, data_dirs, "/systemd/user") < 0)
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (strv_extend_strv(&r, (char**) data_unit_paths) < 0)
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering const char *e;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering bool append = false; /* Add items from SYSTEMD_UNIT_PATH before normal directories */
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering /* First priority is whatever has been passed to us via env
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering /* FIXME: empty components in other places should be
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering * rejected. */
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering p->unit_path = path_split_and_make_absolute(e);
71fda00f320379f5cbee8e118848de98caaa229dLennart Poettering /* Let's figure something out. */
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering /* For the user units we include share/ in the search
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering * path in order to comply with the XDG basedir spec.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering * For the system stuff we avoid such nonsense. OTOH
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering * we include /lib in the search path for the system
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering * stuff but avoid it for user stuff. */
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering unit_path = user_dirs(generator, generator_early, generator_late);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering /* If you modify this you also want to modify
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering * systemduserunitpath= in systemd.pc.in, and
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering * the arrays in user_dirs() above! */
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering /* If you modify this you also want to modify
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering * systemdsystemunitpath= in systemd.pc.in! */
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering r = strv_extend_strv(&p->unit_path, unit_path);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering if (!path_strv_resolve_uniq(p->unit_path, root_dir))
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering _cleanup_free_ char *t = strv_join(p->unit_path, "\n\t");
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering log_debug("Looking for unit files in (higher priority first):\n\t%s", t);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering /* /etc/init.d/ compatibility does not matter to users */
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering p->sysvinit_path = path_split_and_make_absolute(e);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering p->sysvrcnd_path = path_split_and_make_absolute(e);
NULL);
if (!p->sysvrcnd_path)
return -ENOMEM;
return -ENOMEM;
return -ENOMEM;
return -ENOMEM;
_cleanup_free_ char *t =
return -ENOMEM;
assert(p);
#ifdef HAVE_SYSV_COMPAT