]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/xdg-autostart-generator/xdg-autostart-condition.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
7 * This binary is intended to be run as an ExecCondition= in units generated
8 * by the xdg-autostart-generator. It does the appropriate checks against
9 * XDG_CURRENT_DESKTOP that are too advanced for simple ConditionEnvironment=
13 static int run(int argc
, char *argv
[]) {
14 _cleanup_strv_free_
char **only_show_in
= NULL
, **not_show_in
= NULL
, **desktops
= NULL
;
15 const char *xdg_current_desktop
;
18 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
19 "Wrong argument count. Expected the OnlyShowIn= and NotShowIn= sets, each colon separated.");
21 xdg_current_desktop
= getenv("XDG_CURRENT_DESKTOP");
22 if (xdg_current_desktop
) {
23 desktops
= strv_split(xdg_current_desktop
, ":");
28 only_show_in
= strv_split(argv
[1], ":");
29 not_show_in
= strv_split(argv
[2], ":");
30 if (!only_show_in
|| !not_show_in
)
33 /* Each desktop in XDG_CURRENT_DESKTOP needs to be matched in order. */
34 STRV_FOREACH(d
, desktops
) {
35 if (strv_contains(only_show_in
, *d
))
37 if (strv_contains(not_show_in
, *d
))
41 /* non-zero exit code when only_show_in has a proper value */
42 return !strv_isempty(only_show_in
);
45 DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(run
);