path-lookup.c revision 667a1cd645c9402921dedff08a86bb35cddbcbf9
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering This file is part of systemd.
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering Copyright 2010 Lennart Poettering
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering systemd is free software; you can redistribute it and/or modify it
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering under the terms of the GNU Lesser General Public License as published by
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering (at your option) any later version.
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering systemd is distributed in the hope that it will be useful, but
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering Lesser General Public License for more details.
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering You should have received a copy of the GNU Lesser General Public License
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poetteringstatic const char* const systemd_running_as_table[_SYSTEMD_RUNNING_AS_MAX] = {
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart PoetteringDEFINE_STRING_TABLE_LOOKUP(systemd_running_as, SystemdRunningAs);
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poetteringint user_config_home(char **config_home) {
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering const char *e;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering r = strappend(home, "/.config/systemd/user");
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering const char * const config_unit_paths[] = {
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering const char * const data_unit_paths[] = {
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering const char *home, *e;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering _cleanup_free_ char *config_home = NULL, *data_home = NULL;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering _cleanup_strv_free_ char **config_dirs = NULL, **data_dirs = NULL;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering /* Implement the mechanisms defined in
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering * http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering * We look in both the config and the data dirs because we
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering * want to encourage that distributors ship their unit files
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering * as data, and allow overriding as configuration.
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering /* We don't treat /etc/xdg/systemd here as the spec
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering * suggests because we assume that that is a link to
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering * /etc/systemd/ anyway. */
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering if (asprintf(&data_home, "%s/systemd/user", e) < 0)
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering if (asprintf(&data_home, "%s/.local/share/systemd/user", home) < 0)
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering /* Now merge everything we found. */
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering if (strv_extend(&r, generator_early) < 0)
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagin if (strv_extend_strv_concat(&r, config_dirs, "/systemd/user") < 0)
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagin if (strv_extend_strv(&r, (char**) config_unit_paths) < 0)
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagin if (strv_extend_strv_concat(&r, data_dirs, "/systemd/user") < 0)
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagin if (strv_extend_strv(&r, (char**) data_unit_paths) < 0)
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagin if (strv_extend(&r, generator_late) < 0)
fail:
strv_free(r);
return NULL;
int lookup_paths_init(
LookupPaths *p,
bool personal,
const char *root_dir,
const char *generator,
const char *generator_early,
const char *generator_late) {
assert(p);
if (!p->unit_path)
return -ENOMEM;
if (personal)
NULL);
if (!p->unit_path)
return -ENOMEM;
#ifdef HAVE_SPLIT_USR
NULL);
if (!p->unit_path)
return -ENOMEM;
return -ENOMEM;
return -ENOMEM;
#ifdef HAVE_SYSV_COMPAT
if (!p->sysvinit_path)
return -ENOMEM;
NULL);
if (!p->sysvinit_path)
return -ENOMEM;
if (!p->sysvrcnd_path)
return -ENOMEM;
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