Skip to content

Commit 6bce174

Browse files
authored
Merge pull request systemd#15226 from benzea/benzea/xdg-autostart-generator
xdg-autostart-generator: a generator for XDG autostart files
2 parents f978844 + 2ad7597 commit 6bce174

20 files changed

+1112
-1
lines changed

man/rules/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,7 @@ manpages = [
975975
['systemd-veritysetup'],
976976
'HAVE_LIBCRYPTSETUP'],
977977
['systemd-volatile-root.service', '8', ['systemd-volatile-root'], ''],
978+
['systemd-xdg-autostart-generator', '8', [], 'ENABLE_XDG_AUTOSTART'],
978979
['systemd', '1', ['init'], ''],
979980
['systemd.automount', '5', [], ''],
980981
['systemd.device', '5', [], ''],
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version="1.0"?>
2+
<!--*-nxml-*-->
3+
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
4+
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
5+
<!-- SPDX-License-Identifier: LGPL-2.1+ -->
6+
<refentry id="systemd-xdg-autostart-generator" conditional="ENABLE_XDG_AUTOSTART">
7+
8+
<refentryinfo>
9+
<title>systemd-xdg-autostart-generator</title>
10+
<productname>systemd</productname>
11+
</refentryinfo>
12+
13+
<refmeta>
14+
<refentrytitle>systemd-xdg-autostart-generator</refentrytitle>
15+
<manvolnum>8</manvolnum>
16+
</refmeta>
17+
18+
<refnamediv>
19+
<refname>systemd-xdg-autostart-generator</refname>
20+
<refpurpose>User unit generator for XDG autostart files</refpurpose>
21+
</refnamediv>
22+
23+
<refsynopsisdiv>
24+
<para><filename>/usr/lib/systemd/system-generators/systemd-xdg-autostart-generator</filename></para>
25+
</refsynopsisdiv>
26+
27+
<refsect1>
28+
<title>Description</title>
29+
30+
<para><filename>systemd-xdg-autostart-generator</filename> is a generator
31+
that creates .service units for
32+
<ulink url="https://specifications.freedesktop.org/autostart-spec/autostart-spec-latest.html">XDG autostart</ulink>
33+
files.
34+
This permits desktop environments to delegate startup of these applications to
35+
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>
36+
.</para>
37+
38+
<para>Units created by <filename>systemd-xdg-autostart-generator</filename>
39+
can be started by the desktop environment using <literal>xdg-desktop-autostart.target</literal>.
40+
See
41+
<citerefentry><refentrytitle>systemd.special</refentrytitle><manvolnum>5</manvolnum></citerefentry>
42+
for more details.</para>
43+
44+
<para><filename>systemd-xdg-autostart-generator</filename> implements
45+
<citerefentry><refentrytitle>systemd.generator</refentrytitle><manvolnum>7</manvolnum></citerefentry>.</para>
46+
</refsect1>
47+
48+
<refsect1>
49+
<title>See Also</title>
50+
<para>
51+
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
52+
<citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
53+
<citerefentry><refentrytitle>systemd.target</refentrytitle><manvolnum>5</manvolnum></citerefentry>
54+
</para>
55+
</refsect1>
56+
57+
</refentry>

man/systemd.generator.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ find $dir</programlisting>
310310
<citerefentry><refentrytitle>systemd-rc-local-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
311311
<citerefentry><refentrytitle>systemd-system-update-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
312312
<citerefentry><refentrytitle>systemd-sysv-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
313+
<citerefentry><refentrytitle>systemd-xdg-autostart-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
313314
<citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
314315
<citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
315316
<citerefentry><refentrytitle>systemd.environment-generator</refentrytitle><manvolnum>7</manvolnum></citerefentry>

man/systemd.special.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,18 @@
11501150
<filename>gnome-session.target</filename>.</para>
11511151
</listitem>
11521152
</varlistentry>
1153+
1154+
<varlistentry>
1155+
<term><filename>xdg-desktop-autostart.target</filename></term>
1156+
<listitem>
1157+
<para>The XDG specification defines a way to autostart applications using XDG desktop files.
1158+
systemd ships
1159+
<citerefentry><refentrytitle>systemd-xdg-autostart-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>
1160+
for the XDG desktop files in autostart directories.
1161+
Desktop Environments can opt-in to use this service by adding a <varname>Wants=</varname>
1162+
dependency on <literal>xdg-desktop-autostart.target</literal></para>.
1163+
</listitem>
1164+
</varlistentry>
11531165
</variablelist>
11541166
</refsect2>
11551167
</refsect1>

meson.build

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,6 +1417,7 @@ foreach term : ['utmp',
14171417
'tmpfiles',
14181418
'hwdb',
14191419
'rfkill',
1420+
'xdg-autostart',
14201421
'ldconfig',
14211422
'efi',
14221423
'tpm',
@@ -1520,6 +1521,7 @@ includes = include_directories('src/basic',
15201521
'src/libudev',
15211522
'src/core',
15221523
'src/shutdown',
1524+
'src/xdg-autostart-generator',
15231525
'src/libsystemd/sd-bus',
15241526
'src/libsystemd/sd-device',
15251527
'src/libsystemd/sd-event',
@@ -2301,6 +2303,27 @@ if conf.get('HAVE_SYSV_COMPAT') == 1
23012303
install_dir : systemgeneratordir)
23022304
endif
23032305

2306+
if conf.get('ENABLE_XDG_AUTOSTART') == 1
2307+
executable(
2308+
'systemd-xdg-autostart-generator',
2309+
'src/xdg-autostart-generator/xdg-autostart-generator.c',
2310+
'src/xdg-autostart-generator/xdg-autostart-service.c',
2311+
include_directories : includes,
2312+
link_with : [libshared],
2313+
install_rpath : rootlibexecdir,
2314+
install : true,
2315+
install_dir : usergeneratordir)
2316+
2317+
executable(
2318+
'systemd-xdg-autostart-condition',
2319+
'src/xdg-autostart-generator/xdg-autostart-condition.c',
2320+
include_directories : includes,
2321+
link_with : [libshared],
2322+
install_rpath : rootlibexecdir,
2323+
install : true,
2324+
install_dir : rootlibexecdir)
2325+
endif
2326+
23042327
if conf.get('ENABLE_HOSTNAMED') == 1
23052328
executable(
23062329
'systemd-hostnamed',
@@ -3566,6 +3589,7 @@ foreach tuple : [
35663589
['randomseed'],
35673590
['backlight'],
35683591
['rfkill'],
3592+
['xdg-autostart'],
35693593
['logind'],
35703594
['machined'],
35713595
['portabled'],

meson_options.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ option('hwdb', type : 'boolean',
142142
description : 'support for the hardware database')
143143
option('rfkill', type : 'boolean',
144144
description : 'support for the rfkill tools')
145+
option('xdg-autostart', type : 'boolean',
146+
description : 'install the xdg-autostart-generator and unit')
145147
option('man', type : 'combo', choices : ['auto', 'true', 'false'],
146148
value : 'false',
147149
description : 'build and install man pages')

src/fuzz/fuzz-xdg-desktop.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* SPDX-License-Identifier: LGPL-2.1+ */
2+
3+
#include "alloc-util.h"
4+
#include "fd-util.h"
5+
#include "fs-util.h"
6+
#include "rm-rf.h"
7+
#include "string-util.h"
8+
#include "strv.h"
9+
#include "tests.h"
10+
#include "tmpfile-util.h"
11+
#include "fuzz.h"
12+
#include "xdg-autostart-service.h"
13+
14+
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
15+
_cleanup_(unlink_tempfilep) char name[] = "/tmp/fuzz-xdg-desktop.XXXXXX";
16+
_cleanup_close_ int fd = -1;
17+
_cleanup_(xdg_autostart_service_freep) XdgAutostartService *service = NULL;
18+
_cleanup_(rm_rf_physical_and_freep) char *tmpdir = NULL;
19+
20+
/* We don't want to fill the logs with messages about parse errors.
21+
* Disable most logging if not running standalone */
22+
if (!getenv("SYSTEMD_LOG_LEVEL"))
23+
log_set_max_level(LOG_CRIT);
24+
25+
assert_se(mkdtemp_malloc("/tmp/fuzz-xdg-desktop-XXXXXX", &tmpdir) >= 0);
26+
27+
fd = mkostemp_safe(name);
28+
assert_se(fd >= 0);
29+
assert_se(write(fd, data, size) == (ssize_t) size);
30+
31+
assert_se(service = xdg_autostart_service_parse_desktop(name));
32+
assert_se(service->name = strdup("fuzz-xdg-desktop.service"));
33+
if (service)
34+
(void) xdg_autostart_service_generate_unit(service, tmpdir);
35+
36+
return 0;
37+
}

src/fuzz/meson.build

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,10 @@ fuzzers += [
146146
[['src/fuzz/fuzz-time-util.c'],
147147
[libshared],
148148
[]],
149+
150+
[['src/fuzz/fuzz-xdg-desktop.c',
151+
'src/xdg-autostart-generator/xdg-autostart-service.h',
152+
'src/xdg-autostart-generator/xdg-autostart-service.c'],
153+
[],
154+
[]],
149155
]

src/sysv-generator/sysv-generator.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ static int set_dependencies_from_rcnd(const LookupPaths *lp, Hashmap *all_servic
849849
continue;
850850
}
851851

852-
FOREACH_DIRENT(de, d, log_error_errno(errno, "Failed to enumerate directory %s, ignoring: %m", path)) {
852+
FOREACH_DIRENT(de, d, log_warning_errno(errno, "Failed to enumerate directory %s, ignoring: %m", path)) {
853853
_cleanup_free_ char *name = NULL, *fpath = NULL;
854854
int a, b;
855855

src/test/meson.build

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,3 +1143,13 @@ tests += [
11431143
libshared],
11441144
[threads]],
11451145
]
1146+
1147+
############################################################
1148+
1149+
tests += [
1150+
[['src/test/test-xdg-autostart.c',
1151+
'src/xdg-autostart-generator/xdg-autostart-service.c',
1152+
'src/xdg-autostart-generator/xdg-autostart-service.h',],
1153+
[],
1154+
[]],
1155+
]

0 commit comments

Comments
 (0)