mirror of
https://github.com/systemd/systemd.git
synced 2024-12-23 21:35:11 +03:00
Merge pull request #15217 from keszybz/beef-up-sd-path
Export sd-path functions and beef up systemd-path to show more items
This commit is contained in:
commit
4a874560c5
@ -1,10 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!ENTITY MOUNT_PATH @MOUNT_PATH@>
|
||||
<!ENTITY UMOUNT_PATH @UMOUNT_PATH@>
|
||||
<!ENTITY systemgeneratordir @SYSTEM_GENERATOR_PATH@>
|
||||
<!ENTITY usergeneratordir @USER_GENERATOR_PATH@>
|
||||
<!ENTITY systemenvgeneratordir @SYSTEM_ENV_GENERATOR_PATH@>
|
||||
<!ENTITY userenvgeneratordir @USER_ENV_GENERATOR_PATH@>
|
||||
<!ENTITY systemgeneratordir @SYSTEM_GENERATOR_DIR@>
|
||||
<!ENTITY usergeneratordir @USER_GENERATOR_DIR@>
|
||||
<!ENTITY systemenvgeneratordir @SYSTEM_ENV_GENERATOR_DIR@>
|
||||
<!ENTITY userenvgeneratordir @USER_ENV_GENERATOR_DIR@>
|
||||
<!ENTITY CERTIFICATE_ROOT @CERTIFICATE_ROOT@>
|
||||
<!ENTITY MEMORY_ACCOUNTING_DEFAULT @MEMORY_ACCOUNTING_DEFAULT_YES_NO@>
|
||||
<!ENTITY KILL_USER_PROCESSES @KILL_USER_PROCESSES_YES_NO@>
|
||||
|
@ -6,6 +6,9 @@ if [ -z "$1" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# make sure the rules have been regenrated (in case man/update-man-rules was just run)
|
||||
ninja -C "@BUILD_ROOT@" version.h
|
||||
|
||||
target="man/$1.html"
|
||||
ninja -C "@BUILD_ROOT@" "$target"
|
||||
set -x
|
||||
|
@ -6,6 +6,9 @@ if [ -z "$1" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# make sure the rules have been regenrated (in case man/update-man-rules was just run)
|
||||
ninja -C "@BUILD_ROOT@" version.h
|
||||
|
||||
page="$(echo "$1" | sed 's/\./\\./')"
|
||||
target=$(ninja -C "@BUILD_ROOT@" -t query man/man | grep -E -m1 "man/$page\.[0-9]$" | awk '{print $2}')
|
||||
if [ -z "$target" ]; then
|
||||
|
9
man/path-documents.c
Normal file
9
man/path-documents.c
Normal file
@ -0,0 +1,9 @@
|
||||
#include <stdio.h>
|
||||
#include <sd-path.h>
|
||||
|
||||
int main(void) {
|
||||
char *t;
|
||||
|
||||
sd_path_lookup(SD_PATH_USER_DOCUMENTS, NULL, &t);
|
||||
printf("~/Documents: %s\n", t);
|
||||
}
|
@ -626,6 +626,7 @@ manpages = [
|
||||
'3',
|
||||
['sd_notifyf', 'sd_pid_notify', 'sd_pid_notify_with_fds', 'sd_pid_notifyf'],
|
||||
''],
|
||||
['sd_path_lookup', '3', ['sd_path_lookup_strv'], ''],
|
||||
['sd_pid_get_owner_uid',
|
||||
'3',
|
||||
['sd_peer_get_cgroup',
|
||||
|
215
man/sd_path_lookup.xml
Normal file
215
man/sd_path_lookup.xml
Normal file
@ -0,0 +1,215 @@
|
||||
<?xml version='1.0'?>
|
||||
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
|
||||
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
|
||||
<!-- SPDX-License-Identifier: LGPL-2.1+ -->
|
||||
|
||||
<refentry id="sd_path_lookup" xmlns:xi="http://www.w3.org/2001/XInclude">
|
||||
|
||||
<refentryinfo>
|
||||
<title>sd_path_lookup</title>
|
||||
<productname>systemd</productname>
|
||||
</refentryinfo>
|
||||
|
||||
<refmeta>
|
||||
<refentrytitle>sd_path_lookup</refentrytitle>
|
||||
<manvolnum>3</manvolnum>
|
||||
</refmeta>
|
||||
|
||||
<refnamediv>
|
||||
<refname>sd_path_lookup</refname>
|
||||
<refname>sd_path_lookup_strv</refname>
|
||||
|
||||
<refpurpose>Query well-known file system paths</refpurpose>
|
||||
</refnamediv>
|
||||
|
||||
<refsynopsisdiv>
|
||||
<funcsynopsis>
|
||||
<funcsynopsisinfo>#include <systemd/sd-path.h></funcsynopsisinfo>
|
||||
|
||||
<!-- note: individual constants are not added as <refname>s, there's just too many -->
|
||||
|
||||
<funcsynopsisinfo><token>enum</token> {
|
||||
<constant>SD_PATH_TEMPORARY</constant>,
|
||||
<constant>SD_PATH_TEMPORARY_LARGE</constant>,
|
||||
|
||||
<constant>SD_PATH_SYSTEM_BINARIES</constant>,
|
||||
<constant>SD_PATH_SYSTEM_INCLUDE</constant>,
|
||||
<constant>SD_PATH_SYSTEM_LIBRARY_PRIVATE</constant>,
|
||||
<constant>SD_PATH_SYSTEM_LIBRARY_ARCH</constant>,
|
||||
<constant>SD_PATH_SYSTEM_SHARED</constant>,
|
||||
<constant>SD_PATH_SYSTEM_CONFIGURATION_FACTORY</constant>,
|
||||
<constant>SD_PATH_SYSTEM_STATE_FACTORY</constant>,
|
||||
|
||||
<constant>SD_PATH_SYSTEM_CONFIGURATION</constant>,
|
||||
<constant>SD_PATH_SYSTEM_RUNTIME</constant>,
|
||||
<constant>SD_PATH_SYSTEM_RUNTIME_LOGS</constant>,
|
||||
<constant>SD_PATH_SYSTEM_STATE_PRIVATE</constant>,
|
||||
<constant>SD_PATH_SYSTEM_STATE_LOGS</constant>,
|
||||
<constant>SD_PATH_SYSTEM_STATE_CACHE</constant>,
|
||||
<constant>SD_PATH_SYSTEM_STATE_SPOOL</constant>,
|
||||
|
||||
<constant>SD_PATH_USER_BINARIES</constant>,
|
||||
<constant>SD_PATH_USER_LIBRARY_PRIVATE</constant>,
|
||||
<constant>SD_PATH_USER_LIBRARY_ARCH</constant>,
|
||||
<constant>SD_PATH_USER_SHARED</constant>,
|
||||
|
||||
<constant>SD_PATH_USER_CONFIGURATION</constant>,
|
||||
<constant>SD_PATH_USER_RUNTIME</constant>,
|
||||
<constant>SD_PATH_USER_STATE_CACHE</constant>,
|
||||
|
||||
<constant>SD_PATH_USER</constant>,
|
||||
<constant>SD_PATH_USER_DOCUMENTS</constant>,
|
||||
<constant>SD_PATH_USER_MUSIC</constant>,
|
||||
<constant>SD_PATH_USER_PICTURES</constant>,
|
||||
<constant>SD_PATH_USER_VIDEOS</constant>,
|
||||
<constant>SD_PATH_USER_DOWNLOAD</constant>,
|
||||
<constant>SD_PATH_USER_PUBLIC</constant>,
|
||||
<constant>SD_PATH_USER_TEMPLATES</constant>,
|
||||
<constant>SD_PATH_USER_DESKTOP</constant>,
|
||||
|
||||
<constant>SD_PATH_SEARCH_BINARIES</constant>,
|
||||
<constant>SD_PATH_SEARCH_BINARIES_DEFAULT</constant>,
|
||||
<constant>SD_PATH_SEARCH_LIBRARY_PRIVATE</constant>,
|
||||
<constant>SD_PATH_SEARCH_LIBRARY_ARCH</constant>,
|
||||
<constant>SD_PATH_SEARCH_SHARED</constant>,
|
||||
<constant>SD_PATH_SEARCH_CONFIGURATION_FACTORY</constant>,
|
||||
<constant>SD_PATH_SEARCH_STATE_FACTORY</constant>,
|
||||
<constant>SD_PATH_SEARCH_CONFIGURATION</constant>,
|
||||
|
||||
<constant>SD_PATH_SYSTEMD_UTIL_DIR</constant>,
|
||||
<constant>SD_PATH_SYSTEMD_SYSTEM_UNIT_DIR</constant>,
|
||||
<constant>SD_PATH_SYSTEMD_SYSTEM_PRESET_DIR</constant>,
|
||||
<constant>SD_PATH_SYSTEMD_USER_UNIT_DIR</constant>,
|
||||
<constant>SD_PATH_SYSTEMD_USER_PRESET_DIR</constant>,
|
||||
<constant>SD_PATH_SYSTEMD_SYSTEM_CONF_DIR</constant>,
|
||||
<constant>SD_PATH_SYSTEMD_USER_CONF_DIR</constant>,
|
||||
<constant>SD_PATH_SYSTEMD_SYSTEM_UNIT_PATH</constant>,
|
||||
<constant>SD_PATH_SYSTEMD_USER_UNIT_PATH</constant>,
|
||||
<constant>SD_PATH_SYSTEMD_SYSTEM_GENERATOR_DIR</constant>,
|
||||
<constant>SD_PATH_SYSTEMD_USER_GENERATOR_DIR</constant>,
|
||||
<constant>SD_PATH_SYSTEMD_SYSTEM_GENERATOR_PATH</constant>,
|
||||
<constant>SD_PATH_SYSTEMD_USER_GENERATOR_PATH</constant>,
|
||||
<constant>SD_PATH_SYSTEMD_SLEEP_DIR</constant>,
|
||||
<constant>SD_PATH_SYSTEMD_SHUTDOWN_DIR</constant>,
|
||||
|
||||
<constant>SD_PATH_TMPFILES_DIR</constant>,
|
||||
<constant>SD_PATH_SYSUSERS_DIR</constant>,
|
||||
<constant>SD_PATH_SYSCTL_DIR</constant>,
|
||||
<constant>SD_PATH_BINFMT_DIR</constant>,
|
||||
<constant>SD_PATH_MODULES_LOAD_DIR</constant>,
|
||||
<constant>SD_PATH_CATALOG_DIR</constant>,
|
||||
|
||||
<constant>SD_PATH_SYSTEMD_NETWORK_PATH</constant>,
|
||||
};</funcsynopsisinfo>
|
||||
|
||||
<funcprototype>
|
||||
<funcdef>int <function>sd_path_lookup</function></funcdef>
|
||||
<paramdef>uint64_t <parameter>type</parameter></paramdef>
|
||||
<paramdef>const char *<parameter>suffix</parameter></paramdef>
|
||||
<paramdef>char **<parameter>paths</parameter></paramdef>
|
||||
</funcprototype>
|
||||
|
||||
<funcprototype>
|
||||
<funcdef>int <function>sd_path_lookup_strv</function></funcdef>
|
||||
<paramdef>uint64_t <parameter>type</parameter></paramdef>
|
||||
<paramdef>const char *<parameter>suffix</parameter></paramdef>
|
||||
<paramdef>char ***<parameter>paths</parameter></paramdef>
|
||||
</funcprototype>
|
||||
</funcsynopsis>
|
||||
</refsynopsisdiv>
|
||||
|
||||
<refsect1>
|
||||
<title>Description</title>
|
||||
|
||||
<para><function>sd_path_lookup()</function> and <function>sd_bus_path_lookup_strv()</function> return a
|
||||
single path or set of file system paths specified by the argument <parameter>type</parameter>. In case of
|
||||
<function>sd_path_lookup()</function> a single <constant>NUL</constant>-terminated string is returned.
|
||||
When <parameter>type</parameter> specifies a set of paths, they are concatenated using
|
||||
<literal>:</literal> as a separator (as is traditionally done for e.g. <varname>$PATH</varname> or
|
||||
<varname>$LD_LIBRARY_PATH</varname>). In case of <function>sd_path_lookup_strv()</function> a
|
||||
<constant>NULL</constant>-terminated array of strings is returned (strv). If suffix
|
||||
<parameter>suffix</parameter> is given, it is concatenated to each of the paths after a slash
|
||||
(<literal>/</literal>). All returned paths are absolute.</para>
|
||||
|
||||
<para>For paths which refer to user directories, the relevant XDG standard is followed, with support for
|
||||
environment variables like <varname>$XDG_DOCUMENTS_DIR</varname>, <varname>$XDG_DESKTOP_DIR</varname>,
|
||||
..., and explicit configuration in <filename>/etc/xdg/user-dirs.conf</filename> or
|
||||
<filename>${XDG_CONFIG_HOME}/user-dirs.dirs</filename>. See
|
||||
<ulink url="https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html">
|
||||
XDG Base Directory Specification</ulink> for details.</para>
|
||||
|
||||
<para><citerefentry><refentrytitle>systemd-path</refentrytitle><manvolnum>1</manvolnum></citerefentry> is
|
||||
a wrapper around <function>sd_path_lookup()</function> and allows the same set of paths to be queried.
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
<title>Return Value</title>
|
||||
|
||||
<para>On success, <function>sd_path_lookup()</function> and <function>sd_path_lookup_strv()</function>
|
||||
return a non-negative integer. On failure, a negative errno-style error number is returned by either
|
||||
function.</para>
|
||||
|
||||
<para>The returned string or string array (strv) must be
|
||||
<citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>'d by the
|
||||
caller.</para>
|
||||
|
||||
<refsect2 id='errors'>
|
||||
<title>Errors</title>
|
||||
|
||||
<para>Returned errors may indicate the following problems:</para>
|
||||
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term><constant>-EOPNOTSUPP</constant></term>
|
||||
|
||||
<listitem><para>Unknown identifier <parameter>type</parameter>.</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><constant>-EINVAL</constant></term>
|
||||
|
||||
<listitem><para>Output argument is <constant>NULL</constant>.</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><constant>-ENXIO</constant></term>
|
||||
|
||||
<listitem><para>Query failed because of an undefined environment variable (e.g. for
|
||||
<constant>SD_PATH_USER_RUNTIME</constant> when <varname>$XDG_RUNTIME_DIR</varname> is not
|
||||
defined).</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><constant>-ENOMEM</constant></term>
|
||||
|
||||
<listitem><para>Memory allocation failed.</para></listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</refsect2>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
<title>Examples</title>
|
||||
|
||||
<refsect2>
|
||||
<title>Look up the location of ~/Documents</title>
|
||||
|
||||
<programlisting><xi:include href="path-documents.c" parse="text" /></programlisting>
|
||||
<para>Note that the default answer of <filename index='false'>$HOME/Documents</filename> may be
|
||||
overridden by <filename index='false'>user-dirs.conf</filename> or
|
||||
<varname>$XDG_DOCUMENTS_DIR</varname>.</para>
|
||||
</refsect2>
|
||||
</refsect1>
|
||||
|
||||
<xi:include href="libsystemd-pkgconfig.xml" />
|
||||
|
||||
<refsect1>
|
||||
<title>See Also</title>
|
||||
|
||||
<para>
|
||||
<citerefentry><refentrytitle>systemd-path</refentrytitle><manvolnum>1</manvolnum></citerefentry>
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
</refentry>
|
@ -32,7 +32,7 @@ key.middle/part/with/dots.foo = 123
|
||||
-key.that.will.not.fail = value
|
||||
key.pattern.*.with.glob = whatever
|
||||
-key.pattern.excluded.with.glob
|
||||
key.pattern.overriden.with.glob = custom
|
||||
key.pattern.overridden.with.glob = custom
|
||||
</programlisting>
|
||||
</refsynopsisdiv>
|
||||
|
||||
|
14
meson.build
14
meson.build
@ -196,7 +196,7 @@ memory_accounting_default = get_option('memory-accounting-default')
|
||||
status_unit_format_default = get_option('status-unit-format-default')
|
||||
|
||||
conf.set_quoted('PKGSYSCONFDIR', pkgsysconfdir)
|
||||
conf.set_quoted('SYSTEM_CONFIG_UNIT_PATH', join_paths(pkgsysconfdir, 'system'))
|
||||
conf.set_quoted('SYSTEM_CONFIG_UNIT_DIR', join_paths(pkgsysconfdir, 'system'))
|
||||
conf.set_quoted('SYSTEM_DATA_UNIT_PATH', systemunitdir)
|
||||
conf.set_quoted('SYSTEM_SYSVINIT_PATH', sysvinit_path)
|
||||
conf.set_quoted('SYSTEM_SYSVRCND_PATH', sysvrcnd_path)
|
||||
@ -204,8 +204,8 @@ conf.set_quoted('RC_LOCAL_SCRIPT_PATH_START', get_option('rc-loc
|
||||
|
||||
conf.set('ANSI_OK_COLOR', 'ANSI_' + get_option('ok-color').underscorify().to_upper())
|
||||
|
||||
conf.set_quoted('USER_CONFIG_UNIT_PATH', join_paths(pkgsysconfdir, 'user'))
|
||||
conf.set_quoted('USER_DATA_UNIT_PATH', userunitdir)
|
||||
conf.set_quoted('USER_CONFIG_UNIT_DIR', join_paths(pkgsysconfdir, 'user'))
|
||||
conf.set_quoted('USER_DATA_UNIT_DIR', userunitdir)
|
||||
conf.set_quoted('CERTIFICATE_ROOT', get_option('certificate-root'))
|
||||
conf.set_quoted('CATALOG_DATABASE', join_paths(catalogstatedir, 'database'))
|
||||
conf.set_quoted('SYSTEMD_CGROUP_AGENT_PATH', join_paths(rootlibexecdir, 'systemd-cgroups-agent'))
|
||||
@ -221,10 +221,10 @@ conf.set_quoted('ROOTPREFIX', rootprefixdir)
|
||||
conf.set_quoted('RANDOM_SEED_DIR', randomseeddir)
|
||||
conf.set_quoted('RANDOM_SEED', join_paths(randomseeddir, 'random-seed'))
|
||||
conf.set_quoted('SYSTEMD_CRYPTSETUP_PATH', join_paths(rootlibexecdir, 'systemd-cryptsetup'))
|
||||
conf.set_quoted('SYSTEM_GENERATOR_PATH', systemgeneratordir)
|
||||
conf.set_quoted('USER_GENERATOR_PATH', usergeneratordir)
|
||||
conf.set_quoted('SYSTEM_ENV_GENERATOR_PATH', systemenvgeneratordir)
|
||||
conf.set_quoted('USER_ENV_GENERATOR_PATH', userenvgeneratordir)
|
||||
conf.set_quoted('SYSTEM_GENERATOR_DIR', systemgeneratordir)
|
||||
conf.set_quoted('USER_GENERATOR_DIR', usergeneratordir)
|
||||
conf.set_quoted('SYSTEM_ENV_GENERATOR_DIR', systemenvgeneratordir)
|
||||
conf.set_quoted('USER_ENV_GENERATOR_DIR', userenvgeneratordir)
|
||||
conf.set_quoted('SYSTEM_SHUTDOWN_PATH', systemshutdowndir)
|
||||
conf.set_quoted('SYSTEM_SLEEP_PATH', systemsleepdir)
|
||||
conf.set_quoted('SYSTEMD_KBD_MODEL_MAP', join_paths(pkgdatadir, 'kbd-model-map'))
|
||||
|
@ -159,6 +159,8 @@ basic_sources = files('''
|
||||
ordered-set.h
|
||||
parse-util.c
|
||||
parse-util.h
|
||||
path-lookup.c
|
||||
path-lookup.h
|
||||
path-util.c
|
||||
path-util.h
|
||||
prioq.c
|
||||
|
@ -6,19 +6,15 @@
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "fs-util.h"
|
||||
#include "install.h"
|
||||
#include "log.h"
|
||||
#include "macro.h"
|
||||
#include "mkdir.h"
|
||||
#include "path-lookup.h"
|
||||
#include "path-util.h"
|
||||
#include "rm-rf.h"
|
||||
#include "stat-util.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "tmpfile-util.h"
|
||||
#include "user-util.h"
|
||||
#include "util.h"
|
||||
|
||||
int xdg_user_runtime_dir(char **ret, const char *suffix) {
|
||||
const char *e;
|
||||
@ -100,14 +96,14 @@ int xdg_user_data_dir(char **ret, const char *suffix) {
|
||||
static const char* const user_data_unit_paths[] = {
|
||||
"/usr/local/lib/systemd/user",
|
||||
"/usr/local/share/systemd/user",
|
||||
USER_DATA_UNIT_PATH,
|
||||
USER_DATA_UNIT_DIR,
|
||||
"/usr/lib/systemd/user",
|
||||
"/usr/share/systemd/user",
|
||||
NULL
|
||||
};
|
||||
|
||||
static const char* const user_config_unit_paths[] = {
|
||||
USER_CONFIG_UNIT_PATH,
|
||||
USER_CONFIG_UNIT_DIR,
|
||||
"/etc/systemd/user",
|
||||
NULL
|
||||
};
|
||||
@ -325,12 +321,12 @@ static int acquire_config_dirs(UnitFileScope scope, char **persistent, char **ru
|
||||
switch (scope) {
|
||||
|
||||
case UNIT_FILE_SYSTEM:
|
||||
a = strdup(SYSTEM_CONFIG_UNIT_PATH);
|
||||
a = strdup(SYSTEM_CONFIG_UNIT_DIR);
|
||||
b = strdup("/run/systemd/system");
|
||||
break;
|
||||
|
||||
case UNIT_FILE_GLOBAL:
|
||||
a = strdup(USER_CONFIG_UNIT_PATH);
|
||||
a = strdup(USER_CONFIG_UNIT_DIR);
|
||||
b = strdup("/run/systemd/user");
|
||||
break;
|
||||
|
||||
@ -618,7 +614,7 @@ int lookup_paths_init(
|
||||
STRV_IFNOTNULL(transient),
|
||||
STRV_IFNOTNULL(generator_early),
|
||||
persistent_config,
|
||||
SYSTEM_CONFIG_UNIT_PATH,
|
||||
SYSTEM_CONFIG_UNIT_DIR,
|
||||
"/etc/systemd/system",
|
||||
STRV_IFNOTNULL(persistent_attached),
|
||||
runtime_config,
|
||||
@ -642,7 +638,7 @@ int lookup_paths_init(
|
||||
STRV_IFNOTNULL(transient),
|
||||
STRV_IFNOTNULL(generator_early),
|
||||
persistent_config,
|
||||
USER_CONFIG_UNIT_PATH,
|
||||
USER_CONFIG_UNIT_DIR,
|
||||
"/etc/systemd/user",
|
||||
runtime_config,
|
||||
"/run/systemd/user",
|
||||
@ -650,7 +646,7 @@ int lookup_paths_init(
|
||||
"/usr/local/share/systemd/user",
|
||||
"/usr/share/systemd/user",
|
||||
"/usr/local/lib/systemd/user",
|
||||
USER_DATA_UNIT_PATH,
|
||||
USER_DATA_UNIT_DIR,
|
||||
"/usr/lib/systemd/user",
|
||||
STRV_IFNOTNULL(generator_late));
|
||||
break;
|
||||
@ -783,56 +779,6 @@ void lookup_paths_log(LookupPaths *p) {
|
||||
}
|
||||
}
|
||||
|
||||
int lookup_paths_mkdir_generator(LookupPaths *p) {
|
||||
int r, q;
|
||||
|
||||
assert(p);
|
||||
|
||||
if (!p->generator || !p->generator_early || !p->generator_late)
|
||||
return -EINVAL;
|
||||
|
||||
r = mkdir_p_label(p->generator, 0755);
|
||||
|
||||
q = mkdir_p_label(p->generator_early, 0755);
|
||||
if (q < 0 && r >= 0)
|
||||
r = q;
|
||||
|
||||
q = mkdir_p_label(p->generator_late, 0755);
|
||||
if (q < 0 && r >= 0)
|
||||
r = q;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void lookup_paths_trim_generator(LookupPaths *p) {
|
||||
assert(p);
|
||||
|
||||
/* Trim empty dirs */
|
||||
|
||||
if (p->generator)
|
||||
(void) rmdir(p->generator);
|
||||
if (p->generator_early)
|
||||
(void) rmdir(p->generator_early);
|
||||
if (p->generator_late)
|
||||
(void) rmdir(p->generator_late);
|
||||
}
|
||||
|
||||
void lookup_paths_flush_generator(LookupPaths *p) {
|
||||
assert(p);
|
||||
|
||||
/* Flush the generated unit files in full */
|
||||
|
||||
if (p->generator)
|
||||
(void) rm_rf(p->generator, REMOVE_ROOT|REMOVE_PHYSICAL);
|
||||
if (p->generator_early)
|
||||
(void) rm_rf(p->generator_early, REMOVE_ROOT|REMOVE_PHYSICAL);
|
||||
if (p->generator_late)
|
||||
(void) rm_rf(p->generator_late, REMOVE_ROOT|REMOVE_PHYSICAL);
|
||||
|
||||
if (p->temporary_dir)
|
||||
(void) rm_rf(p->temporary_dir, REMOVE_ROOT|REMOVE_PHYSICAL);
|
||||
}
|
||||
|
||||
char **generator_binary_paths(UnitFileScope scope) {
|
||||
bool append = false; /* Add items from SYSTEMD_GENERATOR_PATH before normal directories */
|
||||
_cleanup_strv_free_ char **paths = NULL;
|
||||
@ -852,7 +798,7 @@ char **generator_binary_paths(UnitFileScope scope) {
|
||||
add = strv_new("/run/systemd/system-generators",
|
||||
"/etc/systemd/system-generators",
|
||||
"/usr/local/lib/systemd/system-generators",
|
||||
SYSTEM_GENERATOR_PATH);
|
||||
SYSTEM_GENERATOR_DIR);
|
||||
break;
|
||||
|
||||
case UNIT_FILE_GLOBAL:
|
||||
@ -860,7 +806,7 @@ char **generator_binary_paths(UnitFileScope scope) {
|
||||
add = strv_new("/run/systemd/user-generators",
|
||||
"/etc/systemd/user-generators",
|
||||
"/usr/local/lib/systemd/user-generators",
|
||||
USER_GENERATOR_PATH);
|
||||
USER_GENERATOR_DIR);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -899,12 +845,12 @@ char **env_generator_binary_paths(bool is_system) {
|
||||
add = strv_new("/run/systemd/system-environment-generators",
|
||||
"/etc/systemd/system-environment-generators",
|
||||
"/usr/local/lib/systemd/system-environment-generators",
|
||||
SYSTEM_ENV_GENERATOR_PATH);
|
||||
SYSTEM_ENV_GENERATOR_DIR);
|
||||
else
|
||||
add = strv_new("/run/systemd/user-environment-generators",
|
||||
"/etc/systemd/user-environment-generators",
|
||||
"/usr/local/lib/systemd/user-environment-generators",
|
||||
USER_ENV_GENERATOR_PATH);
|
||||
USER_ENV_GENERATOR_DIR);
|
||||
|
||||
if (!add)
|
||||
return NULL;
|
@ -5,6 +5,7 @@
|
||||
|
||||
typedef struct LookupPaths LookupPaths;
|
||||
|
||||
#include "def.h"
|
||||
#include "unit-file.h"
|
||||
#include "macro.h"
|
||||
|
||||
@ -64,12 +65,10 @@ bool path_is_user_data_dir(const char *path);
|
||||
bool path_is_user_config_dir(const char *path);
|
||||
|
||||
void lookup_paths_log(LookupPaths *p);
|
||||
|
||||
int lookup_paths_mkdir_generator(LookupPaths *p);
|
||||
void lookup_paths_trim_generator(LookupPaths *p);
|
||||
void lookup_paths_flush_generator(LookupPaths *p);
|
||||
|
||||
void lookup_paths_free(LookupPaths *p);
|
||||
|
||||
char **generator_binary_paths(UnitFileScope scope);
|
||||
char **env_generator_binary_paths(bool is_system);
|
||||
|
||||
#define NETWORK_DIRS ((const char* const*) CONF_PATHS_STRV("systemd/network"))
|
||||
#define NETWORK_DIRS_NULSTR CONF_PATHS_NULSTR("systemd/network")
|
@ -87,6 +87,16 @@ char **strv_parse_nulstr(const char *s, size_t l);
|
||||
char **strv_split_nulstr(const char *s);
|
||||
int strv_make_nulstr(char * const *l, char **p, size_t *n);
|
||||
|
||||
static inline int strv_from_nulstr(char ***a, const char *nulstr) {
|
||||
char **t;
|
||||
|
||||
t = strv_split_nulstr(nulstr);
|
||||
if (!t)
|
||||
return -ENOMEM;
|
||||
*a = t;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool strv_overlap(char * const *a, char * const *b) _pure_;
|
||||
|
||||
#define STRV_FOREACH(s, l) \
|
||||
|
58
src/core/generator-setup.c
Normal file
58
src/core/generator-setup.c
Normal file
@ -0,0 +1,58 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "generator-setup.h"
|
||||
#include "macro.h"
|
||||
#include "mkdir.h"
|
||||
#include "rm-rf.h"
|
||||
|
||||
int lookup_paths_mkdir_generator(LookupPaths *p) {
|
||||
int r, q;
|
||||
|
||||
assert(p);
|
||||
|
||||
if (!p->generator || !p->generator_early || !p->generator_late)
|
||||
return -EINVAL;
|
||||
|
||||
r = mkdir_p_label(p->generator, 0755);
|
||||
|
||||
q = mkdir_p_label(p->generator_early, 0755);
|
||||
if (q < 0 && r >= 0)
|
||||
r = q;
|
||||
|
||||
q = mkdir_p_label(p->generator_late, 0755);
|
||||
if (q < 0 && r >= 0)
|
||||
r = q;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void lookup_paths_trim_generator(LookupPaths *p) {
|
||||
assert(p);
|
||||
|
||||
/* Trim empty dirs */
|
||||
|
||||
if (p->generator)
|
||||
(void) rmdir(p->generator);
|
||||
if (p->generator_early)
|
||||
(void) rmdir(p->generator_early);
|
||||
if (p->generator_late)
|
||||
(void) rmdir(p->generator_late);
|
||||
}
|
||||
|
||||
void lookup_paths_flush_generator(LookupPaths *p) {
|
||||
assert(p);
|
||||
|
||||
/* Flush the generated unit files in full */
|
||||
|
||||
if (p->generator)
|
||||
(void) rm_rf(p->generator, REMOVE_ROOT|REMOVE_PHYSICAL);
|
||||
if (p->generator_early)
|
||||
(void) rm_rf(p->generator_early, REMOVE_ROOT|REMOVE_PHYSICAL);
|
||||
if (p->generator_late)
|
||||
(void) rm_rf(p->generator_late, REMOVE_ROOT|REMOVE_PHYSICAL);
|
||||
|
||||
if (p->temporary_dir)
|
||||
(void) rm_rf(p->temporary_dir, REMOVE_ROOT|REMOVE_PHYSICAL);
|
||||
}
|
8
src/core/generator-setup.h
Normal file
8
src/core/generator-setup.h
Normal file
@ -0,0 +1,8 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
#include "path-lookup.h"
|
||||
|
||||
int lookup_paths_mkdir_generator(LookupPaths *p);
|
||||
void lookup_paths_trim_generator(LookupPaths *p);
|
||||
void lookup_paths_flush_generator(LookupPaths *p);
|
@ -44,6 +44,7 @@
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "fs-util.h"
|
||||
#include "generator-setup.h"
|
||||
#include "hashmap.h"
|
||||
#include "install.h"
|
||||
#include "io-util.h"
|
||||
@ -689,7 +690,7 @@ static int manager_setup_prefix(Manager *m) {
|
||||
p = paths_user;
|
||||
|
||||
for (i = 0; i < _EXEC_DIRECTORY_TYPE_MAX; i++) {
|
||||
r = sd_path_home(p[i].type, p[i].suffix, &m->prefix[i]);
|
||||
r = sd_path_lookup(p[i].type, p[i].suffix, &m->prefix[i]);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
@ -72,6 +72,8 @@ libcore_sources = '''
|
||||
emergency-action.h
|
||||
execute.c
|
||||
execute.h
|
||||
generator-setup.c
|
||||
generator-setup.h
|
||||
hostname-setup.c
|
||||
hostname-setup.h
|
||||
ima-setup.c
|
||||
|
@ -7,36 +7,93 @@
|
||||
# the Free Software Foundation; either version 2.1 of the License, or
|
||||
# (at your option) any later version.
|
||||
|
||||
# Names with prefixes are prefered, and the run-together names should be
|
||||
# considered deprecated (though there is no plan to remove them). New names
|
||||
# shall have underscores.
|
||||
|
||||
prefix=@prefix@
|
||||
rootprefix=@rootprefix_noslash@
|
||||
sysconfdir=@sysconfdir@
|
||||
systemdutildir=${rootprefix}/lib/systemd
|
||||
systemdsystemunitdir=${rootprefix}/lib/systemd/system
|
||||
systemdsystempresetdir=${rootprefix}/lib/systemd/system-preset
|
||||
systemduserunitdir=${prefix}/lib/systemd/user
|
||||
systemduserpresetdir=${prefix}/lib/systemd/user-preset
|
||||
systemdsystemconfdir=${sysconfdir}/systemd/system
|
||||
systemduserconfdir=${sysconfdir}/systemd/user
|
||||
systemdsystemunitpath=${systemdsystemconfdir}:/etc/systemd/system:/run/systemd/system:/usr/local/lib/systemd/system:${systemdsystemunitdir}:/usr/lib/systemd/system:/lib/systemd/system
|
||||
systemduserunitpath=${systemduserconfdir}:/etc/systemd/user:/run/systemd/user:/usr/local/lib/systemd/user:/usr/local/share/systemd/user:${systemduserunitdir}:/usr/lib/systemd/user:/usr/share/systemd/user
|
||||
systemdsystemgeneratordir=${rootprefix}/lib/systemd/system-generators
|
||||
systemdusergeneratordir=${prefix}/lib/systemd/user-generators
|
||||
systemdsystemgeneratorpath=/run/systemd/system-generators:/etc/systemd/system-generators:/usr/local/lib/systemd/system-generators:${systemdsystemgeneratordir}
|
||||
systemdusergeneratorpath=/run/systemd/user-generators:/etc/systemd/user-generators:/usr/local/lib/systemd/user-generators:${systemdusergeneratordir}
|
||||
systemdsleepdir=${rootprefix}/lib/systemd/system-sleep
|
||||
systemdshutdowndir=${rootprefix}/lib/systemd/system-shutdown
|
||||
tmpfilesdir=${prefix}/lib/tmpfiles.d
|
||||
sysusersdir=${prefix}/lib/sysusers.d
|
||||
sysctldir=${prefix}/lib/sysctl.d
|
||||
binfmtdir=${prefix}/lib/binfmt.d
|
||||
modulesloaddir=${prefix}/lib/modules-load.d
|
||||
catalogdir=${prefix}/lib/systemd/catalog
|
||||
systemuidmax=@systemuidmax@
|
||||
systemgidmax=@systemgidmax@
|
||||
dynamicuidmin=@dynamicuidmin@
|
||||
dynamicuidmax=@dynamicuidmax@
|
||||
containeruidbasemin=@containeruidbasemin@
|
||||
containeruidbasemax=@containeruidbasemax@
|
||||
root_prefix=@rootprefix_noslash@
|
||||
rootprefix=${root_prefix}
|
||||
sysconf_dir=@sysconfdir@
|
||||
sysconfdir=${sysconf_dir}
|
||||
|
||||
systemd_util_dir=${root_prefix}/lib/systemd
|
||||
systemdutildir=${systemd_util_dir}
|
||||
|
||||
systemd_system_unit_dir=${rootprefix}/lib/systemd/system
|
||||
systemdsystemunitdir=${systemd_system_unit_dir}
|
||||
|
||||
systemd_system_preset_dir=${rootprefix}/lib/systemd/system-preset
|
||||
systemdsystempresetdir=${systemd_system_preset_dir}
|
||||
|
||||
systemd_user_unit_dir=${prefix}/lib/systemd/user
|
||||
systemduserunitdir=${systemd_user_unit_dir}
|
||||
|
||||
systemd_user_preset_dir=${prefix}/lib/systemd/user-preset
|
||||
systemduserpresetdir=${systemd_user_preset_dir}
|
||||
|
||||
systemd_system_conf_dir=${sysconfdir}/systemd/system
|
||||
systemdsystemconfdir=${systemd_system_conf_dir}
|
||||
|
||||
systemd_user_conf_dir=${sysconfdir}/systemd/user
|
||||
systemduserconfdir=${systemd_user_conf_dir}
|
||||
|
||||
systemd_system_unit_path=${systemd_system_conf_dir}:/etc/systemd/system:/run/systemd/system:/usr/local/lib/systemd/system:${systemd_system_unit_dir}:/usr/lib/systemd/system:/lib/systemd/system
|
||||
systemdsystemunitpath=${systemd_system_unit_path}
|
||||
|
||||
systemd_user_unit_path=${systemd_user_conf_dir}:/etc/systemd/user:/run/systemd/user:/usr/local/lib/systemd/user:/usr/local/share/systemd/user:${systemd_user_unit_dir}:/usr/lib/systemd/user:/usr/share/systemd/user
|
||||
systemduserunitpath=${systemd_user_unit_path}
|
||||
|
||||
systemd_system_generator_dir=${root_prefix}/lib/systemd/system-generators
|
||||
systemdsystemgeneratordir=${systemd_system_generator_dir}
|
||||
|
||||
systemd_user_generator_dir=${prefix}/lib/systemd/user-generators
|
||||
systemdusergeneratordir=${systemd_user_generator_dir}
|
||||
|
||||
systemd_system_generator_path=/run/systemd/system-generators:/etc/systemd/system-generators:/usr/local/lib/systemd/system-generators:${systemd_system_generator_dir}
|
||||
systemdsystemgeneratorpath=${systemd_system_generator_path}
|
||||
|
||||
systemd_user_generator_path=/run/systemd/user-generators:/etc/systemd/user-generators:/usr/local/lib/systemd/user-generators:${systemd_user_generator_dir}
|
||||
systemdusergeneratorpath=${systemd_user_generator_path}
|
||||
|
||||
systemd_sleep_dir=${root_prefix}/lib/systemd/system-sleep
|
||||
systemdsleepdir=${systemd_sleep_dir}
|
||||
|
||||
systemd_shutdown_dir=${root_prefix}/lib/systemd/system-shutdown
|
||||
systemdshutdowndir=${systemd_shutdown_dir}
|
||||
|
||||
tmpfiles_dir=${prefix}/lib/tmpfiles.d
|
||||
tmpfilesdir=${tmpfiles_dir}
|
||||
|
||||
sysusers_dir=${prefix}/lib/sysusers.d
|
||||
sysusersdir=${sysusers_dir}
|
||||
|
||||
sysctl_dir=${prefix}/lib/sysctl.d
|
||||
sysctldir=${sysctl_dir}
|
||||
|
||||
binfmt_dir=${prefix}/lib/binfmt.d
|
||||
binfmtdir=${binfmt_dir}
|
||||
|
||||
modules_load_dir=${prefix}/lib/modules-load.d
|
||||
modulesloaddir=${modules_load_dir}
|
||||
|
||||
catalog_dir=${prefix}/lib/systemd/catalog
|
||||
catalogdir=${catalog_dir}
|
||||
|
||||
system_uid_max=@systemuidmax@
|
||||
systemuidmax=${system_uid_max}
|
||||
system_gid_max=@systemgidmax@
|
||||
systemgidmax=${system_gid_max}
|
||||
|
||||
dynamic_uid_min=@dynamicuidmin@
|
||||
dynamicuidmin=${dynamic_uid_min}
|
||||
dynamic_uid_max=@dynamicuidmax@
|
||||
dynamicuidmax=${dynamic_uid_max}
|
||||
|
||||
container_uid_base_min=@containeruidbasemin@
|
||||
containeruidbasemin=${container_uid_base_min}
|
||||
container_uid_base_max=@containeruidbasemax@
|
||||
containeruidbasemax=${container_uid_base_max}
|
||||
|
||||
Name: systemd
|
||||
Description: systemd System and Service Manager
|
||||
|
@ -20,7 +20,7 @@ static int environment_dirs(char ***ret) {
|
||||
return -ENOMEM;
|
||||
|
||||
/* ~/.config/systemd/environment.d */
|
||||
r = sd_path_home(SD_PATH_USER_CONFIGURATION, "environment.d", &c);
|
||||
r = sd_path_lookup(SD_PATH_USER_CONFIGURATION, "environment.d", &c);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include "sd-dhcp-lease.h"
|
||||
|
||||
#include "conf-parser.h"
|
||||
#include "def.h"
|
||||
#include "set.h"
|
||||
#include "strv.h"
|
||||
|
||||
@ -66,5 +65,3 @@ int deserialize_dhcp_routes(struct sd_dhcp_route **ret, size_t *ret_size, size_t
|
||||
|
||||
/* It is not necessary to add deserialize_dhcp_option(). Use unhexmem() instead. */
|
||||
int serialize_dhcp_option(FILE *f, const char *key, const void *data, size_t size);
|
||||
|
||||
#define NETWORK_DIRS ((const char* const*) CONF_PATHS_STRV("systemd/network"))
|
||||
|
@ -697,3 +697,9 @@ global:
|
||||
sd_event_source_send_child_signal;
|
||||
sd_journal_open_namespace;
|
||||
} LIBSYSTEMD_243;
|
||||
|
||||
LIBSYSTEMD_246 {
|
||||
global:
|
||||
sd_path_lookup;
|
||||
sd_path_lookup_strv;
|
||||
} LIBSYSTEMD_245;
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "fs-util.h"
|
||||
#include "path-lookup.h"
|
||||
#include "path-util.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
@ -318,64 +319,130 @@ static int get_path(uint64_t type, char **buffer, const char **ret) {
|
||||
|
||||
case SD_PATH_USER_DESKTOP:
|
||||
return from_user_dir("XDG_DESKTOP_DIR", buffer, ret);
|
||||
|
||||
case SD_PATH_SYSTEMD_UTIL_DIR:
|
||||
*ret = ROOTPREFIX "lib/systemd";
|
||||
return 0;
|
||||
|
||||
case SD_PATH_SYSTEMD_SYSTEM_UNIT_DIR:
|
||||
*ret = SYSTEM_DATA_UNIT_PATH;
|
||||
return 0;
|
||||
|
||||
case SD_PATH_SYSTEMD_SYSTEM_PRESET_DIR:
|
||||
*ret = ROOTPREFIX "lib/systemd/system-preset";
|
||||
return 0;
|
||||
|
||||
case SD_PATH_SYSTEMD_USER_UNIT_DIR:
|
||||
*ret = USER_DATA_UNIT_DIR;
|
||||
return 0;
|
||||
|
||||
case SD_PATH_SYSTEMD_USER_PRESET_DIR:
|
||||
*ret = ROOTPREFIX "lib/systemd/user-preset";
|
||||
return 0;
|
||||
|
||||
case SD_PATH_SYSTEMD_SYSTEM_CONF_DIR:
|
||||
*ret = SYSTEM_CONFIG_UNIT_DIR;
|
||||
return 0;
|
||||
|
||||
case SD_PATH_SYSTEMD_USER_CONF_DIR:
|
||||
*ret = USER_CONFIG_UNIT_DIR;
|
||||
return 0;
|
||||
|
||||
case SD_PATH_SYSTEMD_SYSTEM_GENERATOR_DIR:
|
||||
*ret = SYSTEM_GENERATOR_DIR;
|
||||
return 0;
|
||||
|
||||
case SD_PATH_SYSTEMD_USER_GENERATOR_DIR:
|
||||
*ret = USER_GENERATOR_DIR;
|
||||
return 0;
|
||||
|
||||
case SD_PATH_SYSTEMD_SLEEP_DIR:
|
||||
*ret = ROOTPREFIX "lib/systemd/system-sleep";
|
||||
return 0;
|
||||
|
||||
case SD_PATH_SYSTEMD_SHUTDOWN_DIR:
|
||||
*ret = ROOTPREFIX "lib/systemd/system-shutdown";
|
||||
return 0;
|
||||
|
||||
/* FIXME: systemd.pc uses ${prefix}, but CONF_PATHS_NULSTR doesn't.
|
||||
* Should ${prefix} use in systemd.pc be removed? */
|
||||
case SD_PATH_TMPFILES_DIR:
|
||||
*ret = "/usr/lib/tmpfiles.d";
|
||||
return 0;
|
||||
|
||||
case SD_PATH_SYSUSERS_DIR:
|
||||
*ret = "/usr/lib/sysusers.d";
|
||||
return 0;
|
||||
|
||||
case SD_PATH_SYSCTL_DIR:
|
||||
*ret = "/usr/lib/sysctl.d";
|
||||
return 0;
|
||||
|
||||
case SD_PATH_BINFMT_DIR:
|
||||
*ret = "/usr/lib/binfmt.d";
|
||||
return 0;
|
||||
|
||||
case SD_PATH_MODULES_LOAD_DIR:
|
||||
*ret = "/usr/lib/modules-load.d";
|
||||
return 0;
|
||||
|
||||
case SD_PATH_CATALOG_DIR:
|
||||
*ret = "/usr/lib/systemd/catalog";
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
||||
_public_ int sd_path_home(uint64_t type, const char *suffix, char **path) {
|
||||
static int get_path_alloc(uint64_t type, const char *suffix, char **path) {
|
||||
_cleanup_free_ char *buffer = NULL;
|
||||
char *buffer2 = NULL;
|
||||
const char *ret;
|
||||
char *cc;
|
||||
int r;
|
||||
|
||||
assert_return(path, -EINVAL);
|
||||
|
||||
if (IN_SET(type,
|
||||
SD_PATH_SEARCH_BINARIES,
|
||||
SD_PATH_SEARCH_BINARIES_DEFAULT,
|
||||
SD_PATH_SEARCH_LIBRARY_PRIVATE,
|
||||
SD_PATH_SEARCH_LIBRARY_ARCH,
|
||||
SD_PATH_SEARCH_SHARED,
|
||||
SD_PATH_SEARCH_CONFIGURATION_FACTORY,
|
||||
SD_PATH_SEARCH_STATE_FACTORY,
|
||||
SD_PATH_SEARCH_CONFIGURATION)) {
|
||||
|
||||
_cleanup_strv_free_ char **l = NULL;
|
||||
|
||||
r = sd_path_search(type, suffix, &l);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
buffer = strv_join(l, ":");
|
||||
if (!buffer)
|
||||
return -ENOMEM;
|
||||
|
||||
*path = TAKE_PTR(buffer);
|
||||
return 0;
|
||||
}
|
||||
assert(path);
|
||||
|
||||
r = get_path(type, &buffer, &ret);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (!suffix) {
|
||||
if (!buffer) {
|
||||
buffer = strdup(ret);
|
||||
if (!buffer)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
*path = TAKE_PTR(buffer);
|
||||
return 0;
|
||||
if (suffix) {
|
||||
suffix += strspn(suffix, "/");
|
||||
buffer2 = path_join(ret, suffix);
|
||||
if (!buffer2)
|
||||
return -ENOMEM;
|
||||
} else if (!buffer) {
|
||||
buffer = strdup(ret);
|
||||
if (!buffer)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
suffix += strspn(suffix, "/");
|
||||
cc = path_join(ret, suffix);
|
||||
if (!cc)
|
||||
*path = buffer2 ?: TAKE_PTR(buffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
_public_ int sd_path_lookup(uint64_t type, const char *suffix, char **path) {
|
||||
int r;
|
||||
|
||||
assert_return(path, -EINVAL);
|
||||
|
||||
r = get_path_alloc(type, suffix, path);
|
||||
if (r != -EOPNOTSUPP)
|
||||
return r;
|
||||
|
||||
/* Fall back to sd_path_lookup_strv */
|
||||
_cleanup_strv_free_ char **l = NULL;
|
||||
char *buffer;
|
||||
|
||||
r = sd_path_lookup_strv(type, suffix, &l);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
buffer = strv_join(l, ":");
|
||||
if (!buffer)
|
||||
return -ENOMEM;
|
||||
|
||||
*path = TAKE_PTR(cc);
|
||||
*path = buffer;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -454,6 +521,7 @@ static int search_from_environment(
|
||||
#endif
|
||||
|
||||
static int get_search(uint64_t type, char ***list) {
|
||||
int r;
|
||||
|
||||
assert(list);
|
||||
|
||||
@ -536,58 +604,69 @@ static int get_search(uint64_t type, char ***list) {
|
||||
"/etc",
|
||||
NULL);
|
||||
|
||||
case SD_PATH_SEARCH_BINARIES_DEFAULT: {
|
||||
char **t;
|
||||
case SD_PATH_SEARCH_BINARIES_DEFAULT:
|
||||
return strv_from_nulstr(list, DEFAULT_PATH_NULSTR);
|
||||
|
||||
t = strv_split_nulstr(DEFAULT_PATH_NULSTR);
|
||||
case SD_PATH_SYSTEMD_SYSTEM_UNIT_PATH:
|
||||
case SD_PATH_SYSTEMD_USER_UNIT_PATH: {
|
||||
_cleanup_(lookup_paths_free) LookupPaths lp = {};
|
||||
const UnitFileScope scope = type == SD_PATH_SYSTEMD_SYSTEM_UNIT_PATH ?
|
||||
UNIT_FILE_SYSTEM : UNIT_FILE_USER;
|
||||
|
||||
r = lookup_paths_init(&lp, scope, 0, NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
*list = TAKE_PTR(lp.search_path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
case SD_PATH_SYSTEMD_SYSTEM_GENERATOR_PATH:
|
||||
case SD_PATH_SYSTEMD_USER_GENERATOR_PATH: {
|
||||
char **t;
|
||||
const UnitFileScope scope = type == SD_PATH_SYSTEMD_SYSTEM_UNIT_PATH ?
|
||||
UNIT_FILE_SYSTEM : UNIT_FILE_USER;
|
||||
|
||||
t = generator_binary_paths(scope);
|
||||
if (!t)
|
||||
return -ENOMEM;
|
||||
|
||||
*list = t;
|
||||
return 0;
|
||||
}}
|
||||
}
|
||||
|
||||
case SD_PATH_SYSTEMD_NETWORK_PATH:
|
||||
return strv_from_nulstr(list, NETWORK_DIRS_NULSTR);
|
||||
|
||||
}
|
||||
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
||||
_public_ int sd_path_search(uint64_t type, const char *suffix, char ***paths) {
|
||||
char **i, **j;
|
||||
_public_ int sd_path_lookup_strv(uint64_t type, const char *suffix, char ***paths) {
|
||||
_cleanup_strv_free_ char **l = NULL, **n = NULL;
|
||||
int r;
|
||||
|
||||
assert_return(paths, -EINVAL);
|
||||
|
||||
if (!IN_SET(type,
|
||||
SD_PATH_SEARCH_BINARIES,
|
||||
SD_PATH_SEARCH_BINARIES_DEFAULT,
|
||||
SD_PATH_SEARCH_LIBRARY_PRIVATE,
|
||||
SD_PATH_SEARCH_LIBRARY_ARCH,
|
||||
SD_PATH_SEARCH_SHARED,
|
||||
SD_PATH_SEARCH_CONFIGURATION_FACTORY,
|
||||
SD_PATH_SEARCH_STATE_FACTORY,
|
||||
SD_PATH_SEARCH_CONFIGURATION)) {
|
||||
r = get_search(type, &l);
|
||||
if (r == -EOPNOTSUPP) {
|
||||
_cleanup_free_ char *t = NULL;
|
||||
|
||||
char *p;
|
||||
|
||||
r = sd_path_home(type, suffix, &p);
|
||||
r = get_path_alloc(type, suffix, &t);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
l = new(char*, 2);
|
||||
if (!l) {
|
||||
free(p);
|
||||
if (!l)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
l[0] = p;
|
||||
l[0] = TAKE_PTR(t);
|
||||
l[1] = NULL;
|
||||
|
||||
*paths = TAKE_PTR(l);
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = get_search(type, &l);
|
||||
if (r < 0)
|
||||
} else if (r < 0)
|
||||
return r;
|
||||
|
||||
if (!suffix) {
|
||||
@ -599,7 +678,7 @@ _public_ int sd_path_search(uint64_t type, const char *suffix, char ***paths) {
|
||||
if (!n)
|
||||
return -ENOMEM;
|
||||
|
||||
j = n;
|
||||
char **i, **j = n;
|
||||
STRV_FOREACH(i, l) {
|
||||
*j = path_join(*i, suffix);
|
||||
if (!*j)
|
||||
@ -607,8 +686,8 @@ _public_ int sd_path_search(uint64_t type, const char *suffix, char ***paths) {
|
||||
|
||||
j++;
|
||||
}
|
||||
|
||||
*j = NULL;
|
||||
|
||||
*paths = TAKE_PTR(n);
|
||||
return 0;
|
||||
}
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "network-internal.h"
|
||||
#include "networkd-manager.h"
|
||||
#include "nlmon.h"
|
||||
#include "path-lookup.h"
|
||||
#include "siphash24.h"
|
||||
#include "stat-util.h"
|
||||
#include "string-table.h"
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "networkd-network-bus.h"
|
||||
#include "networkd-speed-meter.h"
|
||||
#include "ordered-set.h"
|
||||
#include "path-lookup.h"
|
||||
#include "path-util.h"
|
||||
#include "set.h"
|
||||
#include "signal-util.h"
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "networkd-manager.h"
|
||||
#include "networkd-network.h"
|
||||
#include "parse-util.h"
|
||||
#include "path-lookup.h"
|
||||
#include "set.h"
|
||||
#include "socket-util.h"
|
||||
#include "stat-util.h"
|
||||
|
118
src/path/path.c
118
src/path/path.c
@ -18,46 +18,71 @@
|
||||
static const char *arg_suffix = NULL;
|
||||
|
||||
static const char* const path_table[_SD_PATH_MAX] = {
|
||||
[SD_PATH_TEMPORARY] = "temporary",
|
||||
[SD_PATH_TEMPORARY_LARGE] = "temporary-large",
|
||||
[SD_PATH_SYSTEM_BINARIES] = "system-binaries",
|
||||
[SD_PATH_SYSTEM_INCLUDE] = "system-include",
|
||||
[SD_PATH_SYSTEM_LIBRARY_PRIVATE] = "system-library-private",
|
||||
[SD_PATH_SYSTEM_LIBRARY_ARCH] = "system-library-arch",
|
||||
[SD_PATH_SYSTEM_SHARED] = "system-shared",
|
||||
[SD_PATH_SYSTEM_CONFIGURATION_FACTORY] = "system-configuration-factory",
|
||||
[SD_PATH_SYSTEM_STATE_FACTORY] = "system-state-factory",
|
||||
[SD_PATH_SYSTEM_CONFIGURATION] = "system-configuration",
|
||||
[SD_PATH_SYSTEM_RUNTIME] = "system-runtime",
|
||||
[SD_PATH_SYSTEM_RUNTIME_LOGS] = "system-runtime-logs",
|
||||
[SD_PATH_SYSTEM_STATE_PRIVATE] = "system-state-private",
|
||||
[SD_PATH_SYSTEM_STATE_LOGS] = "system-state-logs",
|
||||
[SD_PATH_SYSTEM_STATE_CACHE] = "system-state-cache",
|
||||
[SD_PATH_SYSTEM_STATE_SPOOL] = "system-state-spool",
|
||||
[SD_PATH_USER_BINARIES] = "user-binaries",
|
||||
[SD_PATH_USER_LIBRARY_PRIVATE] = "user-library-private",
|
||||
[SD_PATH_USER_LIBRARY_ARCH] = "user-library-arch",
|
||||
[SD_PATH_USER_SHARED] = "user-shared",
|
||||
[SD_PATH_USER_CONFIGURATION] = "user-configuration",
|
||||
[SD_PATH_USER_RUNTIME] = "user-runtime",
|
||||
[SD_PATH_USER_STATE_CACHE] = "user-state-cache",
|
||||
[SD_PATH_USER] = "user",
|
||||
[SD_PATH_USER_DOCUMENTS] = "user-documents",
|
||||
[SD_PATH_USER_MUSIC] = "user-music",
|
||||
[SD_PATH_USER_PICTURES] = "user-pictures",
|
||||
[SD_PATH_USER_VIDEOS] = "user-videos",
|
||||
[SD_PATH_USER_DOWNLOAD] = "user-download",
|
||||
[SD_PATH_USER_PUBLIC] = "user-public",
|
||||
[SD_PATH_USER_TEMPLATES] = "user-templates",
|
||||
[SD_PATH_USER_DESKTOP] = "user-desktop",
|
||||
[SD_PATH_SEARCH_BINARIES] = "search-binaries",
|
||||
[SD_PATH_SEARCH_BINARIES_DEFAULT] = "search-binaries-default",
|
||||
[SD_PATH_SEARCH_LIBRARY_PRIVATE] = "search-library-private",
|
||||
[SD_PATH_SEARCH_LIBRARY_ARCH] = "search-library-arch",
|
||||
[SD_PATH_SEARCH_SHARED] = "search-shared",
|
||||
[SD_PATH_SEARCH_CONFIGURATION_FACTORY] = "search-configuration-factory",
|
||||
[SD_PATH_SEARCH_STATE_FACTORY] = "search-state-factory",
|
||||
[SD_PATH_SEARCH_CONFIGURATION] = "search-configuration",
|
||||
[SD_PATH_TEMPORARY] = "temporary",
|
||||
[SD_PATH_TEMPORARY_LARGE] = "temporary-large",
|
||||
[SD_PATH_SYSTEM_BINARIES] = "system-binaries",
|
||||
[SD_PATH_SYSTEM_INCLUDE] = "system-include",
|
||||
[SD_PATH_SYSTEM_LIBRARY_PRIVATE] = "system-library-private",
|
||||
[SD_PATH_SYSTEM_LIBRARY_ARCH] = "system-library-arch",
|
||||
[SD_PATH_SYSTEM_SHARED] = "system-shared",
|
||||
[SD_PATH_SYSTEM_CONFIGURATION_FACTORY] = "system-configuration-factory",
|
||||
[SD_PATH_SYSTEM_STATE_FACTORY] = "system-state-factory",
|
||||
[SD_PATH_SYSTEM_CONFIGURATION] = "system-configuration",
|
||||
[SD_PATH_SYSTEM_RUNTIME] = "system-runtime",
|
||||
[SD_PATH_SYSTEM_RUNTIME_LOGS] = "system-runtime-logs",
|
||||
[SD_PATH_SYSTEM_STATE_PRIVATE] = "system-state-private",
|
||||
[SD_PATH_SYSTEM_STATE_LOGS] = "system-state-logs",
|
||||
[SD_PATH_SYSTEM_STATE_CACHE] = "system-state-cache",
|
||||
[SD_PATH_SYSTEM_STATE_SPOOL] = "system-state-spool",
|
||||
[SD_PATH_USER_BINARIES] = "user-binaries",
|
||||
[SD_PATH_USER_LIBRARY_PRIVATE] = "user-library-private",
|
||||
[SD_PATH_USER_LIBRARY_ARCH] = "user-library-arch",
|
||||
[SD_PATH_USER_SHARED] = "user-shared",
|
||||
[SD_PATH_USER_CONFIGURATION] = "user-configuration",
|
||||
[SD_PATH_USER_RUNTIME] = "user-runtime",
|
||||
[SD_PATH_USER_STATE_CACHE] = "user-state-cache",
|
||||
[SD_PATH_USER] = "user",
|
||||
[SD_PATH_USER_DOCUMENTS] = "user-documents",
|
||||
[SD_PATH_USER_MUSIC] = "user-music",
|
||||
[SD_PATH_USER_PICTURES] = "user-pictures",
|
||||
[SD_PATH_USER_VIDEOS] = "user-videos",
|
||||
[SD_PATH_USER_DOWNLOAD] = "user-download",
|
||||
[SD_PATH_USER_PUBLIC] = "user-public",
|
||||
[SD_PATH_USER_TEMPLATES] = "user-templates",
|
||||
[SD_PATH_USER_DESKTOP] = "user-desktop",
|
||||
[SD_PATH_SEARCH_BINARIES] = "search-binaries",
|
||||
[SD_PATH_SEARCH_BINARIES_DEFAULT] = "search-binaries-default",
|
||||
[SD_PATH_SEARCH_LIBRARY_PRIVATE] = "search-library-private",
|
||||
[SD_PATH_SEARCH_LIBRARY_ARCH] = "search-library-arch",
|
||||
[SD_PATH_SEARCH_SHARED] = "search-shared",
|
||||
[SD_PATH_SEARCH_CONFIGURATION_FACTORY] = "search-configuration-factory",
|
||||
[SD_PATH_SEARCH_STATE_FACTORY] = "search-state-factory",
|
||||
[SD_PATH_SEARCH_CONFIGURATION] = "search-configuration",
|
||||
|
||||
[SD_PATH_SYSTEMD_UTIL_DIR] = "systemd-util-dir",
|
||||
[SD_PATH_SYSTEMD_SYSTEM_UNIT_DIR] = "systemd-system-unit-dir",
|
||||
[SD_PATH_SYSTEMD_SYSTEM_PRESET_DIR] = "systemd-system-preset-dir",
|
||||
[SD_PATH_SYSTEMD_USER_UNIT_DIR] = "systemd-user-unit-dir",
|
||||
[SD_PATH_SYSTEMD_USER_PRESET_DIR] = "systemd-user-preset-dir",
|
||||
[SD_PATH_SYSTEMD_SYSTEM_CONF_DIR] = "systemd-system-conf-dir",
|
||||
[SD_PATH_SYSTEMD_USER_CONF_DIR] = "systemd-user-conf-dir",
|
||||
[SD_PATH_SYSTEMD_SYSTEM_UNIT_PATH] = "systemd-system-unit-path",
|
||||
[SD_PATH_SYSTEMD_USER_UNIT_PATH] = "systemd-user-unit-path",
|
||||
[SD_PATH_SYSTEMD_SYSTEM_GENERATOR_DIR] = "systemd-system-generator-dir",
|
||||
[SD_PATH_SYSTEMD_USER_GENERATOR_DIR] = "systemd-user-generator-dir",
|
||||
[SD_PATH_SYSTEMD_SYSTEM_GENERATOR_PATH] = "systemd-system-generator-path",
|
||||
[SD_PATH_SYSTEMD_USER_GENERATOR_PATH] = "systemd-user-generator-path",
|
||||
[SD_PATH_SYSTEMD_SLEEP_DIR] = "systemd-sleep-dir",
|
||||
[SD_PATH_SYSTEMD_SHUTDOWN_DIR] = "systemd-shutdown-dir",
|
||||
|
||||
[SD_PATH_TMPFILES_DIR] = "tmpfiles-dir",
|
||||
[SD_PATH_SYSUSERS_DIR] = "sysusers-dir",
|
||||
[SD_PATH_SYSCTL_DIR] = "sysctl-dir",
|
||||
[SD_PATH_BINFMT_DIR] = "binfmt-dir",
|
||||
[SD_PATH_MODULES_LOAD_DIR] = "modules-load-dir",
|
||||
[SD_PATH_CATALOG_DIR] = "catalog-dir",
|
||||
|
||||
[SD_PATH_SYSTEMD_NETWORK_PATH] = "systemd-network-path",
|
||||
};
|
||||
|
||||
static int list_homes(void) {
|
||||
@ -68,12 +93,12 @@ static int list_homes(void) {
|
||||
_cleanup_free_ char *p = NULL;
|
||||
int q;
|
||||
|
||||
q = sd_path_home(i, arg_suffix, &p);
|
||||
if (q == -ENXIO)
|
||||
continue;
|
||||
q = sd_path_lookup(i, arg_suffix, &p);
|
||||
if (q < 0) {
|
||||
log_error_errno(r, "Failed to query %s: %m", path_table[i]);
|
||||
r = q;
|
||||
log_full_errno(q == -ENXIO ? LOG_DEBUG : LOG_ERR,
|
||||
q, "Failed to query %s: %m", path_table[i]);
|
||||
if (q != -ENXIO)
|
||||
r = q;
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -91,7 +116,7 @@ static int print_home(const char *n) {
|
||||
if (streq(path_table[i], n)) {
|
||||
_cleanup_free_ char *p = NULL;
|
||||
|
||||
r = sd_path_home(i, arg_suffix, &p);
|
||||
r = sd_path_lookup(i, arg_suffix, &p);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to query %s: %m", n);
|
||||
|
||||
@ -126,7 +151,6 @@ static int help(void) {
|
||||
}
|
||||
|
||||
static int parse_argv(int argc, char *argv[]) {
|
||||
|
||||
enum {
|
||||
ARG_VERSION = 0x100,
|
||||
ARG_SUFFIX,
|
||||
|
@ -160,8 +160,6 @@ shared_sources = files('''
|
||||
output-mode.h
|
||||
pager.c
|
||||
pager.h
|
||||
path-lookup.c
|
||||
path-lookup.h
|
||||
pe-header.h
|
||||
pkcs11-util.c
|
||||
pkcs11-util.h
|
||||
|
@ -12,6 +12,7 @@ _systemd_headers = '''
|
||||
sd-journal.h
|
||||
sd-login.h
|
||||
sd-messages.h
|
||||
sd-path.h
|
||||
'''.split()
|
||||
|
||||
# https://github.com/mesonbuild/meson/issues/1633
|
||||
@ -30,7 +31,6 @@ _not_installed_headers = '''
|
||||
sd-ndisc.h
|
||||
sd-netlink.h
|
||||
sd-network.h
|
||||
sd-path.h
|
||||
sd-radv.h
|
||||
sd-resolve.h
|
||||
sd-utf8.h
|
||||
|
@ -78,11 +78,38 @@ enum {
|
||||
SD_PATH_SEARCH_STATE_FACTORY,
|
||||
SD_PATH_SEARCH_CONFIGURATION,
|
||||
|
||||
/* Various systemd paths, generally mirroring systemd.pc */
|
||||
SD_PATH_SYSTEMD_UTIL_DIR,
|
||||
SD_PATH_SYSTEMD_SYSTEM_UNIT_DIR,
|
||||
SD_PATH_SYSTEMD_SYSTEM_PRESET_DIR,
|
||||
SD_PATH_SYSTEMD_USER_UNIT_DIR,
|
||||
SD_PATH_SYSTEMD_USER_PRESET_DIR,
|
||||
SD_PATH_SYSTEMD_SYSTEM_CONF_DIR,
|
||||
SD_PATH_SYSTEMD_USER_CONF_DIR,
|
||||
SD_PATH_SYSTEMD_SYSTEM_UNIT_PATH,
|
||||
SD_PATH_SYSTEMD_USER_UNIT_PATH,
|
||||
SD_PATH_SYSTEMD_SYSTEM_GENERATOR_DIR,
|
||||
SD_PATH_SYSTEMD_USER_GENERATOR_DIR,
|
||||
SD_PATH_SYSTEMD_SYSTEM_GENERATOR_PATH,
|
||||
SD_PATH_SYSTEMD_USER_GENERATOR_PATH,
|
||||
SD_PATH_SYSTEMD_SLEEP_DIR,
|
||||
SD_PATH_SYSTEMD_SHUTDOWN_DIR,
|
||||
|
||||
SD_PATH_TMPFILES_DIR,
|
||||
SD_PATH_SYSUSERS_DIR,
|
||||
SD_PATH_SYSCTL_DIR,
|
||||
SD_PATH_BINFMT_DIR,
|
||||
SD_PATH_MODULES_LOAD_DIR,
|
||||
SD_PATH_CATALOG_DIR,
|
||||
|
||||
/* systemd-networkd search paths */
|
||||
SD_PATH_SYSTEMD_NETWORK_PATH,
|
||||
|
||||
_SD_PATH_MAX,
|
||||
};
|
||||
|
||||
int sd_path_home(uint64_t type, const char *suffix, char **path);
|
||||
int sd_path_search(uint64_t type, const char *suffix, char ***paths);
|
||||
int sd_path_lookup(uint64_t type, const char *suffix, char **path);
|
||||
int sd_path_lookup_strv(uint64_t type, const char *suffix, char ***paths);
|
||||
|
||||
_SD_END_DECLARATIONS;
|
||||
|
||||
|
@ -778,6 +778,10 @@ tests += [
|
||||
[],
|
||||
[]],
|
||||
|
||||
[['src/test/test-sd-path.c'],
|
||||
[],
|
||||
[]],
|
||||
|
||||
[['src/test/test-local-addresses.c'],
|
||||
[],
|
||||
[]],
|
||||
|
@ -55,7 +55,7 @@ static void test_basic_mask_and_enable(const char *root) {
|
||||
assert_se(n_changes == 1);
|
||||
assert_se(changes[0].type == UNIT_FILE_SYMLINK);
|
||||
assert_se(streq(changes[0].source, "/dev/null"));
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/a.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/a.service");
|
||||
assert_se(streq(changes[0].path, p));
|
||||
|
||||
unit_file_changes_free(changes, n_changes);
|
||||
@ -74,7 +74,7 @@ static void test_basic_mask_and_enable(const char *root) {
|
||||
assert_se(unit_file_unmask(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("a.service"), &changes, &n_changes) >= 0);
|
||||
assert_se(n_changes == 1);
|
||||
assert_se(changes[0].type == UNIT_FILE_UNLINK);
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/a.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/a.service");
|
||||
assert_se(streq(changes[0].path, p));
|
||||
unit_file_changes_free(changes, n_changes);
|
||||
changes = NULL; n_changes = 0;
|
||||
@ -83,7 +83,7 @@ static void test_basic_mask_and_enable(const char *root) {
|
||||
assert_se(n_changes == 1);
|
||||
assert_se(changes[0].type == UNIT_FILE_SYMLINK);
|
||||
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/a.service"));
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/a.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/a.service");
|
||||
assert_se(streq(changes[0].path, p));
|
||||
unit_file_changes_free(changes, n_changes);
|
||||
changes = NULL; n_changes = 0;
|
||||
@ -102,7 +102,7 @@ static void test_basic_mask_and_enable(const char *root) {
|
||||
assert_se(unit_file_disable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("a.service"), &changes, &n_changes) >= 0);
|
||||
assert_se(n_changes == 1);
|
||||
assert_se(changes[0].type == UNIT_FILE_UNLINK);
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/a.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/a.service");
|
||||
assert_se(streq(changes[0].path, p));
|
||||
unit_file_changes_free(changes, n_changes);
|
||||
changes = NULL; n_changes = 0;
|
||||
@ -123,7 +123,7 @@ static void test_basic_mask_and_enable(const char *root) {
|
||||
assert_se(n_changes == 1);
|
||||
assert_se(changes[0].type == UNIT_FILE_SYMLINK);
|
||||
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/a.service"));
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/a.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/a.service");
|
||||
assert_se(streq(changes[0].path, p));
|
||||
unit_file_changes_free(changes, n_changes);
|
||||
changes = NULL; n_changes = 0;
|
||||
@ -138,7 +138,7 @@ static void test_basic_mask_and_enable(const char *root) {
|
||||
assert_se(unit_file_reenable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("b.service"), &changes, &n_changes) >= 0);
|
||||
assert_se(n_changes == 2);
|
||||
assert_se(changes[0].type == UNIT_FILE_UNLINK);
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/a.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/a.service");
|
||||
assert_se(streq(changes[0].path, p));
|
||||
assert_se(changes[1].type == UNIT_FILE_SYMLINK);
|
||||
assert_se(streq(changes[1].source, "/usr/lib/systemd/system/a.service"));
|
||||
@ -196,7 +196,7 @@ static void test_linked_units(const char *root) {
|
||||
p = strjoina(root, "/usr/lib/systemd/system/linked2.service");
|
||||
assert_se(symlink("/opt/linked2.service", p) >= 0);
|
||||
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/linked3.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/linked3.service");
|
||||
assert_se(symlink("/opt/linked3.service", p) >= 0);
|
||||
|
||||
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "linked.service", &state) == -ENOENT);
|
||||
@ -208,7 +208,7 @@ static void test_linked_units(const char *root) {
|
||||
assert_se(n_changes == 1);
|
||||
assert_se(changes[0].type == UNIT_FILE_SYMLINK);
|
||||
assert_se(streq(changes[0].source, "/opt/linked.service"));
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/linked.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/linked.service");
|
||||
assert_se(streq(changes[0].path, p));
|
||||
unit_file_changes_free(changes, n_changes);
|
||||
changes = NULL; n_changes = 0;
|
||||
@ -219,7 +219,7 @@ static void test_linked_units(const char *root) {
|
||||
assert_se(unit_file_disable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("linked.service"), &changes, &n_changes) >= 0);
|
||||
assert_se(n_changes == 1);
|
||||
assert_se(changes[0].type == UNIT_FILE_UNLINK);
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/linked.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/linked.service");
|
||||
assert_se(streq(changes[0].path, p));
|
||||
unit_file_changes_free(changes, n_changes);
|
||||
changes = NULL; n_changes = 0;
|
||||
@ -229,8 +229,8 @@ static void test_linked_units(const char *root) {
|
||||
/* Now, let's not just link it, but also enable it */
|
||||
assert_se(unit_file_enable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("/opt/linked.service"), &changes, &n_changes) >= 0);
|
||||
assert_se(n_changes == 2);
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/linked.service");
|
||||
q = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/linked.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/linked.service");
|
||||
q = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/linked.service");
|
||||
for (i = 0 ; i < n_changes; i++) {
|
||||
assert_se(changes[i].type == UNIT_FILE_SYMLINK);
|
||||
assert_se(streq(changes[i].source, "/opt/linked.service"));
|
||||
@ -251,8 +251,8 @@ static void test_linked_units(const char *root) {
|
||||
/* And let's unlink it again */
|
||||
assert_se(unit_file_disable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("linked.service"), &changes, &n_changes) >= 0);
|
||||
assert_se(n_changes == 2);
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/linked.service");
|
||||
q = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/linked.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/linked.service");
|
||||
q = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/linked.service");
|
||||
for (i = 0; i < n_changes; i++) {
|
||||
assert_se(changes[i].type == UNIT_FILE_UNLINK);
|
||||
|
||||
@ -271,8 +271,8 @@ static void test_linked_units(const char *root) {
|
||||
|
||||
assert_se(unit_file_enable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("linked2.service"), &changes, &n_changes) >= 0);
|
||||
assert_se(n_changes == 2);
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/linked2.service");
|
||||
q = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/linked2.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/linked2.service");
|
||||
q = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/linked2.service");
|
||||
for (i = 0 ; i < n_changes; i++) {
|
||||
assert_se(changes[i].type == UNIT_FILE_SYMLINK);
|
||||
assert_se(streq(changes[i].source, "/opt/linked2.service"));
|
||||
@ -325,7 +325,7 @@ static void test_default(const char *root) {
|
||||
assert_se(n_changes == 1);
|
||||
assert_se(changes[0].type == UNIT_FILE_SYMLINK);
|
||||
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/test-default-real.target"));
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH "/" SPECIAL_DEFAULT_TARGET);
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR "/" SPECIAL_DEFAULT_TARGET);
|
||||
assert_se(streq(changes[0].path, p));
|
||||
unit_file_changes_free(changes, n_changes);
|
||||
changes = NULL; n_changes = 0;
|
||||
@ -355,7 +355,7 @@ static void test_add_dependency(const char *root) {
|
||||
assert_se(n_changes == 1);
|
||||
assert_se(changes[0].type == UNIT_FILE_SYMLINK);
|
||||
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/real-add-dependency-test-service.service"));
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/real-add-dependency-test-target.target.wants/real-add-dependency-test-service.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/real-add-dependency-test-target.target.wants/real-add-dependency-test-service.service");
|
||||
assert_se(streq(changes[0].path, p));
|
||||
unit_file_changes_free(changes, n_changes);
|
||||
changes = NULL; n_changes = 0;
|
||||
@ -396,7 +396,7 @@ static void test_template_enable(const char *root) {
|
||||
assert_se(n_changes == 1);
|
||||
assert_se(changes[0].type == UNIT_FILE_SYMLINK);
|
||||
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/template@.service"));
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/template@def.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/template@def.service");
|
||||
assert_se(streq(changes[0].path, p));
|
||||
unit_file_changes_free(changes, n_changes);
|
||||
changes = NULL; n_changes = 0;
|
||||
@ -427,7 +427,7 @@ static void test_template_enable(const char *root) {
|
||||
assert_se(unit_file_enable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("template@foo.service"), &changes, &n_changes) >= 0);
|
||||
assert_se(changes[0].type == UNIT_FILE_SYMLINK);
|
||||
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/template@.service"));
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/template@foo.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/template@foo.service");
|
||||
assert_se(streq(changes[0].path, p));
|
||||
unit_file_changes_free(changes, n_changes);
|
||||
changes = NULL; n_changes = 0;
|
||||
@ -460,7 +460,7 @@ static void test_template_enable(const char *root) {
|
||||
assert_se(unit_file_enable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("template-symlink@quux.service"), &changes, &n_changes) >= 0);
|
||||
assert_se(changes[0].type == UNIT_FILE_SYMLINK);
|
||||
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/template@.service"));
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/template@quux.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/template@quux.service");
|
||||
assert_se(streq(changes[0].path, p));
|
||||
unit_file_changes_free(changes, n_changes);
|
||||
changes = NULL; n_changes = 0;
|
||||
@ -506,7 +506,7 @@ static void test_indirect(const char *root) {
|
||||
assert_se(n_changes == 1);
|
||||
assert_se(changes[0].type == UNIT_FILE_SYMLINK);
|
||||
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/indirectb.service"));
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/indirectb.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/indirectb.service");
|
||||
assert_se(streq(changes[0].path, p));
|
||||
unit_file_changes_free(changes, n_changes);
|
||||
changes = NULL; n_changes = 0;
|
||||
@ -518,7 +518,7 @@ static void test_indirect(const char *root) {
|
||||
assert_se(unit_file_disable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("indirectc.service"), &changes, &n_changes) >= 0);
|
||||
assert_se(n_changes == 1);
|
||||
assert_se(changes[0].type == UNIT_FILE_UNLINK);
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/indirectb.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/indirectb.service");
|
||||
assert_se(streq(changes[0].path, p));
|
||||
unit_file_changes_free(changes, n_changes);
|
||||
changes = NULL; n_changes = 0;
|
||||
@ -559,7 +559,7 @@ static void test_preset_and_list(const char *root) {
|
||||
assert_se(n_changes == 1);
|
||||
assert_se(changes[0].type == UNIT_FILE_SYMLINK);
|
||||
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/preset-yes.service"));
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/preset-yes.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/preset-yes.service");
|
||||
assert_se(streq(changes[0].path, p));
|
||||
unit_file_changes_free(changes, n_changes);
|
||||
changes = NULL; n_changes = 0;
|
||||
@ -570,7 +570,7 @@ static void test_preset_and_list(const char *root) {
|
||||
assert_se(unit_file_disable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("preset-yes.service"), &changes, &n_changes) >= 0);
|
||||
assert_se(n_changes == 1);
|
||||
assert_se(changes[0].type == UNIT_FILE_UNLINK);
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/preset-yes.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/preset-yes.service");
|
||||
assert_se(streq(changes[0].path, p));
|
||||
unit_file_changes_free(changes, n_changes);
|
||||
changes = NULL; n_changes = 0;
|
||||
@ -590,7 +590,7 @@ static void test_preset_and_list(const char *root) {
|
||||
|
||||
assert_se(n_changes > 0);
|
||||
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/preset-yes.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/preset-yes.service");
|
||||
|
||||
for (i = 0; i < n_changes; i++) {
|
||||
|
||||
@ -655,7 +655,7 @@ static void test_revert(const char *root) {
|
||||
unit_file_changes_free(changes, n_changes);
|
||||
changes = NULL; n_changes = 0;
|
||||
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/xx.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/xx.service");
|
||||
assert_se(write_string_file(p, "# Empty override\n", WRITE_STRING_FILE_CREATE) >= 0);
|
||||
|
||||
/* Revert the override file */
|
||||
@ -666,7 +666,7 @@ static void test_revert(const char *root) {
|
||||
unit_file_changes_free(changes, n_changes);
|
||||
changes = NULL; n_changes = 0;
|
||||
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/xx.service.d/dropin.conf");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/xx.service.d/dropin.conf");
|
||||
assert_se(mkdir_parents(p, 0755) >= 0);
|
||||
assert_se(write_string_file(p, "# Empty dropin\n", WRITE_STRING_FILE_CREATE) >= 0);
|
||||
|
||||
@ -676,7 +676,7 @@ static void test_revert(const char *root) {
|
||||
assert_se(changes[0].type == UNIT_FILE_UNLINK);
|
||||
assert_se(streq(changes[0].path, p));
|
||||
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/xx.service.d");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/xx.service.d");
|
||||
assert_se(changes[1].type == UNIT_FILE_UNLINK);
|
||||
assert_se(streq(changes[1].path, p));
|
||||
unit_file_changes_free(changes, n_changes);
|
||||
@ -715,7 +715,7 @@ static void test_preset_order(const char *root) {
|
||||
assert_se(n_changes == 1);
|
||||
assert_se(changes[0].type == UNIT_FILE_SYMLINK);
|
||||
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/prefix-1.service"));
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/prefix-1.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/prefix-1.service");
|
||||
assert_se(streq(changes[0].path, p));
|
||||
unit_file_changes_free(changes, n_changes);
|
||||
changes = NULL; n_changes = 0;
|
||||
@ -777,7 +777,7 @@ static void test_with_dropin(const char *root) {
|
||||
|
||||
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "with-dropin-1.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
|
||||
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/with-dropin-2.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/with-dropin-2.service");
|
||||
assert_se(write_string_file(p,
|
||||
"[Install]\n"
|
||||
"WantedBy=multi-user.target\n", WRITE_STRING_FILE_CREATE) >= 0);
|
||||
@ -795,7 +795,7 @@ static void test_with_dropin(const char *root) {
|
||||
"[Install]\n"
|
||||
"WantedBy=multi-user.target\n", WRITE_STRING_FILE_CREATE) >= 0);
|
||||
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/with-dropin-3.service.d/dropin.conf");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/with-dropin-3.service.d/dropin.conf");
|
||||
assert_se(mkdir_parents(p, 0755) >= 0);
|
||||
assert_se(write_string_file(p,
|
||||
"[Install]\n"
|
||||
@ -808,7 +808,7 @@ static void test_with_dropin(const char *root) {
|
||||
"[Install]\n"
|
||||
"WantedBy=multi-user.target\n", WRITE_STRING_FILE_CREATE) >= 0);
|
||||
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/with-dropin-4a.service.d/dropin.conf");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/with-dropin-4a.service.d/dropin.conf");
|
||||
assert_se(mkdir_parents(p, 0755) >= 0);
|
||||
assert_se(write_string_file(p,
|
||||
"[Install]\n"
|
||||
@ -829,9 +829,9 @@ static void test_with_dropin(const char *root) {
|
||||
assert_se(changes[1].type == UNIT_FILE_SYMLINK);
|
||||
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/with-dropin-1.service"));
|
||||
assert_se(streq(changes[1].source, "/usr/lib/systemd/system/with-dropin-1.service"));
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/with-dropin-1.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/with-dropin-1.service");
|
||||
assert_se(streq(changes[0].path, p));
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/graphical.target.wants/with-dropin-1.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/graphical.target.wants/with-dropin-1.service");
|
||||
assert_se(streq(changes[1].path, p));
|
||||
unit_file_changes_free(changes, n_changes);
|
||||
changes = NULL; n_changes = 0;
|
||||
@ -841,11 +841,11 @@ static void test_with_dropin(const char *root) {
|
||||
assert_se(n_changes == 2);
|
||||
assert_se(changes[0].type == UNIT_FILE_SYMLINK);
|
||||
assert_se(changes[1].type == UNIT_FILE_SYMLINK);
|
||||
assert_se(streq(changes[0].source, SYSTEM_CONFIG_UNIT_PATH"/with-dropin-2.service"));
|
||||
assert_se(streq(changes[1].source, SYSTEM_CONFIG_UNIT_PATH"/with-dropin-2.service"));
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/with-dropin-2.service");
|
||||
assert_se(streq(changes[0].source, SYSTEM_CONFIG_UNIT_DIR"/with-dropin-2.service"));
|
||||
assert_se(streq(changes[1].source, SYSTEM_CONFIG_UNIT_DIR"/with-dropin-2.service"));
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/with-dropin-2.service");
|
||||
assert_se(streq(changes[0].path, p));
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/graphical.target.wants/with-dropin-2.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/graphical.target.wants/with-dropin-2.service");
|
||||
assert_se(streq(changes[1].path, p));
|
||||
unit_file_changes_free(changes, n_changes);
|
||||
changes = NULL; n_changes = 0;
|
||||
@ -857,9 +857,9 @@ static void test_with_dropin(const char *root) {
|
||||
assert_se(changes[1].type == UNIT_FILE_SYMLINK);
|
||||
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/with-dropin-3.service"));
|
||||
assert_se(streq(changes[1].source, "/usr/lib/systemd/system/with-dropin-3.service"));
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/with-dropin-3.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/with-dropin-3.service");
|
||||
assert_se(streq(changes[0].path, p));
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/graphical.target.wants/with-dropin-3.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/graphical.target.wants/with-dropin-3.service");
|
||||
assert_se(streq(changes[1].path, p));
|
||||
unit_file_changes_free(changes, n_changes);
|
||||
changes = NULL; n_changes = 0;
|
||||
@ -871,9 +871,9 @@ static void test_with_dropin(const char *root) {
|
||||
assert_se(changes[1].type == UNIT_FILE_SYMLINK);
|
||||
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/with-dropin-4a.service"));
|
||||
assert_se(streq(changes[1].source, "/usr/lib/systemd/system/with-dropin-4b.service"));
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/with-dropin-4a.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/with-dropin-4a.service");
|
||||
assert_se(streq(changes[0].path, p));
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/with-dropin-4b.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/with-dropin-4b.service");
|
||||
assert_se(streq(changes[1].path, p));
|
||||
unit_file_changes_free(changes, n_changes);
|
||||
changes = NULL; n_changes = 0;
|
||||
@ -941,9 +941,9 @@ static void test_with_dropin_template(const char *root) {
|
||||
assert_se(changes[1].type == UNIT_FILE_SYMLINK);
|
||||
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/with-dropin-1@.service"));
|
||||
assert_se(streq(changes[1].source, "/usr/lib/systemd/system/with-dropin-1@.service"));
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/with-dropin-1@instance-1.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/with-dropin-1@instance-1.service");
|
||||
assert_se(streq(changes[0].path, p));
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/graphical.target.wants/with-dropin-1@instance-1.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/graphical.target.wants/with-dropin-1@instance-1.service");
|
||||
assert_se(streq(changes[1].path, p));
|
||||
unit_file_changes_free(changes, n_changes);
|
||||
changes = NULL; n_changes = 0;
|
||||
@ -954,9 +954,9 @@ static void test_with_dropin_template(const char *root) {
|
||||
assert_se(changes[1].type == UNIT_FILE_SYMLINK);
|
||||
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/with-dropin-2@.service"));
|
||||
assert_se(streq(changes[1].source, "/usr/lib/systemd/system/with-dropin-2@.service"));
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/with-dropin-2@instance-1.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/with-dropin-2@instance-1.service");
|
||||
assert_se(streq(changes[0].path, p));
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/graphical.target.wants/with-dropin-2@instance-1.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/graphical.target.wants/with-dropin-2@instance-1.service");
|
||||
assert_se(streq(changes[1].path, p));
|
||||
unit_file_changes_free(changes, n_changes);
|
||||
changes = NULL; n_changes = 0;
|
||||
@ -965,7 +965,7 @@ static void test_with_dropin_template(const char *root) {
|
||||
assert_se(n_changes == 1);
|
||||
assert_se(changes[0].type == UNIT_FILE_SYMLINK);
|
||||
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/with-dropin-2@.service"));
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/with-dropin-2@instance-2.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/with-dropin-2@instance-2.service");
|
||||
assert_se(streq(changes[0].path, p));
|
||||
unit_file_changes_free(changes, n_changes);
|
||||
changes = NULL; n_changes = 0;
|
||||
@ -974,7 +974,7 @@ static void test_with_dropin_template(const char *root) {
|
||||
assert_se(n_changes == 1);
|
||||
assert_se(changes[0].type == UNIT_FILE_SYMLINK);
|
||||
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/with-dropin-3@.service"));
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/with-dropin-3@instance-2.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/with-dropin-3@instance-2.service");
|
||||
assert_se(streq(changes[0].path, p));
|
||||
unit_file_changes_free(changes, n_changes);
|
||||
changes = NULL; n_changes = 0;
|
||||
@ -1014,7 +1014,7 @@ static void test_preset_multiple_instances(const char *root) {
|
||||
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "foo@bar0.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
|
||||
assert_se(n_changes == 1);
|
||||
assert_se(changes[0].type == UNIT_FILE_SYMLINK);
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/foo@bar0.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/foo@bar0.service");
|
||||
assert_se(streq(changes[0].path, p));
|
||||
unit_file_changes_free(changes, n_changes);
|
||||
changes = NULL; n_changes = 0;
|
||||
@ -1022,7 +1022,7 @@ static void test_preset_multiple_instances(const char *root) {
|
||||
assert_se(unit_file_disable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("foo@bar0.service"), &changes, &n_changes) >= 0);
|
||||
assert_se(n_changes == 1);
|
||||
assert_se(changes[0].type == UNIT_FILE_UNLINK);
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/foo@bar0.service");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/foo@bar0.service");
|
||||
assert_se(streq(changes[0].path, p));
|
||||
unit_file_changes_free(changes, n_changes);
|
||||
changes = NULL; n_changes = 0;
|
||||
@ -1214,7 +1214,7 @@ int main(int argc, char *argv[]) {
|
||||
p = strjoina(root, "/usr/lib/systemd/system/");
|
||||
assert_se(mkdir_p(p, 0755) >= 0);
|
||||
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/");
|
||||
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/");
|
||||
assert_se(mkdir_p(p, 0755) >= 0);
|
||||
|
||||
p = strjoina(root, "/run/systemd/system/");
|
||||
|
69
src/test/test-sd-path.c
Normal file
69
src/test/test-sd-path.c
Normal file
@ -0,0 +1,69 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#include "sd-path.h"
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "tests.h"
|
||||
|
||||
static void test_sd_path_lookup(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
for (uint64_t i = 0; i < _SD_PATH_MAX; i++) {
|
||||
_cleanup_free_ char *t = NULL, *s = NULL;
|
||||
int r;
|
||||
|
||||
r = sd_path_lookup(i, NULL, &t);
|
||||
if (i == SD_PATH_USER_RUNTIME && r == -ENXIO)
|
||||
continue;
|
||||
assert_se(r == 0);
|
||||
assert_se(t);
|
||||
log_info("%02"PRIu64": \"%s\"", i, t);
|
||||
|
||||
assert_se(sd_path_lookup(i, "suffix", &s) == 0);
|
||||
assert_se(s);
|
||||
log_info("%02"PRIu64": \"%s\"", i, s);
|
||||
assert_se(endswith(s, "/suffix"));
|
||||
}
|
||||
|
||||
char *tt;
|
||||
assert_se(sd_path_lookup(_SD_PATH_MAX, NULL, &tt) == -EOPNOTSUPP);
|
||||
}
|
||||
|
||||
static void test_sd_path_lookup_strv(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
for (uint64_t i = 0; i < _SD_PATH_MAX; i++) {
|
||||
_cleanup_strv_free_ char **t = NULL, **s = NULL;
|
||||
char **item;
|
||||
int r;
|
||||
|
||||
r = sd_path_lookup_strv(i, NULL, &t);
|
||||
if (i == SD_PATH_USER_RUNTIME && r == -ENXIO)
|
||||
continue;
|
||||
assert_se(r == 0);
|
||||
assert_se(t);
|
||||
log_info("%02"PRIu64":", i);
|
||||
STRV_FOREACH(item, t)
|
||||
log_debug(" %s", *item);
|
||||
|
||||
assert_se(sd_path_lookup_strv(i, "suffix", &s) == 0);
|
||||
assert_se(s);
|
||||
log_info("%02"PRIu64":", i);
|
||||
STRV_FOREACH(item, s) {
|
||||
assert_se(endswith(*item, "/suffix"));
|
||||
log_debug(" %s", *item);
|
||||
}
|
||||
}
|
||||
|
||||
char *tt;
|
||||
assert_se(sd_path_lookup(_SD_PATH_MAX, NULL, &tt) == -EOPNOTSUPP);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
test_sd_path_lookup();
|
||||
test_sd_path_lookup_strv();
|
||||
}
|
@ -244,7 +244,7 @@ static int specifier_directory(char specifier, const void *data, const void *use
|
||||
i = PTR_TO_UINT(data);
|
||||
assert(i < ELEMENTSOF(paths_system));
|
||||
|
||||
return sd_path_home(paths[i].type, paths[i].suffix, ret);
|
||||
return sd_path_lookup(paths[i].type, paths[i].suffix, ret);
|
||||
}
|
||||
|
||||
static int log_unresolvable_specifier(const char *filename, unsigned line) {
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "netlink-util.h"
|
||||
#include "network-internal.h"
|
||||
#include "parse-util.h"
|
||||
#include "path-lookup.h"
|
||||
#include "path-util.h"
|
||||
#include "proc-cmdline.h"
|
||||
#include "random-util.h"
|
||||
|
@ -2,4 +2,5 @@ Name: udev
|
||||
Description: udev
|
||||
Version: @PROJECT_VERSION@
|
||||
|
||||
udevdir=@udevlibexecdir@
|
||||
udev_dir=@udevlibexecdir@
|
||||
udevdir=${udev_dir}
|
||||
|
Loading…
Reference in New Issue
Block a user