Commit Graph

22760 Commits

Author SHA1 Message Date
Norbert Pocs
a879c46a39 gdbus: Add FD support for gdbus call
Gdbus call could not take file handle (parameter 'h') as a parameter.

Original patch from Tim Waugh <twaugh@redhat.com>.

Fixes: #961
2020-11-06 17:19:27 +00:00
Patrick Griffis
482e10d3bb guri: Normalize uri segments if they are encoded
This changes it so when a segment is encoded it will be
normalized at parse time which ensures its valid and
it can more easily be compared with other uris.
2020-11-04 10:55:04 -06:00
Emmanuele Bassi
63dfceedd2 Merge branch 'scanner-undefined-behaviour' into 'master'
gscanner: Avoid undefined behaviour copying between union members

See merge request GNOME/glib!1737
2020-11-03 17:25:04 +00:00
Philip Withnall
add3be2086 gscanner: Avoid undefined behaviour copying between union members
It’s technically undefined behaviour in C to copy between two
potentially-overlapping regions of memory (just like it is when calling
`memcpy()`). This can easily happen with union members; and the ones in
`GScanner` in particular.

Fix that by copying through an intermediate variable.

Coverity CID: #1427317, 1427340

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-11-03 16:59:36 +00:00
Philip Withnall
e1e32e9b0b Merge branch 'wip/carlosg/shared-hidden-cache-timeout' into 'master'
glocalfileinfo: Use a single timeout source at a time for hidden file cache

See merge request GNOME/glib!1734
2020-11-03 15:09:44 +00:00
Carlos Garnacho
c1e0e6a055 glocalfileinfo: Use a single timeout source at a time for hidden file cache
As hidden file caches currently work, every look up on a directory caches
its .hidden file contents, and sets a 5s timeout to prune the directory
from the cache.

This creates a problem for usecases like Tracker Miners, which is in the
business of inspecting as many files as possible from as many directories
as possible in the shortest time possible. One timeout is created for each
directory, which possibly means gobbling thousands of entries in the hidden
file cache. This adds as many GSources to the glib worker thread, with the
involved CPU overhead in iterating those in its main context.

To fix this, use a unique timeout that will keep running until the cache
is empty. This will keep the overhead constant with many files/folders
being queried.
2020-11-03 14:16:36 +01:00
Philip Withnall
5719d2cde6 Merge branch 'wip/otte/interface-types' into 'master'
Improve support for interface types

See merge request GNOME/glib!1251
2020-11-02 18:07:29 +00:00
Matthias Clasen
0b1f909691 Add a test for signals returning interface types
Add a test for a signal returning interface types, using
the generic marshaller. This will hopefully exercise newly
added code in value_from_ffi_type().
2020-11-02 17:36:18 +00:00
Matthias Clasen
52357aac44 Add a binding test involving interfaces
This tests the new functionality that
g_type_interface_instantiable_prerequisite
was added for.

Before the changes, this fails with
GObject-WARNING **: Unable to convert a value of type \
                    GObject to a value of type Foo

We do the same test with g_object_bind_property_with_closures
as well, to exercise g_cclosure_marshal_generic.
2020-11-02 17:36:18 +00:00
Benjamin Otte
458e3b7a84 value: Allow automatic transforms to/from interfaces
Use the new g_type_interface_instantiable_prerequisite() to check
compatibility for transform functions.

In particular, this allows interfaces (in my case GDK_TYPE_PAINTABLE) to
be transformed to/from any GObject type (in my case G_TYPE_OBJECT) using
the transform function registered to transform between any 2 objects
(g_value_object_transform_value() does a type check and uses NULL if the
types don't match).

And this in turn allows be to g_object_bind_property() a gobject-typed
generic property (GtkListItem::item) to a GtkImage::paintable.

Tests for the new functionality are included.
2020-11-02 17:36:18 +00:00
Benjamin Otte
3f2a8d53f0 closure: Support generic marshals for interface returns
Use the newly added g_type_interface_instantiable_prerequisite() to
allow closure return values being interfaces by looking up the
instantiable type for the interface and using its GValue accessors.
2020-11-02 17:36:18 +00:00
Benjamin Otte
98f0a5a7da gtype: Add g_type_interface_instantiatable_prerequisite()
This function returns the most specific instantiatable type
that is a prerequisite for a given interface.

This type is necessary in particular when dealing with GValues
because a GValue contains an instance of a type.

This commit includes tests for the new API.
2020-11-02 17:36:18 +00:00
Benjamin Otte
e1b5afb7c0 gtype: Fix typo in API comment 2020-11-02 17:36:18 +00:00
Benjamin Otte
1f6c73747e Suggest braces around empty body in ‘if’ statements 2020-11-02 17:36:18 +00:00
Philip Withnall
4f2b1e250d gobject: Standardise on the term ‘instantiatable’
Rather than using a mixture of ‘instantiable’ and ‘instantiatable’
everywhere, standardise on the term which is already in the public API.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-11-02 17:22:01 +00:00
Philip Withnall
4f7c6e1ec8 gdbusauthmechanismsha1: Don’t create keyring dir when running as setuid
Continue to allow overriding the keyring dir, but don’t automatically
create it when running as root.

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

Coverity CID: #1432485
2020-11-02 12:23:50 +00:00
Philip Withnall
86b910e6b1 Merge branch 'issue-2236' into 'master'
Include generated files and documentation in the GIO reference

Closes #2236

See merge request GNOME/glib!1730
2020-11-02 11:45:26 +00:00
Philip Withnall
f2e347d93a Merge branch 'wip/smcv/fileutils-test-as-root' into 'master'
glib/tests/fileutils: Fix expectations when running as root

See merge request GNOME/glib!1724
2020-11-02 11:18:49 +00:00
Philip Withnall
7fd0d1c762 Merge branch 'wip/smcv/assert-no-errno' into 'master'
Make more use of g_assert_no_errno()

See merge request GNOME/glib!1731
2020-11-02 11:16:25 +00:00
Simon McVittie
087fdf86a6 glib/tests/fileutils: Fix expectations when running as root
This test asserts that g_file_set_contents_full() will fail when used
on a read-only file, but processes with CAP_DAC_OVERRIDE on Linux or
uid 0 on traditional Unix can and do ignore DAC permissions.
See also #2027, #2028.

Bug-Debian: https://bugs.debian.org/973271
Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-10-31 12:26:44 +00:00
Simon McVittie
f53aaeac9f gio/tests/gsettings: Assert that temporary directory ends up empty
If there are stray files left over, g_rmdir() will fail with ENOTEMPTY.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-10-31 12:26:01 +00:00
Simon McVittie
782c1b424e gio/tests/gsettings: Assert that g_chmod succeeds
Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-10-31 12:24:59 +00:00
Simon McVittie
3f9f7da0f1 gio/tests/gsettings: Use g_assert_no_errno()
Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-10-31 12:24:22 +00:00
Simon McVittie
3468369625 gio/tests/appmonitor: Use g_assert_no_errno()
Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-10-31 12:24:05 +00:00
Simon McVittie
b3b4ad4f94 gio/tests/live-g-file: Use g_assert_no_errno()
Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-10-31 12:20:53 +00:00
Simon McVittie
c63da52bec glib/tests/fileutils: Make more use of g_assert_no_errno()
Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-10-31 12:20:32 +00:00
Emmanuele Bassi
e1744603d8 Build gdbus-objectmanager-example docs unconditionally
The GIO reference documentation links to that documentation, so we
cannot only build it when the installed tests are enabled.
2020-10-30 16:42:53 +00:00
Emmanuele Bassi
2993bb8275 docs: Fix xinclude directives
For legacy reasons, Meson's gtk-doc helper script launches the
gtkdoc-mkhtml tool in the `html` directory under the build root. This
means that all paths must be relative to that location.
2020-10-30 16:41:07 +00:00
Emmanuele Bassi
db2cb16e20 docs: Add missing annotation glossary
Without the glossary, gtk-doc will emit warnings for every introspection
annotation it finds.
2020-10-30 16:39:10 +00:00
Philip Withnall
b04a359d1e Merge branch 'mcatanzaro/#2233' into 'master'
gsocketclient: fix crash when async connection step fails

Closes #2233

See merge request GNOME/glib!1728
2020-10-28 16:04:22 +00:00
Michael Catanzaro
c2b8fa8a34 gsocketclient: fix crash when async connection step fails
This is a regression from !1686. The tmp_error is no longer valid after
it is "considered" and cannot be used at this point. We should print the
error earlier instead.

Fixes #2233
2020-10-28 10:43:43 -05:00
Philip Withnall
35ffbf953d Merge branch 'wip/smcv/big-dbus-write-with-fds' into 'master'
gdbus: Cope with sending fds in a message that takes multiple writes

Closes #2074

See merge request GNOME/glib!1725
2020-10-28 13:12:19 +00:00
Philip Withnall
5b0a7ed046 Merge branch 'wip/smcv/dbus-fd-convention' into 'master'
gdbus: Document the intended semantics of handles and fds

See merge request GNOME/glib!1726
2020-10-28 12:40:28 +00:00
Simon McVittie
e5cee9ce5a gio/tests/gdbus-peer: Exercise fds attached to a large message
This incidentally also exercises the intended pattern for sending fds in
a D-Bus message: the fd list is meant to contain exactly those fds that
are referenced by a handle (type 'h') in the body of the message, with
numeric handle value n corresponding to g_unix_fd_list_peek_fds(...)[n].

Being able to send and receive file descriptors that are not referenced by
a handle (as in OpenFile here) is a quirk of the GDBus API, and while it's
entirely possible in the wire protocol, other D-Bus implementations like
libdbus and sd-bus typically don't provide APIs that make this possible.

Reproduces: https://gitlab.gnome.org/GNOME/glib/-/issues/2074
Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-10-28 12:03:59 +00:00
Simon McVittie
fc1f4969bf gdbus: Document the intended semantics of handles and fds
In the D-Bus wire protocol, the handle type (G_VARIANT_TYPE_HANDLE, h)
is intended to be an index/pointer into the implementation's closest
equivalent of GUnixFDList: its numeric value has no semantic meaning
(in the same way that the numeric values of pointers have no semantic
meaning), but a handle with value n acts as a reference to the nth fd
in the fd list.

GDBus provides a fairly direct mapping from the wire protocol to the
C API, which makes it technically possible to attach and use fds
without ever referring to them in the message body, and some
GLib-centric D-Bus APIs rely on this.

However, the other major implementations of D-Bus (libdbus and sd-bus)
transparently replace file descriptors with handles when building
messages, and transparently replace handles with file descriptors when
parsing messages. This means they cannot implement D-Bus APIs that do
not follow the conventional meaning of handles as indexes/pointers into
an equivalent of GUnixFDList.

For interoperability, we should encourage D-Bus API designers to follow
the convention, even though code written against GDBus doesn't strictly
need to do so.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-10-28 11:52:22 +00:00
Simon McVittie
70279f8446 gdbus: Cope with sending fds in a message that takes multiple writes
Suppose we are sending a 5K message with fds (so data->blob points
to 5K of data, data->blob_size is 5K, and fd_list is non-null), but
the kernel is only accepting up to 4K with each sendmsg().

The first time we get into write_message_continue_writing(),
data->total_written will be 0. We will try to write the entire message,
plus the attached file descriptors; or if the stream doesn't support
fd-passing (not a socket), we need to fail with
"Tried sending a file descriptor on unsupported stream".

Because the kernel didn't accept the entire message, we come back in.
This time, we won't enter the Unix-specific block that involves sending
fds, because now data->total_written is 4K, and it would be wrong to try
to attach the same fds again. However, we also need to avoid failing
with "Tried sending a file descriptor on unsupported stream" in this
case. We just want to write out the data of the rest of the message,
starting from (blob + total_written) (in this exaple, the last 1K).

Resolves: https://gitlab.gnome.org/GNOME/glib/-/issues/2074
Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-10-28 11:06:52 +00:00
Philip Withnall
2d008e4645 Merge branch 'mcatanzaro/#2221' into 'master'
Fix race in socketclient-slow test

Closes #2221

See merge request GNOME/glib!1711
2020-10-26 15:40:49 +00:00
Sebastian Dröge
4926948aa9 Merge branch 'app-info-docs' into 'master'
gio: Fix some remaining DocBook syntax in a documentation comment

See merge request GNOME/glib!1701
2020-10-26 15:20:03 +00:00
Sebastian Dröge
98f2607006 Merge branch 'dbus-typos' into 'master'
gio: Fix various typos of the name ‘D-Bus’

See merge request GNOME/glib!1722
2020-10-26 15:14:46 +00:00
Philip Withnall
159a9c215a gio: Fix various typos of the name ‘D-Bus’
This introduces no functional changes.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-10-26 14:28:15 +00:00
Michael Catanzaro
1d28fd530c Fix race in socketclient-slow test
This test ensures that g_socket_client_connect_to_host_async() fails if
it is cancelled, but it's not cancelled until after 1 millisecond. Our
CI testers are hitting that race window, and Milan is able to reproduce
the crash locally as well. Switching it from 1ms to 0ms is enough for
Milan to avoid the crash, but not enough for our CI, so let's move the
cancellation to a GSocketClientEvent callback where the timing is
completely deterministic.

Hopefully fixes #2221
2020-10-26 14:18:06 +00:00
Philip Withnall
ec222422c0 Merge branch 'g_main_context_check_skipping_pollrec_updates' into 'master'
gmain: g_main_context_check() can skip updating polled FD sources

Closes #1592

See merge request GNOME/glib!1713
2020-10-26 14:12:04 +00:00
Claudio Saavedra
96ccf06d3d gmain: g_main_context_check() can skip updating polled FD sources
If there is a file descriptor source that has a lower priority
than the one for sources that are going to be dispatched,
all subsequent file descriptor sources (internally sorted by
file descriptor identifier) do not get an update in their GPollRec
and later on wrong sources can be dispatched.

Fix this by first finding the first GPollRec that matches the current
GPollFD, instead of relying on it to be the current one. At
the same time, document the assumptions about the ordering of the
file descriptor records and array and make explicit in the documentation
that the array needs to be passed to g_main_context_check() as it was
received from g_main_context_query().

Added a new test that reproduces the bug by creating two file
descriptor sources and an idle one. Since the first
file descriptor created has a lower identifier and a low priority,
the second one is not dispatched even when it has the same, higher,
priority as the idle source. After fixing this bug, both
higher priority sources are dispatched as expected.

While this patch was written independently, a similar fix for this
bug was first submitted by Eugene M in GNOME/glib!562. Having a
second fix that basically does the same is a reassurance that we
are in the right here.

Fixes #1592
2020-10-26 13:08:01 +00:00
Sebastian Dröge
5339082bbb Merge branch 'improve-g_strrstr_len-docstring' into 'master'
Improve docstrings of 'g_strstr_len' and 'g_strrstr_len'

Closes #2223

See merge request GNOME/glib!1697
2020-10-26 10:51:21 +00:00
Reuben Thomas
3b10a07126 Improve docstrings of 'g_strstr_len' and 'g_strrstr_len' (fixes: #2223)
glib/gstrfuncs.c: clarify the functions’ ability to process
non-nul-terminated strings with a negative 'haystack_length' argument.
2020-10-26 09:26:03 +00:00
Philip Withnall
8f0b968cd1 2.67.0
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-10-23 16:38:06 +01:00
Emmanuele Bassi
2d812f1ee1 Merge branch 'clang-fixes' into 'master'
gtrace: Add G_GNUC_PRINTF annotation

See merge request GNOME/glib!1718
2020-10-23 14:42:49 +00:00
Emmanuele Bassi
51f30ccb85 Merge branch 'wip/pwithnall/credentials-fix' into 'master'
gmacros: Use __typeof__ when compiling with Clang

See merge request GNOME/glib!1714
2020-10-23 11:41:24 +00:00
Philip Withnall
30782c4c3c gtrace: Add G_GNUC_PRINTF annotation
This allows compilers to check the format placeholders properly. It
fixes compilation on clang, which gives a warning about untrusted
strings being passed on to subsequent functions which require format
placeholders.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-10-23 12:07:02 +01:00
Philip Withnall
dce24dc449 gmacros: Use __typeof__ when compiling with Clang
Just like gcc, clang has supported `__typeof__` for a long time, so
allow it to be used. This fixes compilation of `gio/gcredentials.c` on
macOS (which uses clang by default).

I don’t know which version clang started supporting `__typeof__` in, so
there’s no version check. One can be added in future if there are
problems.

This fixes commit 5b2bee3f53.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-10-23 12:04:04 +01:00