path-lookup.c revision 7ad94c716d6403233d04c4d37cb14df958c9b65d
a660c63c551b88136ac6176855b5907cc533e848Kay Sievers/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
a660c63c551b88136ac6176855b5907cc533e848Kay Sievers This file is part of systemd.
a660c63c551b88136ac6176855b5907cc533e848Kay Sievers Copyright 2010 Lennart Poettering
a660c63c551b88136ac6176855b5907cc533e848Kay Sievers systemd is free software; you can redistribute it and/or modify it
a660c63c551b88136ac6176855b5907cc533e848Kay Sievers under the terms of the GNU Lesser General Public License as published by
a660c63c551b88136ac6176855b5907cc533e848Kay Sievers the Free Software Foundation; either version 2.1 of the License, or
a660c63c551b88136ac6176855b5907cc533e848Kay Sievers (at your option) any later version.
a660c63c551b88136ac6176855b5907cc533e848Kay Sievers systemd is distributed in the hope that it will be useful, but
a660c63c551b88136ac6176855b5907cc533e848Kay Sievers WITHOUT ANY WARRANTY; without even the implied warranty of
a660c63c551b88136ac6176855b5907cc533e848Kay Sievers MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a660c63c551b88136ac6176855b5907cc533e848Kay Sievers Lesser General Public License for more details.
a660c63c551b88136ac6176855b5907cc533e848Kay Sievers You should have received a copy of the GNU Lesser General Public License
a660c63c551b88136ac6176855b5907cc533e848Kay Sievers along with systemd; If not, see <http://www.gnu.org/licenses/>.
1328f66ad16b5afeb5684858c27e121a46c1959eKay Sieversstatic const char* const systemd_running_as_table[_SYSTEMD_RUNNING_AS_MAX] = {
ad37f393fa97f4274cc3bf97a0d8c388a429037eKay SieversDEFINE_STRING_TABLE_LOOKUP(systemd_running_as, SystemdRunningAs);
0d6ce9236f61cb991d7e8f2359d818e41ead0cf5Kay Sievers const char *e;
ad37f393fa97f4274cc3bf97a0d8c388a429037eKay Sievers if (asprintf(config_home, "%s/systemd/user", e) < 0)
ad37f393fa97f4274cc3bf97a0d8c388a429037eKay Sievers const char *home;
de892aea1c486b59e04884268b612081d1660514Kay Sievers if (asprintf(config_home, "%s/.config/systemd/user", home) < 0)
f610d6de38119b372b377ec41b2a6089872d3294Kay Sieversstatic char** user_dirs(
f610d6de38119b372b377ec41b2a6089872d3294Kay Sievers const char * const config_unit_paths[] = {
f610d6de38119b372b377ec41b2a6089872d3294Kay Sievers const char * const data_unit_paths[] = {
a660c63c551b88136ac6176855b5907cc533e848Kay Sievers const char *home, *e;
a660c63c551b88136ac6176855b5907cc533e848Kay Sievers char **r = NULL, **t;
a660c63c551b88136ac6176855b5907cc533e848Kay Sievers /* Implement the mechanisms defined in
0260944060426d54d9ecb40930baad985cbd02a1Kay Sievers * http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html
0260944060426d54d9ecb40930baad985cbd02a1Kay Sievers * We look in both the config and the data dirs because we
0260944060426d54d9ecb40930baad985cbd02a1Kay Sievers * want to encourage that distributors ship their unit files
0260944060426d54d9ecb40930baad985cbd02a1Kay Sievers * as data, and allow overriding as configuration.
0260944060426d54d9ecb40930baad985cbd02a1Kay Sievers /* We don't treat /etc/xdg/systemd here as the spec
0260944060426d54d9ecb40930baad985cbd02a1Kay Sievers * suggests because we assume that that is a link to
0035597a30d120f70df2dd7da3d6128fb8ba6051Kay Sievers * /etc/systemd/ anyway. */
a660c63c551b88136ac6176855b5907cc533e848Kay Sievers if (asprintf(&data_home, "%s/systemd/user", e) < 0)
01d183ddae6fb3445c4519cf1d90c6575f17292eKay Sievers } else if (home) {
01d183ddae6fb3445c4519cf1d90c6575f17292eKay Sievers if (asprintf(&data_home, "%s/.local/share/systemd/user", home) < 0)
0035597a30d120f70df2dd7da3d6128fb8ba6051Kay Sievers /* There is really no need for two unit dirs in $HOME,
0035597a30d120f70df2dd7da3d6128fb8ba6051Kay Sievers * except to be fully compliant with the XDG spec. We
0035597a30d120f70df2dd7da3d6128fb8ba6051Kay Sievers * now try to link the two dirs, so that we can
0035597a30d120f70df2dd7da3d6128fb8ba6051Kay Sievers * minimize disk seeks a little. Further down we'll
0260944060426d54d9ecb40930baad985cbd02a1Kay Sievers * then filter out this link, if it is actually is
0035597a30d120f70df2dd7da3d6128fb8ba6051Kay Sievers (void) symlink("../../../.config/systemd/user", data_home);
de892aea1c486b59e04884268b612081d1660514Kay Sievers /* Now merge everything we found. */
1328f66ad16b5afeb5684858c27e121a46c1959eKay Sievers t = strv_merge_concat(r, config_dirs, "/systemd/user");
0035597a30d120f70df2dd7da3d6128fb8ba6051Kay Sievers t = strv_merge_concat(r, data_dirs, "/systemd/user");
0035597a30d120f70df2dd7da3d6128fb8ba6051Kay Sievers const char *e;
0035597a30d120f70df2dd7da3d6128fb8ba6051Kay Sievers /* First priority is whatever has been passed to us via env
0260944060426d54d9ecb40930baad985cbd02a1Kay Sievers /* Nothing is set, so let's figure something out. */
0260944060426d54d9ecb40930baad985cbd02a1Kay Sievers /* For the user units we include share/ in the search
0260944060426d54d9ecb40930baad985cbd02a1Kay Sievers * path in order to comply with the XDG basedir
0260944060426d54d9ecb40930baad985cbd02a1Kay Sievers * spec. For the system stuff we avoid such
0260944060426d54d9ecb40930baad985cbd02a1Kay Sievers * nonsense. OTOH we include /lib in the search path
0260944060426d54d9ecb40930baad985cbd02a1Kay Sievers * for the system stuff but avoid it for user
0260944060426d54d9ecb40930baad985cbd02a1Kay Sievers p->unit_path = user_dirs(generator, generator_early, generator_late);
0260944060426d54d9ecb40930baad985cbd02a1Kay Sievers /* If you modify this you also want to modify
0260944060426d54d9ecb40930baad985cbd02a1Kay Sievers * systemduserunitpath= in systemd.pc.in, and
0260944060426d54d9ecb40930baad985cbd02a1Kay Sievers * the arrays in user_dirs() above! */
0260944060426d54d9ecb40930baad985cbd02a1Kay Sievers /* If you modify this you also want to modify
0260944060426d54d9ecb40930baad985cbd02a1Kay Sievers * systemdsystemunitpath= in systemd.pc.in! */
d23965a64eb5c2c97b839dc2e3e79fc1613994f1Kay Sievers char _cleanup_free_ *t = strv_join(p->unit_path, "\n\t");
d23965a64eb5c2c97b839dc2e3e79fc1613994f1Kay Sievers log_info("Looking for unit files in (higher priority first):\n\t%s", t);
d23965a64eb5c2c97b839dc2e3e79fc1613994f1Kay Sievers /* /etc/init.d/ compatibility does not matter to users */
d23965a64eb5c2c97b839dc2e3e79fc1613994f1Kay Sievers p->sysvinit_path = path_split_and_make_absolute(e);
0260944060426d54d9ecb40930baad985cbd02a1Kay Sievers p->sysvrcnd_path = path_split_and_make_absolute(e);
d23965a64eb5c2c97b839dc2e3e79fc1613994f1Kay Sievers char _cleanup_free_ *t = strv_join(p->sysvinit_path, "\n\t");
d23965a64eb5c2c97b839dc2e3e79fc1613994f1Kay Sievers log_info("Looking for SysV init scripts in:\n\t%s", t);
d23965a64eb5c2c97b839dc2e3e79fc1613994f1Kay Sievers log_debug("Looking for SysV rcN.d links in:\n\t%s", t);
0260944060426d54d9ecb40930baad985cbd02a1Kay Sievers log_info("SysV init scripts and rcN.d links support disabled");