]>
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
;
19 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
20 "Wrong argument count. Expected the OnlyShowIn= and NotShowIn= sets, each colon separated.");
22 xdg_current_desktop
= getenv("XDG_CURRENT_DESKTOP");
23 if (xdg_current_desktop
) {
24 desktops
= strv_split(xdg_current_desktop
, ":");
29 only_show_in
= strv_split(argv
[1], ":");
30 not_show_in
= strv_split(argv
[2], ":");
31 if (!only_show_in
|| !not_show_in
)
34 /* Each desktop in XDG_CURRENT_DESKTOP needs to be matched in order. */
35 STRV_FOREACH(d
, desktops
) {
36 if (strv_contains(only_show_in
, *d
))
38 if (strv_contains(not_show_in
, *d
))
42 /* non-zero exit code when only_show_in has a proper value */
43 return !strv_isempty(only_show_in
);
46 DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(run
);