Commit Graph

250 Commits

Author SHA1 Message Date
Jan Kot
0b0fcfad11 Add support for Tilix and Konsole 2021-02-03 20:44:55 +01:00
Emmanuel Fleury
ae1eebb2e9 Fix signedness warning in gio/gdesktopappinfo.c:g_app_info_get_all()
gio/gdesktopappinfo.c: In function ‘g_app_info_get_all’:
gio/gdesktopappinfo.c:4597:17: error: comparison of integer expressions of different signedness: ‘int’ and ‘guint’ {aka ‘unsigned int’}
 4597 |   for (i = 0; i < desktop_file_dirs->len; i++)
      |                 ^
2021-01-19 10:03:12 +00:00
Emmanuel Fleury
9567665524 Fix signedness warning in gio/gdesktopappinfo.c:g_desktop_app_info_search()
gio/gdesktopappinfo.c: In function ‘g_desktop_app_info_search’:
gio/gdesktopappinfo.c:4517:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘guint’ {aka ‘unsigned int’}
 4517 |   for (i = 0; i < desktop_file_dirs->len; i++)
      |                 ^
2021-01-19 10:03:12 +00:00
Emmanuel Fleury
6bce33300a Fix signedness warning in gio/gdesktopappinfo.c:g_desktop_app_info_get_implementations()
gio/gdesktopappinfo.c: In function ‘g_desktop_app_info_get_implementations’:
gio/gdesktopappinfo.c:4451:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘guint’ {aka ‘unsigned int’}
 4451 |   for (i = 0; i < desktop_file_dirs->len; i++)
      |                 ^
2021-01-19 10:03:12 +00:00
Emmanuel Fleury
554b1ff0e2 Fix several signedness warnings in gio/gdesktopappinfo.c:g_app_info_get_default_for_type()
gio/gdesktopappinfo.c: In function ‘g_app_info_get_default_for_type’:
gio/gdesktopappinfo.c:4357:21: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘guint’ {aka ‘unsigned int’}
 4357 |       for (j = 0; j < desktop_file_dirs->len; j++)
      |                     ^
gio/gdesktopappinfo.c:4361:21: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘guint’ {aka ‘unsigned int’}
 4361 |       for (j = 0; j < desktop_file_dirs->len; j++)
      |                     ^
gio/gdesktopappinfo.c:4365:21: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘guint’ {aka ‘unsigned int’}
 4365 |       for (j = 0; j < results->len; j++)
      |                     ^
gio/gdesktopappinfo.c:4369:25: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘guint’ {aka ‘unsigned int’}
 4369 |           for (k = 0; k < desktop_file_dirs->len; k++)
      |                         ^
2021-01-19 10:03:12 +00:00
Emmanuel Fleury
daa0e0b76b Fix signedness warnings in gio/gdesktopappinfo.c:g_desktop_app_info_get_desktop_ids_for_content_type()
gio/gdesktopappinfo.c: In function ‘g_desktop_app_info_get_desktop_ids_for_content_type’:
gio/gdesktopappinfo.c:4154:19: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘guint’ {aka ‘unsigned int’}
 4154 |     for (j = 0; j < desktop_file_dirs->len; j++)
      |                   ^
gio/gdesktopappinfo.c:4158:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘guint’ {aka ‘unsigned int’} [-Werror=sign-compare]
 4158 |   for (i = 0; i < hits->len; i++)
      |                 ^
2021-01-19 10:03:12 +00:00
Emmanuel Fleury
46772fe4c3 Fix signedness warning in gio/gdesktopappinfo.c:get_list_of_mimetypes()
gio/gdesktopappinfo.c: In function ‘get_list_of_mimetypes’:
gio/gdesktopappinfo.c:4116:21: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘guint’ {aka ‘unsigned int’}
 4116 |       for (i = 0; i < array->len; i++)
      |                     ^
2021-01-19 10:03:12 +00:00
Emmanuel Fleury
08f73f8187 Fix signedness warning in gio/gdesktopappinfo.c:g_desktop_app_info_launch_uris_with_spawn()
gio/gdesktopappinfo.c: In function ‘g_desktop_app_info_launch_uris_with_spawn’:
gio/gdesktopappinfo.c:2804:21: error: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’
 2804 |       for (i = 0; i < G_N_ELEMENTS (wrapper_argv); i++)
      |                     ^
2021-01-12 19:25:26 +01:00
Emmanuel Fleury
04a05ff016 Fix signedness warning in gio/gdesktopappinfo.c:desktop_file_dirs_lock()
gio/gdesktopappinfo.c: In function ‘desktop_file_dirs_lock’:
gio/gdesktopappinfo.c:1564:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘guint’ {aka ‘unsigned int’}
 1564 |   for (i = 0; i < desktop_file_dirs->len; i++)
      |                 ^
2021-01-12 19:16:56 +01:00
Emmanuel Fleury
ce2446ddfd Fix signedness warning in gio/gdesktopappinfo.c:array_contains()
gio/gdesktopappinfo.c: In function ‘array_contains’:
gio/gdesktopappinfo.c:1193:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘guint’ {aka ‘unsigned int’}
 1193 |   for (i = 0; i < array->len; i++)
      |                 ^
2021-01-12 19:16:56 +01:00
Emmanuel Fleury
5940d51167 Fix signedness warning in gio/gdesktopappinfo.c:desktop_file_dir_unindexed_setup_search()
gio/gdesktopappinfo.c: In function ‘desktop_file_dir_unindexed_setup_search’:
gio/gdesktopappinfo.c:1114:25: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘long unsigned int’
 1114 |           for (i = 0; i < G_N_ELEMENTS (desktop_key_match_category); i++)
      |                         ^
2021-01-12 19:16:56 +01:00
Krzesimir Nowak
cdf0a50c69 gdesktopappinfo: Fix validation of XDG_CURRENT_DESKTOP
Split out XDG_CURRENT_DESKTOP handling to a separate function and make
sure that it drops all the invalid entries properly. Earlier a bad
entry could slip through the checks by sitting just after another bad
entry, like in env being set to `invalid1!:invalid2!`, where
`invalid2!` could slip the checks.
2021-01-09 15:39:09 +01:00
Philip Withnall
45d01e5aa9 gdesktopappinfo: Validate XDG_CURRENT_DESKTOP before using it
Its components are used to build filenames, so if the value of
`XDG_CURRENT_DESKTOP` comes from an untrusted caller (as can happen in
setuid programs), using it unvalidated may be unsafe.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #2168
2021-01-07 15:02:25 +00:00
Sebastian Dröge
705a59a315 gio: Add missing nullable annotations 2020-11-11 13:15:21 +02:00
Philip Withnall
648986a290 glib: Avoid redefining GLIB_DISABLE_DEPRECATION_WARNINGS
It may be defined by the environment (we document that as being allowed)
— if so, individual files should not try to redefine it, as that causes
a preprocessor warning.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-07-27 15:41:09 +01:00
Philip Withnall
3b6460b94c glib: Use g_file_set_contents_full() throughout GLib and GIO
Where applicable. Where the current use of `g_file_set_contents()` seems
the most appropriate, leave that in place.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #1302
2020-07-26 21:37:46 +01:00
Felix Riemann
88fe78137d gdesktopappinfo: Fix unnecessarily copied and leaked URI list
When an app is spawned using g_desktop_app_info_launch_uris_with_spawn
it will expand the various token in the app's commandline with the
URIs of the files to open. The expand_macro() function that is used for
this advances the pointer to the URI list to show up to which entries
it used.

To not loose the pointer to the list head a duplicate of the URI list
was actually passed to expand_macro(). However, it's not necessary to
create a copy of the URI list for that as expand_macro() will only
change which element the pointer will point to.

This behaviour actually caused the duplicated list to be leaked as the
the list pointer is NULL once all URIs are used up by expand_macro()
and thus nothing was freed at the end of the function.
2020-07-04 20:20:42 +02:00
Philip Withnall
00bfb3ab44 tree: Fix various typos and outdated terminology
This was mostly machine generated with the following command:
```
codespell \
    --builtin clear,rare,usage \
    --skip './po/*' --skip './.git/*' --skip './NEWS*' \
    --write-changes .
```
using the latest git version of `codespell` as per [these
instructions](https://github.com/codespell-project/codespell#user-content-updating).

Then I manually checked each change using `git add -p`, made a few
manual fixups and dropped a load of incorrect changes.

There are still some outdated or loaded terms used in GLib, mostly to do
with git branch terminology. They will need to be changed later as part
of a wider migration of git terminology.

If I’ve missed anything, please file an issue!

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-06-12 15:01:08 +01:00
Corentin Noël
0663a9bd56 gdesktopappinfo: Add several nullable annotation to GAppInfo getters
Some functions can return a NULL GAppInfo when the conditions given as arguments are not met.
2020-05-07 10:30:39 +01:00
Philip Withnall
5314a20389 gdesktopappinfo: Note that search results are not filtered
Mention in the documentation that (presumably for performance reasons)
the search results from `g_desktop_app_info_search()` are not filtered
by executable presence or hidden attribute.

Perhaps they should be in future, but for now we should at least
document it.

Spotted by Will Thompson.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-05-05 09:29:50 +01:00
Philip Withnall
2b533ca99a gdesktopappinfo: Use sh rather than gio-launch-desktop
There were some problems about where to install `gio-launch-desktop` to
support multiarch systems without circular dependencies. Simon McVittie
suggested that, actually, given the current set of platforms supported
by `GDesktopAppInfo` (they’re all POSIX), we could just use `sh`.

That simplifies things nicely. `gio-launch-desktop` can always be
resurrected (and the multiarch debate continued and resolved) if needed
in future.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #1633
2020-02-14 18:09:18 +00:00
Philip Withnall
5b07fc98e0 gdesktopappinfo: Cancel file monitor when resetting a DesktopFileDir
It’s not enough to unref the monitor, since the GLib worker thread might
still hold a reference to it.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #1903
2019-10-11 22:31:24 +01:00
Philip Withnall
bffe058550 gdesktopappinfo: Allocate DesktopFileDir structs dynamically
`DesktopFileDir` pointers are passed around between threads: they are
initially created on the main thread, but a pointer to them is passed to
the GLib worker thread in the file monitor callback
(`desktop_file_dir_changed()`).

Accordingly, the `DesktopFileDir` objects either have to be
 (1) immutable;
 (2) reference counted; or
 (3) synchronised between the two threads
to avoid one of them being used by one thread after being freed on
another. Option (1) changed with commit 99bc33b6 and is no longer an
option. Option (3) would mean blocking the main thread on the worker
thread, which would be hard to achieve and is against the point of
having a worker thread. So that leaves option (2), which is implemented
here.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #1903
2019-10-11 22:31:24 +01:00
Philip Withnall
d55f6fb5fe gdesktopappinfo: Update calling convention for gnome-terminal
For several years now (I haven’t looked up the exact date),
`gnome-terminal` has preferred being called as `gnome-terminal
--terminal-args -- /some/other/program --its-args` rather than as
`gnome-terminal --terminal-args -x /some/other/program --its-args`.
Since 2017 it has warned about uses of `-x` (see
ad4edbd118).

So we should change our calling convention for it.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-06-28 13:05:07 +01:00
Philip Withnall
40ff475977 Annotate various types and macros as deprecated
These have all been documented as deprecated for a long time, but we’ve
never had a way to programmatically mark them as deprecated. Do that
now.

This is based on the list of deprecations from the reverted commit
80fcb1bc2.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #638
2019-05-30 10:39:11 +01:00
Philip Withnall
70c8a7ef8d gdesktopappinfo: Improve documentation formatting slightly
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-05-30 10:38:45 +01:00
Philip Withnall
9bfd7e2a9d gdesktopappinfo: Add deprecation version to GDesktopAppInfoLookup
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-05-30 10:38:45 +01:00
Colomban Wendling
292cb2cb1b gdesktopappinfo: Add support for MATE and Xfce4 terminals
Add support for mate-terminal and xfce4-terminal with higher precedence
over xterm as it's likely people that have those want to use them.
They both use the gnome-terminal `-x` switch instead of xterm's `-e`.
2019-04-25 16:10:49 +02:00
Philip Withnall
d55ed6755e gdesktopappinfo: Fix an overly-specific ‘Since’ documentation line
This was causing gtk-doc to try and link to an API deprecation index
which doesn’t exist.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-03-15 11:09:32 +00:00
Ondrej Holy
cec5778cad gappinfo: Add launch_uris_async() and launch_uris_finish() vfuncs
The g_app_info_launch_uris_async() and g_app_info_launch_uris_finish()
functions are crucial to fix g_app_info_launch_default_for_uri_async()
to be really asynchronous.

This patch also adds GDesktopAppInfo implementation of that vfuncs.
The implementation may still use some synchronous calls to local MIME DB.

https://gitlab.gnome.org/GNOME/glib/issues/1347
https://gitlab.gnome.org/GNOME/glib/issues/1249
2019-01-28 16:42:34 +01:00
Philip Withnall
99bc33b632 gdesktopappinfo: Reload the desktop dirs if the $XDG_CONFIG_HOME changes
This causes the desktop directory cache to be correctly reloaded between
unit tests if G_TEST_OPTION_ISOLATE_DIRS is in use.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-12-17 17:16:04 +00:00
Philip Withnall
3f2a5ee1cc docs: Fix ‘Since’ line for new function to reference stable release
We only build API ‘since’ indexes for stable releases, so 2.59 needs to
be rounded up to 2.60.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-11-23 13:30:33 +00:00
Will Thompson
5ca9eca632 gdesktopappinfo: add get_string_list() function
The X-Flatpak-RenamedFrom key is used in .desktop files to identify past
names for the desktop file. It is defined to be a list of strings.
However, there was previously no correct way to retrieve a list of
strings from the GKeyFile wrapped by GDesktopAppInfo, short of
re-parsing the file with GKeyFile.

Note that doing something like:

    g_strsplit (g_desktop_app_info_get_string (...), ";", -1)

is not correct: the raw value "a\;b;" represents the one-element list
["a;b"], but g_key_file_get_string() rejects the sequence "\;", and so
g_desktop_app_info_get_string() returns NULL in this case. (Of course, a
.desktop file with a semicolon in its name is a pathological case.)

Add g_desktop_app_info_get_string_list(), a trivial wrapper around
g_key_file_get_string_list(), similar to g_desktop_app_info_get_string()
and co.

The change from g_key_file_free() to g_key_file_unref() in the test is
needed because g_key_file_free() clears the contents of the keyfile.
This is fine for all the fields which are eagerly loaded and copied into
GDesktopAppInfo, but not when we want to access arbitrary stuff from the
keyfile.
2018-10-01 20:03:55 +01:00
Philip Withnall
6db2412b41 gdesktopappinfo: Fix a minor command line leak
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-06-27 15:01:09 +01:00
Daniel Drake
156d009696 gdesktopappinfo: add g_desktop_app_info_launch_uris_as_manager_with_fds variant
Add an app-launching function which allows standard file descriptors
to be passed to the child process.

This will be used by gnome-shell to pass systemd journal descriptors
as stdout/stderr. gnome-shell's child_setup function can then be
eliminated, which will enable use of the posix_spawn optimized
gspawn codepath for desktop app launching.
2018-06-21 11:44:59 -05:00
Daniel Drake
742efe6232 gdesktopappinfo: enable fast posix_spawn gspawn codepath
In order to use the new posix_spawn gspawn codepath, for more robust
app launching when available memory is low, we need to meet some
conditions.

child_setup needs to be NULL for this optimization to work, so drop
the internal child_setup that is used here. Replace it with a lightweight
wrapper binary (gio-launch-desktop) that sets GIO_LAUNCHED_DESKTOP_FILE_PID
before executing the app.

Adjust PATH for gio tests so that it can execute the new binary from the
build directory.
2018-06-21 11:44:28 -05:00
Tomasz Miąsko
9d40f64960 gdesktopappinfo: Mark GDesktopAppInfo constructors as nullable.
GDesktopAppInfo constructors return NULL on error without having
separate **GError parameter.

https://bugzilla.gnome.org/show_bug.cgi?id=795152
2018-05-04 17:13:39 +01:00
Florian Müllner
1e2579da2c gdesktopappinfo: Filter out some binary names in search
The executable name can be a useful bit of information to match on in
searches where it differs from the name (for example because the latter
is localised), but will produce surprising results where the real appli-
cation is executed by a shared binary (for example interpretors like
gjs or python, or sandboxes like flatpak).

Address this by adding a blacklist of binary names that are ignored
in search.

https://bugzilla.gnome.org/show_bug.cgi?id=795488
2018-04-24 13:11:00 +02:00
Emmanuele Bassi
07731ff3fc Do not use g_autofree
The g_auto macros are available only with GCC-compatible compilers on
Unix, but having __attribute__((cleanup)) is not part of our toolchain
requirements, so we shouldn't use it — even if we are building on
Unix-compatible systems.

https://bugzilla.gnome.org/show_bug.cgi?id=794732
2018-03-28 11:49:59 +01:00
Florian Müllner
a55bfeee41 gdesktopappinfo: Add g_desktop_app_info_get_locale_string()
Custom desktop file fields may be translated, but there is currently
no non-hacky way to look up the localized value; fill get gap with
a small wrapper around g_key_file_get_locale_string().

https://bugzilla.gnome.org/show_bug.cgi?id=779413
2018-01-08 16:28:34 +01:00
Mario Sanchez Prada
d501bd0dbe gdesktopappinfo: Gracefully handle NULL URIs when passed to expand_macro()
If an application calls g_app_info_launch_uris() with a GList that includes
NULL values in some of its data members, and GIO ends up internally calling
g_desktop_app_info_launch_uris_with_spawn() for whatever reason (e.g. no
D-Bus session available), expand_macro() will crash due to the invalid data.

As this is considered a programmer error, use g_return_val_if_fail() in those
situations to prevent the crash from happening, but printing a warning anyway.

https://bugzilla.gnome.org/show_bug.cgi?id=791337
2017-12-08 13:47:23 +00:00
Mario Sanchez Prada
fbed9c8b85 gdesktopappinfo: Pass a copy of the URIs list to expand_application_parameters()
This list will be modified in-place when calling expand_macro(), so pass a copy
of it instead the original pointer, that is supposed to be an input parameter
only for g_desktop_app_info_launch_uris_with_spawn().

https://bugzilla.gnome.org/show_bug.cgi?id=791337
2017-12-08 13:47:23 +00:00
Philip Withnall
181eb900d5 gdesktopappinfo: Downgrade a warning to a debug message
Bug #786580 triggered this warning to show up in the appinfo tests if
run on a machine where no terminal except xterm is installed (for
example, a build machine). Since we didn’t warn before if xterm but no
other terminals were installed, it seems reasonable to downgrade the
warning to a debug message.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://bugzilla.gnome.org/show_bug.cgi?id=790914
2017-11-28 14:12:40 +00:00
Christoph Reiter
fed574a0c8 introspection: Add more filename type annotations for strings which can contain filenames
This continues the changes done in https://bugzilla.gnome.org/show_bug.cgi?id=767245

This makes it possible to pass Python path types as process arguments and env vars
in PyGObject and and makes it clear that the values are not strictly utf-8 and need
to be validated/converted first.

https://bugzilla.gnome.org/show_bug.cgi?id=788863
2017-10-26 18:51:51 +02:00
Mikhail Zabaluev
48cf1d32c6 Fix up closure annotations for GSpawnChildSetupFunc
https://bugzilla.gnome.org/show_bug.cgi?id=738176
2017-09-11 21:07:08 +01:00
Cj Malone
926db3174a gdesktopappinfo.c: Drop disregarded xterm check
https://bugzilla.gnome.org/show_bug.cgi?id=786580
2017-08-23 23:55:43 +01:00
Matthias Clasen
d3b4f7c9f6 Make dbus activation sandbox-aware
When we call org.freedesktop.Application.Open to activate
an application and pass file uris, the application may not
be able to see the files due to a flatpak sandbox.

Flatpak puts the flatpak app-id in the  X-Flatpak key in
desktop files that it exports, so we can easily recognize
applications that may be affected by this.

In this case, call the document portal to export the files
and pass the resulting uri's instead of the original ones.

https://bugzilla.gnome.org/show_bug.cgi?id=783130
2017-05-29 17:57:39 -04:00
Sébastien Wilmet
3bf4a720c3 gio/: LGPLv2+ -> LGPLv2.1+
Sub-directories inside gio/ already processed in a previous commit:
- fam/
- gdbus-2.0/ (which contains only codegen/)
- gvdb/
- inotify/
- tests/
- win32/
- xdgmime/

Other sub-directories inside gio/:
- completion/: no license headers
- kqueue/: not LGPL, BSD-style license

https://bugzilla.gnome.org/show_bug.cgi?id=776504
2017-05-29 19:53:34 +02:00
Simon McVittie
e5ed410c8c Avoid calling Standard C string/array functions with NULL arguments
glibc string.h declares memcpy() with attribute(nonnull(1,2)), causing
calls with NULL arguments to be treated as undefined behaviour.
This is consistent with ISO C99 and C11, which state that passing 0
to string functions as an array length does not remove the requirement
that the pointer to the array is a valid pointer.
gcc -fsanitize=undefined catches this while running OSTree's test suite.

Similarly, running the GLib test suite reports similar issues for
qsort(), memmove(), memcmp().

Signed-off-by: Simon McVittie <smcv@debian.org>
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=775510
Reviewed-by: Colin Walters
2016-12-02 19:10:39 +00:00
Christian Hergert
18a33f72db introspection: use (nullable) or (optional) instead of (allow-none)
If we have an input parameter (or return value) we need to use (nullable).
However, if it is an (inout) or (out) parameter, (optional) is sufficient.

It looks like (nullable) could be used for everything according to the
Annotation documentation, but (optional) is more specific.
2016-11-22 14:14:37 -08:00