Compare commits

..

27 Commits

Author SHA1 Message Date
Evgeny Vereshchagin c4ae2704b7 travis: install ninja with pip
https://mesonbuild.com/Release-notes-for-0-54-0.html#ninja-version-requirement-bumped-to-17
https://github.com/mesonbuild/meson/issues/6867
2020-03-30 02:57:56 +03:00
Zbigniew Jędrzejewski-Szmek 4a874560c5
Merge pull request #15217 from keszybz/beef-up-sd-path
Export sd-path functions and beef up systemd-path to show more items
2020-03-29 22:57:53 +02:00
Daan De Meyer 35bae98dce sd-bus: Fix pointer alignment 2020-03-29 21:48:21 +02:00
Daan De Meyer 45069c67ce sd-bus: Add sd_bus_slot_get_current_* docs 2020-03-29 21:36:55 +02:00
Topi Miettinen a6c9f8fa6d README.md: add repology badge
Show downstream usage for various versions of systemd.
2020-03-29 21:26:28 +02:00
Kevin Kuehler 7ea4392f1e basic: Fix capability_ambient_set_apply for kernels < 4.3
https://github.com/systemd/systemd/pull/14133 made
capability_ambient_set_apply() acquire capabilities that were explicitly
asked for and drop all others. This change means the function is called
even with an empty capability set, opening up a code path for users
without ambient capabilities to call this function. This function will
error with EINVAL out on kernels < 4.3 because PR_CAP_AMBIENT is not
understood. This turns capability_ambient_set_apply() into a noop for
kernels < 4.3

Fixes https://github.com/systemd/systemd/issues/15225
2020-03-29 21:11:25 +02:00
Zbigniew Jędrzejewski-Szmek 3e118d135b
Merge pull request #15233 from msekletar/device-dbus
device: make sure we don't generate bogus PropertiesChanged signals
2020-03-29 20:52:31 +02:00
Michal Sekletár 2e129d5d6b device: don't emit PropetiesChanged needlessly
Functions called from device_setup_unit() already make sure that unit is
enqueued in case it is a new unit or properties exported on the bus have
changed.

This should prevent unnecessary DBus wakeups and associated DBus traffic
when device_setup_unit() was called while reparsing /proc/self/mountinfo
due to the mountinfo notifications. Note that we parse
/proc/self/mountinfo quite often on the busy systems (e.g. k8s container
hosts) but majority of the time mounts didn't change, only some mount
got added. Thus we don't need to generate PropertiesChanged for devices
associated with the mounts that didn't change.

Thanks to Renaud Métrich <rmetrich@redhat.com> for debugging the
problem and providing draft version of the patch.
2020-03-28 21:26:40 +01:00
Michal Sekletár 7c4d139485 device: make sure we emit PropertiesChanged signal once we set sysfs 2020-03-28 21:26:40 +01:00
Zbigniew Jędrzejewski-Szmek 2e09fa8906 sd-path: handle case of missing runtime dir in test
Also document it in the man page.
2020-03-27 20:12:45 +01:00
Zbigniew Jędrzejewski-Szmek e342055851 path: log at debug level when we can't query a variable 2020-03-27 20:12:45 +01:00
Zbigniew Jędrzejewski-Szmek f52b9131e5 man: fix typo 2020-03-27 20:12:45 +01:00
Zbigniew Jędrzejewski-Szmek f1bb691a5a sd-path: export "systemd-network-path"
Inspired by https://lists.freedesktop.org/archives/systemd-devel/2020-March/044169.html.
2020-03-27 20:12:45 +01:00
Zbigniew Jędrzejewski-Szmek b0c8219260 network: move NETWORK_DIRS to path-lookup.h
In preparation for future changes...
2020-03-27 20:12:45 +01:00
Zbigniew Jędrzejewski-Szmek 96d33e4ac0 Rename _PATH variables to _DIR when they refer to a directory
We were very inconsistent in this, but in general _PATH signifies
a search path (separated with :), and _DIR signifies a single directory.
2020-03-27 20:12:45 +01:00
Zbigniew Jędrzejewski-Szmek 9c5bb2033d path: show various systemd directories and search paths too
So far we had various ad hoc APIs to query search paths:
systemd-analyze unit-paths, lookup_paths_log(), the pkgconfig file,
debug logs emitted by systemd-analyze cat-config.
But answering a simple question "what is the search path for tmpfiles,
sysusers, .network files, ..." is surprisingly hard.

I think we should have an api that makes it easy to query this. Pkgconfig is
not bad, but it is primarily a development tool, so it's not available in many
context. Also it can't provide support for paths which are influenced by
environment variables, and I'd like to be able to answer the question "what is
the search path for ..., assuming that VAR_FOO=... is set?".

Extending sd-path to support more of our internal paths seems to be most
flexible solution. We already have systemd-path which provides a nice
way to query, and we can add stuff like optional descriptions later on.
We we essentially get a nice programmatic and commmandline apis for the price
of one.
2020-03-27 20:12:45 +01:00
Zbigniew Jędrzejewski-Szmek ce7eb6aa84 sd-path: simplify implementation of sd_path_lookup*()
The two functions were duplicating a lot of functionality and more
importantly, they both had explicit lists of types which are search
paths. I want to add more types, and I don't want to have to remember
to add them to both lists.
2020-03-27 20:12:44 +01:00
Zbigniew Jędrzejewski-Szmek 09e6443ef4 Move path-lookup.c to src/basic
I want to use it from sd-path later on so it needs to be moved out of
src/shared (libsystemd is not allowed to use code from src/shared).
2020-03-27 20:12:44 +01:00
Zbigniew Jędrzejewski-Szmek 385093b702 Split out generator directory setup to a src/core/generator-setup.c
Those functions have only one non-test user, so we can move them to src/core/.
2020-03-27 20:12:44 +01:00
Zbigniew Jędrzejewski-Szmek a7addf32a5 sd-path,strv: add simple helper to wrap oom handling around strv_split_nulstr() 2020-03-27 20:12:44 +01:00
Zbigniew Jędrzejewski-Szmek b35ed5530b man: add sd_path_lookup(3) 2020-03-27 20:12:44 +01:00
Zbigniew Jędrzejewski-Szmek 557afad2b7 libsystemd: install sd-path.h and export sd_path_lookup{,_strv}
Those are not terribly imporant functions, but we have them, and there's
no reason not to export them.
2020-03-27 20:12:44 +01:00
Zbigniew Jędrzejewski-Szmek 3919ecc553 meson: run a no-op build to generate man rules
When a new page is added using man/update-man-rules, ninja doesn't know
about the new target until a build is initiated, so build/man/man and
build/man/html would fail. Force a trivial build to regenerate the rules
before calling 'ninja -t'.
2020-03-27 20:12:44 +01:00
Zbigniew Jędrzejewski-Szmek 51327bcc74 sd-path: rename the two functions
I think the two names were both pretty bad. They did not give a proper hint
what the difference between the two functions is, and sd_path_home sounds like
it is somehow related to /home or home directories or whatever, when in fact
both functions return the same set of paths as either a colon-delimited string
or a strv. "_strv" suffix is used by various functions in sd-bus, so let's
reuse that.

Those functions are not public yet, so let's rename.
2020-03-27 20:12:44 +01:00
Zbigniew Jędrzejewski-Szmek d32014a5bb test-sd-path: basic test for the sd-path API 2020-03-27 20:12:44 +01:00
Zbigniew Jędrzejewski-Szmek 4908de44b0 {systemd,udev}.pc: add names with underscores, deprecate the old ones
The names with multiple lowercase words run together are hard to read.  We
started that way with very short names like rootprefix, but then same pattern
was applied to longer and longer names. Looking at the body of .pc files
available on my machine, many packages use underscores; let's do the same. Old
names are kept for compatiblity, so this is backwards compatible.
2020-03-27 20:12:44 +01:00
Zbigniew Jędrzejewski-Szmek 009b80a48d path: align columns
Without that it's really hard to see what items are in the table...
2020-03-27 20:12:44 +01:00
42 changed files with 942 additions and 333 deletions

View File

@ -12,7 +12,8 @@ System and Service Manager
[![Travis CI Build Status](https://travis-ci.org/systemd/systemd.svg?branch=master)](https://travis-ci.org/systemd/systemd)<br/> [![Travis CI Build Status](https://travis-ci.org/systemd/systemd.svg?branch=master)](https://travis-ci.org/systemd/systemd)<br/>
[![Language Grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/systemd/systemd.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/systemd/systemd/context:cpp)<br/> [![Language Grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/systemd/systemd.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/systemd/systemd/context:cpp)<br/>
[![CentOS CI Build Status](https://ci.centos.org/buildStatus/icon?job=systemd-pr-build)](https://ci.centos.org/job/systemd-pr-build/)<br/> [![CentOS CI Build Status](https://ci.centos.org/buildStatus/icon?job=systemd-pr-build)](https://ci.centos.org/job/systemd-pr-build/)<br/>
[![Build Status](https://dev.azure.com/evvers/systemd-systemd/_apis/build/status/systemd.systemd?branchName=master)](https://dev.azure.com/evvers/systemd-systemd/_build/latest?definitionId=1&branchName=master) [![Build Status](https://dev.azure.com/evvers/systemd-systemd/_apis/build/status/systemd.systemd?branchName=master)](https://dev.azure.com/evvers/systemd-systemd/_build/latest?definitionId=1&branchName=master)<br/>
[![Packaging status](https://repology.org/badge/tiny-repos/systemd.svg)](https://repology.org/project/systemd/versions)
## Details ## Details

View File

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<!ENTITY MOUNT_PATH @MOUNT_PATH@> <!ENTITY MOUNT_PATH @MOUNT_PATH@>
<!ENTITY UMOUNT_PATH @UMOUNT_PATH@> <!ENTITY UMOUNT_PATH @UMOUNT_PATH@>
<!ENTITY systemgeneratordir @SYSTEM_GENERATOR_PATH@> <!ENTITY systemgeneratordir @SYSTEM_GENERATOR_DIR@>
<!ENTITY usergeneratordir @USER_GENERATOR_PATH@> <!ENTITY usergeneratordir @USER_GENERATOR_DIR@>
<!ENTITY systemenvgeneratordir @SYSTEM_ENV_GENERATOR_PATH@> <!ENTITY systemenvgeneratordir @SYSTEM_ENV_GENERATOR_DIR@>
<!ENTITY userenvgeneratordir @USER_ENV_GENERATOR_PATH@> <!ENTITY userenvgeneratordir @USER_ENV_GENERATOR_DIR@>
<!ENTITY CERTIFICATE_ROOT @CERTIFICATE_ROOT@> <!ENTITY CERTIFICATE_ROOT @CERTIFICATE_ROOT@>
<!ENTITY MEMORY_ACCOUNTING_DEFAULT @MEMORY_ACCOUNTING_DEFAULT_YES_NO@> <!ENTITY MEMORY_ACCOUNTING_DEFAULT @MEMORY_ACCOUNTING_DEFAULT_YES_NO@>
<!ENTITY KILL_USER_PROCESSES @KILL_USER_PROCESSES_YES_NO@> <!ENTITY KILL_USER_PROCESSES @KILL_USER_PROCESSES_YES_NO@>

View File

@ -6,6 +6,9 @@ if [ -z "$1" ]; then
exit 1 exit 1
fi 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" target="man/$1.html"
ninja -C "@BUILD_ROOT@" "$target" ninja -C "@BUILD_ROOT@" "$target"
set -x set -x

View File

@ -6,6 +6,9 @@ if [ -z "$1" ]; then
exit 1 exit 1
fi 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/\./\\./')" page="$(echo "$1" | sed 's/\./\\./')"
target=$(ninja -C "@BUILD_ROOT@" -t query man/man | grep -E -m1 "man/$page\.[0-9]$" | awk '{print $2}') target=$(ninja -C "@BUILD_ROOT@" -t query man/man | grep -E -m1 "man/$page\.[0-9]$" | awk '{print $2}')
if [ -z "$target" ]; then if [ -z "$target" ]; then

9
man/path-documents.c Normal file
View 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);
}

View File

@ -352,10 +352,13 @@ manpages = [
''], ''],
['sd_bus_set_sender', '3', ['sd_bus_get_sender'], ''], ['sd_bus_set_sender', '3', ['sd_bus_get_sender'], ''],
['sd_bus_set_watch_bind', '3', ['sd_bus_get_watch_bind'], ''], ['sd_bus_set_watch_bind', '3', ['sd_bus_get_watch_bind'], ''],
['sd_bus_slot_ref', ['sd_bus_slot_get_bus',
'3', '3',
['sd_bus_slot_get_bus', 'sd_bus_slot_unref', 'sd_bus_slot_unrefp'], ['sd_bus_slot_get_current_handler',
'sd_bus_slot_get_current_message',
'sd_bus_slot_get_current_userdata'],
''], ''],
['sd_bus_slot_ref', '3', ['sd_bus_slot_unref', 'sd_bus_slot_unrefp'], ''],
['sd_bus_slot_set_description', '3', ['sd_bus_slot_get_description'], ''], ['sd_bus_slot_set_description', '3', ['sd_bus_slot_get_description'], ''],
['sd_bus_slot_set_destroy_callback', ['sd_bus_slot_set_destroy_callback',
'3', '3',
@ -623,6 +626,7 @@ manpages = [
'3', '3',
['sd_notifyf', 'sd_pid_notify', 'sd_pid_notify_with_fds', 'sd_pid_notifyf'], ['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', ['sd_pid_get_owner_uid',
'3', '3',
['sd_peer_get_cgroup', ['sd_peer_get_cgroup',

View File

@ -96,7 +96,10 @@
<citerefentry><refentrytitle>sd_bus_set_method_call_timeout</refentrytitle><manvolnum>3</manvolnum></citerefentry>, <citerefentry><refentrytitle>sd_bus_set_method_call_timeout</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_set_sender</refentrytitle><manvolnum>3</manvolnum></citerefentry>, <citerefentry><refentrytitle>sd_bus_set_sender</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_set_watch_bind</refentrytitle><manvolnum>3</manvolnum></citerefentry> <citerefentry><refentrytitle>sd_bus_set_watch_bind</refentrytitle><manvolnum>3</manvolnum></citerefentry>
<citerefentry><refentrytitle>sd_bus_set_close_on_exit</refentrytitle><manvolnum>3</manvolnum></citerefentry> <citerefentry><refentrytitle>sd_bus_set_close_on_exit</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_slot_get_current_handler</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_slot_get_current_message</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_slot_get_current_userdata</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_slot_set_description</refentrytitle><manvolnum>3</manvolnum></citerefentry>, <citerefentry><refentrytitle>sd_bus_slot_set_description</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_slot_set_destroy_callback</refentrytitle><manvolnum>3</manvolnum></citerefentry>, <citerefentry><refentrytitle>sd_bus_slot_set_destroy_callback</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_slot_set_floating</refentrytitle><manvolnum>3</manvolnum></citerefentry>, <citerefentry><refentrytitle>sd_bus_slot_set_floating</refentrytitle><manvolnum>3</manvolnum></citerefentry>,

View File

@ -0,0 +1,88 @@
<?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_bus_slot_get_bus" xmlns:xi="http://www.w3.org/2001/XInclude">
<refentryinfo>
<title>sd_bus_slot_get_bus</title>
<productname>systemd</productname>
</refentryinfo>
<refmeta>
<refentrytitle>sd_bus_slot_get_bus</refentrytitle>
<manvolnum>3</manvolnum>
</refmeta>
<refnamediv>
<refname>sd_bus_slot_get_bus</refname>
<refname>sd_bus_slot_get_current_handler</refname>
<refname>sd_bus_slot_get_current_message</refname>
<refname>sd_bus_slot_get_current_userdata</refname>
<refpurpose>Query information attached to a bus slot object</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcsynopsisinfo>#include &lt;systemd/sd-bus.h&gt;</funcsynopsisinfo>
<funcprototype>
<funcdef>sd_bus *<function>sd_bus_slot_get_bus</function></funcdef>
<paramdef>sd_bus_slot *<parameter>slot</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>sd_bus_message_handler_t <function>sd_bus_slot_get_current_handler</function>
</funcdef>
<paramdef>sd_bus_slot *<parameter>slot</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>sd_bus_message *<function>sd_bus_slot_get_current_message</function></funcdef>
<paramdef>sd_bus_slot *<parameter>slot</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>void *<function>sd_bus_slot_get_current_userdata</function></funcdef>
<paramdef>sd_bus_slot *<parameter>slot</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>Description</title>
<para><function>sd_bus_slot_get_bus()</function> returns the bus object that message
<parameter>slot</parameter> is attached to.</para>
<para><function>sd_bus_slot_get_current_handler()</function>,
<function>sd_bus_slot_get_current_message()</function> and
<function>sd_bus_slot_get_current_userdata()</function> return the current handler, message and
userdata respectively of the bus <parameter>slot</parameter> is attached to if we're currently
executing the callback associated with <parameter>slot</parameter>.</para>
</refsect1>
<refsect1>
<title>Return Value</title>
<para><function>sd_bus_slot_get_bus()</function> always returns the bus object.</para>
<para>On success, <function>sd_bus_slot_get_current_handler()</function>,
<function>sd_bus_slot_get_current_message()</function> and
<function>sd_bus_slot_get_current_userdata()</function> return the requested object. On failure,
they return <constant>NULL</constant>.</para>
</refsect1>
<xi:include href="libsystemd-pkgconfig.xml" />
<refsect1>
<title>See Also</title>
<para>
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
</para>
</refsect1>
</refentry>

View File

@ -18,7 +18,6 @@
<refname>sd_bus_slot_ref</refname> <refname>sd_bus_slot_ref</refname>
<refname>sd_bus_slot_unref</refname> <refname>sd_bus_slot_unref</refname>
<refname>sd_bus_slot_unrefp</refname> <refname>sd_bus_slot_unrefp</refname>
<refname>sd_bus_slot_get_bus</refname>
<refpurpose>Create and destroy references to a bus slot object</refpurpose> <refpurpose>Create and destroy references to a bus slot object</refpurpose>
</refnamediv> </refnamediv>
@ -41,11 +40,6 @@
<funcdef>void <function>sd_bus_slot_unrefp</function></funcdef> <funcdef>void <function>sd_bus_slot_unrefp</function></funcdef>
<paramdef>sd_bus_slot **<parameter>slotp</parameter></paramdef> <paramdef>sd_bus_slot **<parameter>slotp</parameter></paramdef>
</funcprototype> </funcprototype>
<funcprototype>
<funcdef>sd_bus *<function>sd_bus_slot_get_bus</function></funcdef>
<paramdef>sd_bus_slot *<parameter>m</parameter></paramdef>
</funcprototype>
</funcsynopsis> </funcsynopsis>
</refsynopsisdiv> </refsynopsisdiv>
@ -72,11 +66,7 @@
execute no operation if the passed in bus object address is execute no operation if the passed in bus object address is
<constant>NULL</constant>. <function>sd_bus_slot_unrefp()</function> will first dereference <constant>NULL</constant>. <function>sd_bus_slot_unrefp()</function> will first dereference
its argument, which must not be <constant>NULL</constant>, and will execute no operation if its argument, which must not be <constant>NULL</constant>, and will execute no operation if
<emphasis>that</emphasis> is <constant>NULL</constant>. <emphasis>that</emphasis> is <constant>NULL</constant>.</para>
</para>
<para><function>sd_bus_slot_get_bus()</function> returns the bus object that message
<parameter>slot</parameter> is attached to.</para>
</refsect1> </refsect1>
<refsect1> <refsect1>
@ -85,8 +75,6 @@
<para><function>sd_bus_slot_ref()</function> always returns the argument.</para> <para><function>sd_bus_slot_ref()</function> always returns the argument.</para>
<para><function>sd_bus_slot_unref()</function> always returns <constant>NULL</constant>.</para> <para><function>sd_bus_slot_unref()</function> always returns <constant>NULL</constant>.</para>
<para><function>sd_bus_slot_get_bus()</function> always returns the bus object.</para>
</refsect1> </refsect1>
<xi:include href="libsystemd-pkgconfig.xml" /> <xi:include href="libsystemd-pkgconfig.xml" />

215
man/sd_path_lookup.xml Normal file
View 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 &lt;systemd/sd-path.h&gt;</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>

View File

@ -32,7 +32,7 @@ key.middle/part/with/dots.foo = 123
-key.that.will.not.fail = value -key.that.will.not.fail = value
key.pattern.*.with.glob = whatever key.pattern.*.with.glob = whatever
-key.pattern.excluded.with.glob -key.pattern.excluded.with.glob
key.pattern.overriden.with.glob = custom key.pattern.overridden.with.glob = custom
</programlisting> </programlisting>
</refsynopsisdiv> </refsynopsisdiv>

View File

@ -196,7 +196,7 @@ memory_accounting_default = get_option('memory-accounting-default')
status_unit_format_default = get_option('status-unit-format-default') status_unit_format_default = get_option('status-unit-format-default')
conf.set_quoted('PKGSYSCONFDIR', pkgsysconfdir) 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_DATA_UNIT_PATH', systemunitdir)
conf.set_quoted('SYSTEM_SYSVINIT_PATH', sysvinit_path) conf.set_quoted('SYSTEM_SYSVINIT_PATH', sysvinit_path)
conf.set_quoted('SYSTEM_SYSVRCND_PATH', sysvrcnd_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('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_CONFIG_UNIT_DIR', join_paths(pkgsysconfdir, 'user'))
conf.set_quoted('USER_DATA_UNIT_PATH', userunitdir) conf.set_quoted('USER_DATA_UNIT_DIR', userunitdir)
conf.set_quoted('CERTIFICATE_ROOT', get_option('certificate-root')) conf.set_quoted('CERTIFICATE_ROOT', get_option('certificate-root'))
conf.set_quoted('CATALOG_DATABASE', join_paths(catalogstatedir, 'database')) conf.set_quoted('CATALOG_DATABASE', join_paths(catalogstatedir, 'database'))
conf.set_quoted('SYSTEMD_CGROUP_AGENT_PATH', join_paths(rootlibexecdir, 'systemd-cgroups-agent')) 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_DIR', randomseeddir)
conf.set_quoted('RANDOM_SEED', join_paths(randomseeddir, 'random-seed')) conf.set_quoted('RANDOM_SEED', join_paths(randomseeddir, 'random-seed'))
conf.set_quoted('SYSTEMD_CRYPTSETUP_PATH', join_paths(rootlibexecdir, 'systemd-cryptsetup')) conf.set_quoted('SYSTEMD_CRYPTSETUP_PATH', join_paths(rootlibexecdir, 'systemd-cryptsetup'))
conf.set_quoted('SYSTEM_GENERATOR_PATH', systemgeneratordir) conf.set_quoted('SYSTEM_GENERATOR_DIR', systemgeneratordir)
conf.set_quoted('USER_GENERATOR_PATH', usergeneratordir) conf.set_quoted('USER_GENERATOR_DIR', usergeneratordir)
conf.set_quoted('SYSTEM_ENV_GENERATOR_PATH', systemenvgeneratordir) conf.set_quoted('SYSTEM_ENV_GENERATOR_DIR', systemenvgeneratordir)
conf.set_quoted('USER_ENV_GENERATOR_PATH', userenvgeneratordir) conf.set_quoted('USER_ENV_GENERATOR_DIR', userenvgeneratordir)
conf.set_quoted('SYSTEM_SHUTDOWN_PATH', systemshutdowndir) conf.set_quoted('SYSTEM_SHUTDOWN_PATH', systemshutdowndir)
conf.set_quoted('SYSTEM_SLEEP_PATH', systemsleepdir) conf.set_quoted('SYSTEM_SLEEP_PATH', systemsleepdir)
conf.set_quoted('SYSTEMD_KBD_MODEL_MAP', join_paths(pkgdatadir, 'kbd-model-map')) conf.set_quoted('SYSTEMD_KBD_MODEL_MAP', join_paths(pkgdatadir, 'kbd-model-map'))

View File

@ -107,6 +107,10 @@ int capability_ambient_set_apply(uint64_t set, bool also_inherit) {
unsigned long i; unsigned long i;
int r; int r;
/* Check that we can use PR_CAP_AMBIENT or quit early. */
if (!ambient_capabilities_supported())
return 0;
/* Add the capabilities to the ambient set. */ /* Add the capabilities to the ambient set. */
if (also_inherit) { if (also_inherit) {

View File

@ -159,6 +159,8 @@ basic_sources = files('''
ordered-set.h ordered-set.h
parse-util.c parse-util.c
parse-util.h parse-util.h
path-lookup.c
path-lookup.h
path-util.c path-util.c
path-util.h path-util.h
prioq.c prioq.c

View File

@ -6,19 +6,15 @@
#include "alloc-util.h" #include "alloc-util.h"
#include "fs-util.h" #include "fs-util.h"
#include "install.h"
#include "log.h" #include "log.h"
#include "macro.h" #include "macro.h"
#include "mkdir.h"
#include "path-lookup.h" #include "path-lookup.h"
#include "path-util.h" #include "path-util.h"
#include "rm-rf.h"
#include "stat-util.h" #include "stat-util.h"
#include "string-util.h" #include "string-util.h"
#include "strv.h" #include "strv.h"
#include "tmpfile-util.h" #include "tmpfile-util.h"
#include "user-util.h" #include "user-util.h"
#include "util.h"
int xdg_user_runtime_dir(char **ret, const char *suffix) { int xdg_user_runtime_dir(char **ret, const char *suffix) {
const char *e; 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[] = { static const char* const user_data_unit_paths[] = {
"/usr/local/lib/systemd/user", "/usr/local/lib/systemd/user",
"/usr/local/share/systemd/user", "/usr/local/share/systemd/user",
USER_DATA_UNIT_PATH, USER_DATA_UNIT_DIR,
"/usr/lib/systemd/user", "/usr/lib/systemd/user",
"/usr/share/systemd/user", "/usr/share/systemd/user",
NULL NULL
}; };
static const char* const user_config_unit_paths[] = { static const char* const user_config_unit_paths[] = {
USER_CONFIG_UNIT_PATH, USER_CONFIG_UNIT_DIR,
"/etc/systemd/user", "/etc/systemd/user",
NULL NULL
}; };
@ -325,12 +321,12 @@ static int acquire_config_dirs(UnitFileScope scope, char **persistent, char **ru
switch (scope) { switch (scope) {
case UNIT_FILE_SYSTEM: case UNIT_FILE_SYSTEM:
a = strdup(SYSTEM_CONFIG_UNIT_PATH); a = strdup(SYSTEM_CONFIG_UNIT_DIR);
b = strdup("/run/systemd/system"); b = strdup("/run/systemd/system");
break; break;
case UNIT_FILE_GLOBAL: case UNIT_FILE_GLOBAL:
a = strdup(USER_CONFIG_UNIT_PATH); a = strdup(USER_CONFIG_UNIT_DIR);
b = strdup("/run/systemd/user"); b = strdup("/run/systemd/user");
break; break;
@ -618,7 +614,7 @@ int lookup_paths_init(
STRV_IFNOTNULL(transient), STRV_IFNOTNULL(transient),
STRV_IFNOTNULL(generator_early), STRV_IFNOTNULL(generator_early),
persistent_config, persistent_config,
SYSTEM_CONFIG_UNIT_PATH, SYSTEM_CONFIG_UNIT_DIR,
"/etc/systemd/system", "/etc/systemd/system",
STRV_IFNOTNULL(persistent_attached), STRV_IFNOTNULL(persistent_attached),
runtime_config, runtime_config,
@ -642,7 +638,7 @@ int lookup_paths_init(
STRV_IFNOTNULL(transient), STRV_IFNOTNULL(transient),
STRV_IFNOTNULL(generator_early), STRV_IFNOTNULL(generator_early),
persistent_config, persistent_config,
USER_CONFIG_UNIT_PATH, USER_CONFIG_UNIT_DIR,
"/etc/systemd/user", "/etc/systemd/user",
runtime_config, runtime_config,
"/run/systemd/user", "/run/systemd/user",
@ -650,7 +646,7 @@ int lookup_paths_init(
"/usr/local/share/systemd/user", "/usr/local/share/systemd/user",
"/usr/share/systemd/user", "/usr/share/systemd/user",
"/usr/local/lib/systemd/user", "/usr/local/lib/systemd/user",
USER_DATA_UNIT_PATH, USER_DATA_UNIT_DIR,
"/usr/lib/systemd/user", "/usr/lib/systemd/user",
STRV_IFNOTNULL(generator_late)); STRV_IFNOTNULL(generator_late));
break; 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) { char **generator_binary_paths(UnitFileScope scope) {
bool append = false; /* Add items from SYSTEMD_GENERATOR_PATH before normal directories */ bool append = false; /* Add items from SYSTEMD_GENERATOR_PATH before normal directories */
_cleanup_strv_free_ char **paths = NULL; _cleanup_strv_free_ char **paths = NULL;
@ -852,7 +798,7 @@ char **generator_binary_paths(UnitFileScope scope) {
add = strv_new("/run/systemd/system-generators", add = strv_new("/run/systemd/system-generators",
"/etc/systemd/system-generators", "/etc/systemd/system-generators",
"/usr/local/lib/systemd/system-generators", "/usr/local/lib/systemd/system-generators",
SYSTEM_GENERATOR_PATH); SYSTEM_GENERATOR_DIR);
break; break;
case UNIT_FILE_GLOBAL: case UNIT_FILE_GLOBAL:
@ -860,7 +806,7 @@ char **generator_binary_paths(UnitFileScope scope) {
add = strv_new("/run/systemd/user-generators", add = strv_new("/run/systemd/user-generators",
"/etc/systemd/user-generators", "/etc/systemd/user-generators",
"/usr/local/lib/systemd/user-generators", "/usr/local/lib/systemd/user-generators",
USER_GENERATOR_PATH); USER_GENERATOR_DIR);
break; break;
default: default:
@ -899,12 +845,12 @@ char **env_generator_binary_paths(bool is_system) {
add = strv_new("/run/systemd/system-environment-generators", add = strv_new("/run/systemd/system-environment-generators",
"/etc/systemd/system-environment-generators", "/etc/systemd/system-environment-generators",
"/usr/local/lib/systemd/system-environment-generators", "/usr/local/lib/systemd/system-environment-generators",
SYSTEM_ENV_GENERATOR_PATH); SYSTEM_ENV_GENERATOR_DIR);
else else
add = strv_new("/run/systemd/user-environment-generators", add = strv_new("/run/systemd/user-environment-generators",
"/etc/systemd/user-environment-generators", "/etc/systemd/user-environment-generators",
"/usr/local/lib/systemd/user-environment-generators", "/usr/local/lib/systemd/user-environment-generators",
USER_ENV_GENERATOR_PATH); USER_ENV_GENERATOR_DIR);
if (!add) if (!add)
return NULL; return NULL;

View File

@ -5,6 +5,7 @@
typedef struct LookupPaths LookupPaths; typedef struct LookupPaths LookupPaths;
#include "def.h"
#include "unit-file.h" #include "unit-file.h"
#include "macro.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); bool path_is_user_config_dir(const char *path);
void lookup_paths_log(LookupPaths *p); 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); void lookup_paths_free(LookupPaths *p);
char **generator_binary_paths(UnitFileScope scope); char **generator_binary_paths(UnitFileScope scope);
char **env_generator_binary_paths(bool is_system); 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")

View File

@ -87,6 +87,16 @@ char **strv_parse_nulstr(const char *s, size_t l);
char **strv_split_nulstr(const char *s); char **strv_split_nulstr(const char *s);
int strv_make_nulstr(char * const *l, char **p, size_t *n); 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_; bool strv_overlap(char * const *a, char * const *b) _pure_;
#define STRV_FOREACH(s, l) \ #define STRV_FOREACH(s, l) \

View File

@ -83,6 +83,8 @@ static int device_set_sysfs(Device *d, const char *sysfs) {
} }
d->sysfs = TAKE_PTR(copy); d->sysfs = TAKE_PTR(copy);
unit_add_to_dbus_queue(UNIT(d));
return 0; return 0;
} }
@ -562,9 +564,6 @@ static int device_setup_unit(Manager *m, sd_device *dev, const char *path, bool
if (dev && device_is_bound_by_mounts(DEVICE(u), dev)) if (dev && device_is_bound_by_mounts(DEVICE(u), dev))
device_upgrade_mount_deps(u); device_upgrade_mount_deps(u);
/* Note that this won't dispatch the load queue, the caller has to do that if needed and appropriate */
unit_add_to_dbus_queue(u);
return 0; return 0;
fail: fail:

View 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);
}

View 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);

View File

@ -44,6 +44,7 @@
#include "fd-util.h" #include "fd-util.h"
#include "fileio.h" #include "fileio.h"
#include "fs-util.h" #include "fs-util.h"
#include "generator-setup.h"
#include "hashmap.h" #include "hashmap.h"
#include "install.h" #include "install.h"
#include "io-util.h" #include "io-util.h"
@ -689,7 +690,7 @@ static int manager_setup_prefix(Manager *m) {
p = paths_user; p = paths_user;
for (i = 0; i < _EXEC_DIRECTORY_TYPE_MAX; i++) { 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) if (r < 0)
return r; return r;
} }

View File

@ -72,6 +72,8 @@ libcore_sources = '''
emergency-action.h emergency-action.h
execute.c execute.c
execute.h execute.h
generator-setup.c
generator-setup.h
hostname-setup.c hostname-setup.c
hostname-setup.h hostname-setup.h
ima-setup.c ima-setup.c

View File

@ -7,36 +7,93 @@
# the Free Software Foundation; either version 2.1 of the License, or # the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version. # (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@ prefix=@prefix@
rootprefix=@rootprefix_noslash@ root_prefix=@rootprefix_noslash@
sysconfdir=@sysconfdir@ rootprefix=${root_prefix}
systemdutildir=${rootprefix}/lib/systemd sysconf_dir=@sysconfdir@
systemdsystemunitdir=${rootprefix}/lib/systemd/system sysconfdir=${sysconf_dir}
systemdsystempresetdir=${rootprefix}/lib/systemd/system-preset
systemduserunitdir=${prefix}/lib/systemd/user systemd_util_dir=${root_prefix}/lib/systemd
systemduserpresetdir=${prefix}/lib/systemd/user-preset systemdutildir=${systemd_util_dir}
systemdsystemconfdir=${sysconfdir}/systemd/system
systemduserconfdir=${sysconfdir}/systemd/user systemd_system_unit_dir=${rootprefix}/lib/systemd/system
systemdsystemunitpath=${systemdsystemconfdir}:/etc/systemd/system:/run/systemd/system:/usr/local/lib/systemd/system:${systemdsystemunitdir}:/usr/lib/systemd/system:/lib/systemd/system systemdsystemunitdir=${systemd_system_unit_dir}
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 systemd_system_preset_dir=${rootprefix}/lib/systemd/system-preset
systemdusergeneratordir=${prefix}/lib/systemd/user-generators systemdsystempresetdir=${systemd_system_preset_dir}
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} systemd_user_unit_dir=${prefix}/lib/systemd/user
systemdsleepdir=${rootprefix}/lib/systemd/system-sleep systemduserunitdir=${systemd_user_unit_dir}
systemdshutdowndir=${rootprefix}/lib/systemd/system-shutdown
tmpfilesdir=${prefix}/lib/tmpfiles.d systemd_user_preset_dir=${prefix}/lib/systemd/user-preset
sysusersdir=${prefix}/lib/sysusers.d systemduserpresetdir=${systemd_user_preset_dir}
sysctldir=${prefix}/lib/sysctl.d
binfmtdir=${prefix}/lib/binfmt.d systemd_system_conf_dir=${sysconfdir}/systemd/system
modulesloaddir=${prefix}/lib/modules-load.d systemdsystemconfdir=${systemd_system_conf_dir}
catalogdir=${prefix}/lib/systemd/catalog
systemuidmax=@systemuidmax@ systemd_user_conf_dir=${sysconfdir}/systemd/user
systemgidmax=@systemgidmax@ systemduserconfdir=${systemd_user_conf_dir}
dynamicuidmin=@dynamicuidmin@
dynamicuidmax=@dynamicuidmax@ 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
containeruidbasemin=@containeruidbasemin@ systemdsystemunitpath=${systemd_system_unit_path}
containeruidbasemax=@containeruidbasemax@
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 Name: systemd
Description: systemd System and Service Manager Description: systemd System and Service Manager

View File

@ -20,7 +20,7 @@ static int environment_dirs(char ***ret) {
return -ENOMEM; return -ENOMEM;
/* ~/.config/systemd/environment.d */ /* ~/.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) if (r < 0)
return r; return r;

View File

@ -8,7 +8,6 @@
#include "sd-dhcp-lease.h" #include "sd-dhcp-lease.h"
#include "conf-parser.h" #include "conf-parser.h"
#include "def.h"
#include "set.h" #include "set.h"
#include "strv.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. */ /* 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); 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"))

View File

@ -697,3 +697,9 @@ global:
sd_event_source_send_child_signal; sd_event_source_send_child_signal;
sd_journal_open_namespace; sd_journal_open_namespace;
} LIBSYSTEMD_243; } LIBSYSTEMD_243;
LIBSYSTEMD_246 {
global:
sd_path_lookup;
sd_path_lookup_strv;
} LIBSYSTEMD_245;

View File

@ -7,6 +7,7 @@
#include "fd-util.h" #include "fd-util.h"
#include "fileio.h" #include "fileio.h"
#include "fs-util.h" #include "fs-util.h"
#include "path-lookup.h"
#include "path-util.h" #include "path-util.h"
#include "string-util.h" #include "string-util.h"
#include "strv.h" #include "strv.h"
@ -318,32 +319,122 @@ static int get_path(uint64_t type, char **buffer, const char **ret) {
case SD_PATH_USER_DESKTOP: case SD_PATH_USER_DESKTOP:
return from_user_dir("XDG_DESKTOP_DIR", buffer, ret); 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; 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; _cleanup_free_ char *buffer = NULL;
char *buffer2 = NULL;
const char *ret; const char *ret;
char *cc; int r;
assert(path);
r = get_path(type, &buffer, &ret);
if (r < 0)
return r;
if (suffix) {
suffix += strspn(suffix, "/");
buffer2 = path_join(ret, suffix);
if (!buffer2)
return -ENOMEM;
} else if (!buffer) {
buffer = strdup(ret);
if (!buffer)
return -ENOMEM;
}
*path = buffer2 ?: TAKE_PTR(buffer);
return 0;
}
_public_ int sd_path_lookup(uint64_t type, const char *suffix, char **path) {
int r; int r;
assert_return(path, -EINVAL); assert_return(path, -EINVAL);
if (IN_SET(type, r = get_path_alloc(type, suffix, path);
SD_PATH_SEARCH_BINARIES, if (r != -EOPNOTSUPP)
SD_PATH_SEARCH_BINARIES_DEFAULT, return r;
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)) {
/* Fall back to sd_path_lookup_strv */
_cleanup_strv_free_ char **l = NULL; _cleanup_strv_free_ char **l = NULL;
char *buffer;
r = sd_path_search(type, suffix, &l); r = sd_path_lookup_strv(type, suffix, &l);
if (r < 0) if (r < 0)
return r; return r;
@ -351,31 +442,7 @@ _public_ int sd_path_home(uint64_t type, const char *suffix, char **path) {
if (!buffer) if (!buffer)
return -ENOMEM; return -ENOMEM;
*path = TAKE_PTR(buffer); *path = buffer;
return 0;
}
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;
}
suffix += strspn(suffix, "/");
cc = path_join(ret, suffix);
if (!cc)
return -ENOMEM;
*path = TAKE_PTR(cc);
return 0; return 0;
} }
@ -454,6 +521,7 @@ static int search_from_environment(
#endif #endif
static int get_search(uint64_t type, char ***list) { static int get_search(uint64_t type, char ***list) {
int r;
assert(list); assert(list);
@ -536,58 +604,69 @@ static int get_search(uint64_t type, char ***list) {
"/etc", "/etc",
NULL); NULL);
case SD_PATH_SEARCH_BINARIES_DEFAULT: { case SD_PATH_SEARCH_BINARIES_DEFAULT:
char **t; 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) if (!t)
return -ENOMEM; return -ENOMEM;
*list = t; *list = t;
return 0; return 0;
}} }
case SD_PATH_SYSTEMD_NETWORK_PATH:
return strv_from_nulstr(list, NETWORK_DIRS_NULSTR);
}
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
_public_ int sd_path_search(uint64_t type, const char *suffix, char ***paths) { _public_ int sd_path_lookup_strv(uint64_t type, const char *suffix, char ***paths) {
char **i, **j;
_cleanup_strv_free_ char **l = NULL, **n = NULL; _cleanup_strv_free_ char **l = NULL, **n = NULL;
int r; int r;
assert_return(paths, -EINVAL); assert_return(paths, -EINVAL);
if (!IN_SET(type, r = get_search(type, &l);
SD_PATH_SEARCH_BINARIES, if (r == -EOPNOTSUPP) {
SD_PATH_SEARCH_BINARIES_DEFAULT, _cleanup_free_ char *t = NULL;
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)) {
char *p; r = get_path_alloc(type, suffix, &t);
r = sd_path_home(type, suffix, &p);
if (r < 0) if (r < 0)
return r; return r;
l = new(char*, 2); l = new(char*, 2);
if (!l) { if (!l)
free(p);
return -ENOMEM; return -ENOMEM;
} l[0] = TAKE_PTR(t);
l[0] = p;
l[1] = NULL; l[1] = NULL;
*paths = TAKE_PTR(l); *paths = TAKE_PTR(l);
return 0; return 0;
}
r = get_search(type, &l); } else if (r < 0)
if (r < 0)
return r; return r;
if (!suffix) { if (!suffix) {
@ -599,7 +678,7 @@ _public_ int sd_path_search(uint64_t type, const char *suffix, char ***paths) {
if (!n) if (!n)
return -ENOMEM; return -ENOMEM;
j = n; char **i, **j = n;
STRV_FOREACH(i, l) { STRV_FOREACH(i, l) {
*j = path_join(*i, suffix); *j = path_join(*i, suffix);
if (!*j) if (!*j)
@ -607,8 +686,8 @@ _public_ int sd_path_search(uint64_t type, const char *suffix, char ***paths) {
j++; j++;
} }
*j = NULL; *j = NULL;
*paths = TAKE_PTR(n); *paths = TAKE_PTR(n);
return 0; return 0;
} }

View File

@ -24,6 +24,7 @@
#include "network-internal.h" #include "network-internal.h"
#include "networkd-manager.h" #include "networkd-manager.h"
#include "nlmon.h" #include "nlmon.h"
#include "path-lookup.h"
#include "siphash24.h" #include "siphash24.h"
#include "stat-util.h" #include "stat-util.h"
#include "string-table.h" #include "string-table.h"

View File

@ -30,6 +30,7 @@
#include "networkd-network-bus.h" #include "networkd-network-bus.h"
#include "networkd-speed-meter.h" #include "networkd-speed-meter.h"
#include "ordered-set.h" #include "ordered-set.h"
#include "path-lookup.h"
#include "path-util.h" #include "path-util.h"
#include "set.h" #include "set.h"
#include "signal-util.h" #include "signal-util.h"

View File

@ -16,6 +16,7 @@
#include "networkd-manager.h" #include "networkd-manager.h"
#include "networkd-network.h" #include "networkd-network.h"
#include "parse-util.h" #include "parse-util.h"
#include "path-lookup.h"
#include "set.h" #include "set.h"
#include "socket-util.h" #include "socket-util.h"
#include "stat-util.h" #include "stat-util.h"

View File

@ -58,6 +58,31 @@ static const char* const path_table[_SD_PATH_MAX] = {
[SD_PATH_SEARCH_CONFIGURATION_FACTORY] = "search-configuration-factory", [SD_PATH_SEARCH_CONFIGURATION_FACTORY] = "search-configuration-factory",
[SD_PATH_SEARCH_STATE_FACTORY] = "search-state-factory", [SD_PATH_SEARCH_STATE_FACTORY] = "search-state-factory",
[SD_PATH_SEARCH_CONFIGURATION] = "search-configuration", [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) { static int list_homes(void) {
@ -68,11 +93,11 @@ static int list_homes(void) {
_cleanup_free_ char *p = NULL; _cleanup_free_ char *p = NULL;
int q; int q;
q = sd_path_home(i, arg_suffix, &p); q = sd_path_lookup(i, arg_suffix, &p);
if (q == -ENXIO)
continue;
if (q < 0) { if (q < 0) {
log_error_errno(r, "Failed to query %s: %m", path_table[i]); log_full_errno(q == -ENXIO ? LOG_DEBUG : LOG_ERR,
q, "Failed to query %s: %m", path_table[i]);
if (q != -ENXIO)
r = q; r = q;
continue; continue;
} }
@ -91,7 +116,7 @@ static int print_home(const char *n) {
if (streq(path_table[i], n)) { if (streq(path_table[i], n)) {
_cleanup_free_ char *p = NULL; _cleanup_free_ char *p = NULL;
r = sd_path_home(i, arg_suffix, &p); r = sd_path_lookup(i, arg_suffix, &p);
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to query %s: %m", n); 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[]) { static int parse_argv(int argc, char *argv[]) {
enum { enum {
ARG_VERSION = 0x100, ARG_VERSION = 0x100,
ARG_SUFFIX, ARG_SUFFIX,

View File

@ -160,8 +160,6 @@ shared_sources = files('''
output-mode.h output-mode.h
pager.c pager.c
pager.h pager.h
path-lookup.c
path-lookup.h
pe-header.h pe-header.h
pkcs11-util.c pkcs11-util.c
pkcs11-util.h pkcs11-util.h

View File

@ -12,6 +12,7 @@ _systemd_headers = '''
sd-journal.h sd-journal.h
sd-login.h sd-login.h
sd-messages.h sd-messages.h
sd-path.h
'''.split() '''.split()
# https://github.com/mesonbuild/meson/issues/1633 # https://github.com/mesonbuild/meson/issues/1633
@ -30,7 +31,6 @@ _not_installed_headers = '''
sd-ndisc.h sd-ndisc.h
sd-netlink.h sd-netlink.h
sd-network.h sd-network.h
sd-path.h
sd-radv.h sd-radv.h
sd-resolve.h sd-resolve.h
sd-utf8.h sd-utf8.h

View File

@ -78,11 +78,38 @@ enum {
SD_PATH_SEARCH_STATE_FACTORY, SD_PATH_SEARCH_STATE_FACTORY,
SD_PATH_SEARCH_CONFIGURATION, 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, _SD_PATH_MAX,
}; };
int sd_path_home(uint64_t type, const char *suffix, char **path); int sd_path_lookup(uint64_t type, const char *suffix, char **path);
int sd_path_search(uint64_t type, const char *suffix, char ***paths); int sd_path_lookup_strv(uint64_t type, const char *suffix, char ***paths);
_SD_END_DECLARATIONS; _SD_END_DECLARATIONS;

View File

@ -778,6 +778,10 @@ tests += [
[], [],
[]], []],
[['src/test/test-sd-path.c'],
[],
[]],
[['src/test/test-local-addresses.c'], [['src/test/test-local-addresses.c'],
[], [],
[]], []],

View File

@ -55,7 +55,7 @@ static void test_basic_mask_and_enable(const char *root) {
assert_se(n_changes == 1); assert_se(n_changes == 1);
assert_se(changes[0].type == UNIT_FILE_SYMLINK); assert_se(changes[0].type == UNIT_FILE_SYMLINK);
assert_se(streq(changes[0].source, "/dev/null")); 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)); assert_se(streq(changes[0].path, p));
unit_file_changes_free(changes, n_changes); 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(unit_file_unmask(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("a.service"), &changes, &n_changes) >= 0);
assert_se(n_changes == 1); assert_se(n_changes == 1);
assert_se(changes[0].type == UNIT_FILE_UNLINK); 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)); assert_se(streq(changes[0].path, p));
unit_file_changes_free(changes, n_changes); unit_file_changes_free(changes, n_changes);
changes = NULL; n_changes = 0; 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(n_changes == 1);
assert_se(changes[0].type == UNIT_FILE_SYMLINK); assert_se(changes[0].type == UNIT_FILE_SYMLINK);
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/a.service")); 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)); assert_se(streq(changes[0].path, p));
unit_file_changes_free(changes, n_changes); unit_file_changes_free(changes, n_changes);
changes = NULL; n_changes = 0; 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(unit_file_disable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("a.service"), &changes, &n_changes) >= 0);
assert_se(n_changes == 1); assert_se(n_changes == 1);
assert_se(changes[0].type == UNIT_FILE_UNLINK); 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(streq(changes[0].path, p));
unit_file_changes_free(changes, n_changes); unit_file_changes_free(changes, n_changes);
changes = NULL; n_changes = 0; 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(n_changes == 1);
assert_se(changes[0].type == UNIT_FILE_SYMLINK); assert_se(changes[0].type == UNIT_FILE_SYMLINK);
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/a.service")); 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)); assert_se(streq(changes[0].path, p));
unit_file_changes_free(changes, n_changes); unit_file_changes_free(changes, n_changes);
changes = NULL; n_changes = 0; 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(unit_file_reenable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("b.service"), &changes, &n_changes) >= 0);
assert_se(n_changes == 2); assert_se(n_changes == 2);
assert_se(changes[0].type == UNIT_FILE_UNLINK); 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(streq(changes[0].path, p));
assert_se(changes[1].type == UNIT_FILE_SYMLINK); assert_se(changes[1].type == UNIT_FILE_SYMLINK);
assert_se(streq(changes[1].source, "/usr/lib/systemd/system/a.service")); 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"); p = strjoina(root, "/usr/lib/systemd/system/linked2.service");
assert_se(symlink("/opt/linked2.service", p) >= 0); 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(symlink("/opt/linked3.service", p) >= 0);
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "linked.service", &state) == -ENOENT); 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(n_changes == 1);
assert_se(changes[0].type == UNIT_FILE_SYMLINK); assert_se(changes[0].type == UNIT_FILE_SYMLINK);
assert_se(streq(changes[0].source, "/opt/linked.service")); 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)); assert_se(streq(changes[0].path, p));
unit_file_changes_free(changes, n_changes); unit_file_changes_free(changes, n_changes);
changes = NULL; n_changes = 0; 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(unit_file_disable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("linked.service"), &changes, &n_changes) >= 0);
assert_se(n_changes == 1); assert_se(n_changes == 1);
assert_se(changes[0].type == UNIT_FILE_UNLINK); 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)); assert_se(streq(changes[0].path, p));
unit_file_changes_free(changes, n_changes); unit_file_changes_free(changes, n_changes);
changes = NULL; n_changes = 0; 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 */ /* 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(unit_file_enable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("/opt/linked.service"), &changes, &n_changes) >= 0);
assert_se(n_changes == 2); assert_se(n_changes == 2);
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/linked.service"); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/linked.service");
q = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/linked.service"); q = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/linked.service");
for (i = 0 ; i < n_changes; i++) { for (i = 0 ; i < n_changes; i++) {
assert_se(changes[i].type == UNIT_FILE_SYMLINK); assert_se(changes[i].type == UNIT_FILE_SYMLINK);
assert_se(streq(changes[i].source, "/opt/linked.service")); 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 */ /* 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(unit_file_disable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("linked.service"), &changes, &n_changes) >= 0);
assert_se(n_changes == 2); assert_se(n_changes == 2);
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/linked.service"); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/linked.service");
q = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/linked.service"); q = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/linked.service");
for (i = 0; i < n_changes; i++) { for (i = 0; i < n_changes; i++) {
assert_se(changes[i].type == UNIT_FILE_UNLINK); 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(unit_file_enable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("linked2.service"), &changes, &n_changes) >= 0);
assert_se(n_changes == 2); assert_se(n_changes == 2);
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/linked2.service"); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/linked2.service");
q = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/linked2.service"); q = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/linked2.service");
for (i = 0 ; i < n_changes; i++) { for (i = 0 ; i < n_changes; i++) {
assert_se(changes[i].type == UNIT_FILE_SYMLINK); assert_se(changes[i].type == UNIT_FILE_SYMLINK);
assert_se(streq(changes[i].source, "/opt/linked2.service")); 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(n_changes == 1);
assert_se(changes[0].type == UNIT_FILE_SYMLINK); assert_se(changes[0].type == UNIT_FILE_SYMLINK);
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/test-default-real.target")); 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)); assert_se(streq(changes[0].path, p));
unit_file_changes_free(changes, n_changes); unit_file_changes_free(changes, n_changes);
changes = NULL; n_changes = 0; changes = NULL; n_changes = 0;
@ -355,7 +355,7 @@ static void test_add_dependency(const char *root) {
assert_se(n_changes == 1); assert_se(n_changes == 1);
assert_se(changes[0].type == UNIT_FILE_SYMLINK); assert_se(changes[0].type == UNIT_FILE_SYMLINK);
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/real-add-dependency-test-service.service")); 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)); assert_se(streq(changes[0].path, p));
unit_file_changes_free(changes, n_changes); unit_file_changes_free(changes, n_changes);
changes = NULL; n_changes = 0; changes = NULL; n_changes = 0;
@ -396,7 +396,7 @@ static void test_template_enable(const char *root) {
assert_se(n_changes == 1); assert_se(n_changes == 1);
assert_se(changes[0].type == UNIT_FILE_SYMLINK); assert_se(changes[0].type == UNIT_FILE_SYMLINK);
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/template@.service")); 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)); assert_se(streq(changes[0].path, p));
unit_file_changes_free(changes, n_changes); unit_file_changes_free(changes, n_changes);
changes = NULL; n_changes = 0; 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(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(changes[0].type == UNIT_FILE_SYMLINK);
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/template@.service")); 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)); assert_se(streq(changes[0].path, p));
unit_file_changes_free(changes, n_changes); unit_file_changes_free(changes, n_changes);
changes = NULL; n_changes = 0; 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(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(changes[0].type == UNIT_FILE_SYMLINK);
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/template@.service")); 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)); assert_se(streq(changes[0].path, p));
unit_file_changes_free(changes, n_changes); unit_file_changes_free(changes, n_changes);
changes = NULL; n_changes = 0; changes = NULL; n_changes = 0;
@ -506,7 +506,7 @@ static void test_indirect(const char *root) {
assert_se(n_changes == 1); assert_se(n_changes == 1);
assert_se(changes[0].type == UNIT_FILE_SYMLINK); assert_se(changes[0].type == UNIT_FILE_SYMLINK);
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/indirectb.service")); 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)); assert_se(streq(changes[0].path, p));
unit_file_changes_free(changes, n_changes); unit_file_changes_free(changes, n_changes);
changes = NULL; n_changes = 0; 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(unit_file_disable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("indirectc.service"), &changes, &n_changes) >= 0);
assert_se(n_changes == 1); assert_se(n_changes == 1);
assert_se(changes[0].type == UNIT_FILE_UNLINK); 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)); assert_se(streq(changes[0].path, p));
unit_file_changes_free(changes, n_changes); unit_file_changes_free(changes, n_changes);
changes = NULL; n_changes = 0; 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(n_changes == 1);
assert_se(changes[0].type == UNIT_FILE_SYMLINK); assert_se(changes[0].type == UNIT_FILE_SYMLINK);
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/preset-yes.service")); 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)); assert_se(streq(changes[0].path, p));
unit_file_changes_free(changes, n_changes); unit_file_changes_free(changes, n_changes);
changes = NULL; n_changes = 0; 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(unit_file_disable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("preset-yes.service"), &changes, &n_changes) >= 0);
assert_se(n_changes == 1); assert_se(n_changes == 1);
assert_se(changes[0].type == UNIT_FILE_UNLINK); 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)); assert_se(streq(changes[0].path, p));
unit_file_changes_free(changes, n_changes); unit_file_changes_free(changes, n_changes);
changes = NULL; n_changes = 0; changes = NULL; n_changes = 0;
@ -590,7 +590,7 @@ static void test_preset_and_list(const char *root) {
assert_se(n_changes > 0); 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++) { 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); unit_file_changes_free(changes, n_changes);
changes = NULL; n_changes = 0; 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); assert_se(write_string_file(p, "# Empty override\n", WRITE_STRING_FILE_CREATE) >= 0);
/* Revert the override file */ /* Revert the override file */
@ -666,7 +666,7 @@ static void test_revert(const char *root) {
unit_file_changes_free(changes, n_changes); unit_file_changes_free(changes, n_changes);
changes = NULL; n_changes = 0; 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(mkdir_parents(p, 0755) >= 0);
assert_se(write_string_file(p, "# Empty dropin\n", WRITE_STRING_FILE_CREATE) >= 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(changes[0].type == UNIT_FILE_UNLINK);
assert_se(streq(changes[0].path, p)); 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(changes[1].type == UNIT_FILE_UNLINK);
assert_se(streq(changes[1].path, p)); assert_se(streq(changes[1].path, p));
unit_file_changes_free(changes, n_changes); 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(n_changes == 1);
assert_se(changes[0].type == UNIT_FILE_SYMLINK); assert_se(changes[0].type == UNIT_FILE_SYMLINK);
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/prefix-1.service")); 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)); assert_se(streq(changes[0].path, p));
unit_file_changes_free(changes, n_changes); unit_file_changes_free(changes, n_changes);
changes = NULL; n_changes = 0; 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); 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, assert_se(write_string_file(p,
"[Install]\n" "[Install]\n"
"WantedBy=multi-user.target\n", WRITE_STRING_FILE_CREATE) >= 0); "WantedBy=multi-user.target\n", WRITE_STRING_FILE_CREATE) >= 0);
@ -795,7 +795,7 @@ static void test_with_dropin(const char *root) {
"[Install]\n" "[Install]\n"
"WantedBy=multi-user.target\n", WRITE_STRING_FILE_CREATE) >= 0); "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(mkdir_parents(p, 0755) >= 0);
assert_se(write_string_file(p, assert_se(write_string_file(p,
"[Install]\n" "[Install]\n"
@ -808,7 +808,7 @@ static void test_with_dropin(const char *root) {
"[Install]\n" "[Install]\n"
"WantedBy=multi-user.target\n", WRITE_STRING_FILE_CREATE) >= 0); "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(mkdir_parents(p, 0755) >= 0);
assert_se(write_string_file(p, assert_se(write_string_file(p,
"[Install]\n" "[Install]\n"
@ -829,9 +829,9 @@ static void test_with_dropin(const char *root) {
assert_se(changes[1].type == UNIT_FILE_SYMLINK); 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[0].source, "/usr/lib/systemd/system/with-dropin-1.service"));
assert_se(streq(changes[1].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)); 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)); assert_se(streq(changes[1].path, p));
unit_file_changes_free(changes, n_changes); unit_file_changes_free(changes, n_changes);
changes = NULL; n_changes = 0; changes = NULL; n_changes = 0;
@ -841,11 +841,11 @@ static void test_with_dropin(const char *root) {
assert_se(n_changes == 2); assert_se(n_changes == 2);
assert_se(changes[0].type == UNIT_FILE_SYMLINK); assert_se(changes[0].type == UNIT_FILE_SYMLINK);
assert_se(changes[1].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[0].source, SYSTEM_CONFIG_UNIT_DIR"/with-dropin-2.service"));
assert_se(streq(changes[1].source, SYSTEM_CONFIG_UNIT_PATH"/with-dropin-2.service")); assert_se(streq(changes[1].source, SYSTEM_CONFIG_UNIT_DIR"/with-dropin-2.service"));
p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/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)); 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)); assert_se(streq(changes[1].path, p));
unit_file_changes_free(changes, n_changes); unit_file_changes_free(changes, n_changes);
changes = NULL; n_changes = 0; 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(changes[1].type == UNIT_FILE_SYMLINK);
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/with-dropin-3.service")); 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")); 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)); 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)); assert_se(streq(changes[1].path, p));
unit_file_changes_free(changes, n_changes); unit_file_changes_free(changes, n_changes);
changes = NULL; n_changes = 0; 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(changes[1].type == UNIT_FILE_SYMLINK);
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/with-dropin-4a.service")); 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")); 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)); 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)); assert_se(streq(changes[1].path, p));
unit_file_changes_free(changes, n_changes); unit_file_changes_free(changes, n_changes);
changes = NULL; n_changes = 0; 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(changes[1].type == UNIT_FILE_SYMLINK);
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/with-dropin-1@.service")); 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")); 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)); 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)); assert_se(streq(changes[1].path, p));
unit_file_changes_free(changes, n_changes); unit_file_changes_free(changes, n_changes);
changes = NULL; n_changes = 0; 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(changes[1].type == UNIT_FILE_SYMLINK);
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/with-dropin-2@.service")); 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")); 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)); 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)); assert_se(streq(changes[1].path, p));
unit_file_changes_free(changes, n_changes); unit_file_changes_free(changes, n_changes);
changes = NULL; n_changes = 0; 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(n_changes == 1);
assert_se(changes[0].type == UNIT_FILE_SYMLINK); assert_se(changes[0].type == UNIT_FILE_SYMLINK);
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/with-dropin-2@.service")); 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)); assert_se(streq(changes[0].path, p));
unit_file_changes_free(changes, n_changes); unit_file_changes_free(changes, n_changes);
changes = NULL; n_changes = 0; 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(n_changes == 1);
assert_se(changes[0].type == UNIT_FILE_SYMLINK); assert_se(changes[0].type == UNIT_FILE_SYMLINK);
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/with-dropin-3@.service")); 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)); assert_se(streq(changes[0].path, p));
unit_file_changes_free(changes, n_changes); unit_file_changes_free(changes, n_changes);
changes = NULL; n_changes = 0; 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(unit_file_get_state(UNIT_FILE_SYSTEM, root, "foo@bar0.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
assert_se(n_changes == 1); assert_se(n_changes == 1);
assert_se(changes[0].type == UNIT_FILE_SYMLINK); 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)); assert_se(streq(changes[0].path, p));
unit_file_changes_free(changes, n_changes); unit_file_changes_free(changes, n_changes);
changes = NULL; n_changes = 0; 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(unit_file_disable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("foo@bar0.service"), &changes, &n_changes) >= 0);
assert_se(n_changes == 1); assert_se(n_changes == 1);
assert_se(changes[0].type == UNIT_FILE_UNLINK); 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)); assert_se(streq(changes[0].path, p));
unit_file_changes_free(changes, n_changes); unit_file_changes_free(changes, n_changes);
changes = NULL; n_changes = 0; changes = NULL; n_changes = 0;
@ -1214,7 +1214,7 @@ int main(int argc, char *argv[]) {
p = strjoina(root, "/usr/lib/systemd/system/"); p = strjoina(root, "/usr/lib/systemd/system/");
assert_se(mkdir_p(p, 0755) >= 0); 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); assert_se(mkdir_p(p, 0755) >= 0);
p = strjoina(root, "/run/systemd/system/"); p = strjoina(root, "/run/systemd/system/");

69
src/test/test-sd-path.c Normal file
View 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();
}

View File

@ -244,7 +244,7 @@ static int specifier_directory(char specifier, const void *data, const void *use
i = PTR_TO_UINT(data); i = PTR_TO_UINT(data);
assert(i < ELEMENTSOF(paths_system)); 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) { static int log_unresolvable_specifier(const char *filename, unsigned line) {

View File

@ -20,6 +20,7 @@
#include "netlink-util.h" #include "netlink-util.h"
#include "network-internal.h" #include "network-internal.h"
#include "parse-util.h" #include "parse-util.h"
#include "path-lookup.h"
#include "path-util.h" #include "path-util.h"
#include "proc-cmdline.h" #include "proc-cmdline.h"
#include "random-util.h" #include "random-util.h"

View File

@ -2,4 +2,5 @@ Name: udev
Description: udev Description: udev
Version: @PROJECT_VERSION@ Version: @PROJECT_VERSION@
udevdir=@udevlibexecdir@ udev_dir=@udevlibexecdir@
udevdir=${udev_dir}

View File

@ -13,10 +13,10 @@ REPO_ROOT=${REPO_ROOT:-$(pwd)}
sudo bash -c "echo 'deb-src http://archive.ubuntu.com/ubuntu/ xenial main restricted universe multiverse' >>/etc/apt/sources.list" sudo bash -c "echo 'deb-src http://archive.ubuntu.com/ubuntu/ xenial main restricted universe multiverse' >>/etc/apt/sources.list"
sudo apt-get update -y sudo apt-get update -y
sudo apt-get build-dep systemd -y sudo apt-get build-dep systemd -y
sudo apt-get install -y ninja-build python3-pip python3-setuptools sudo apt-get install -y python3-pip python3-setuptools
# The following should be dropped when debian packaging has been updated to include them # The following should be dropped when debian packaging has been updated to include them
sudo apt-get install -y libfdisk-dev libp11-kit-dev libssl-dev libpwquality-dev sudo apt-get install -y libfdisk-dev libp11-kit-dev libssl-dev libpwquality-dev
pip3 install meson pip3 install ninja meson
cd $REPO_ROOT cd $REPO_ROOT
export PATH="$HOME/.local/bin/:$PATH" export PATH="$HOME/.local/bin/:$PATH"