23309 Commits

Author SHA1 Message Date
Michael Catanzaro
3e1d6e9e58 gspawn: add new error message for open() failures
Reporting these as dup2() failures is bogus.
2022-01-27 10:14:02 -06:00
Michael Catanzaro
cbb72948f6 gspawn: Check from errors from safe_dup2() and dupfd_cloexec()
Although unlikely, these functions can fail, e.g. if we run out of file
descriptors. Check for errors to improve robustness. This is especially
important now that I changed our use of dupfd_cloexec() to avoid
returning fds smaller than the largest fd in target_fds. An application
that attempts to remap to the highest-allowed fd value deserves at least
some sort of attempt at error reporting, not silent failure.
2022-01-27 10:14:02 -06:00
Michael Catanzaro
80c105531d gsubprocess: ensure we test fd remapping on the posix_spawn() codepath
We should run test_pass_fd twice, once using gspawn's fork/exec codepath
and once attempting to use its posix_spawn() codepath. There's no
guarantee we'll actually get the posix_spawn() codepath, but it works
for now on Linux.

For good measure, run it a third time with no flags at all.

This causes the test to fail if I separately break the fd remapping
implementation. Without this, we fail to test fd remapping on the
posix_spawn() codepath.
2022-01-27 10:14:02 -06:00
Michael Catanzaro
59da3753d1 gspawn: Implement fd remapping for posix_spawn codepath
This means that GSubprocess will (sometimes) be able to use the
optimized posix_spawn codepath instead of having to fall back to
fork/exec.
2022-01-27 10:14:02 -06:00
Michael Catanzaro
87257f1f46 gspawn: fix fd remapping conflation issue
We currently dup all source fds to avoid possible conflation with the
target fds, but fail to consider that the result of a dup might itself
conflict with one of the target fds. Solve this the easy way by duping
all source_fds to values that are greater than the largest fd in
target_fds.

Fixes #2503
2022-01-27 10:14:02 -06:00
Michael Catanzaro
dc4e25832c gspawn: fix hangs when duping child_err_report_fd
In case child_err_report_fd conflicts with one of the target_fds, the
code here is careful to dup child_err_report_fd in order to avoid
conflating the two. It was a good idea, but evidently was not tested,
because the newly-created fd is not created with CLOEXEC set. This means
it stays open in the child process, causing the parent to hang forever
waiting to read from the other end of the pipe. Oops!

The fix is simple: just set CLOEXEC. This removes our only usage of the
safe_dup() function, so it can be dropped.

Fixes #2506
2022-01-27 10:14:02 -06:00
Michael Catanzaro
1e1002469c gspawn: Improve error message when dup fails
This error message is no longer accurate now that we allow arbitrary fd
remapping.
2022-01-27 10:14:02 -06:00
Michael Catanzaro
ecde1b75d0 gspawn: use close_and_invalidate more 2022-01-27 10:14:02 -06:00
Simon McVittie
2f489d0b0f gversionmacros: Add version macros for GLib 2.70
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-01-27 10:13:58 -06:00
Benjamin Berg
eea325b4ef gdesktopappinfo: Add SourcePath= to transient systemd units
systemd allows setting a SourcePath= which shows the file that the unit
has been generated from. KDE is starting to set this and it seems like a
good idea, so do the same here.

See https://invent.kde.org/frameworks/kio/-/merge_requests/124
2022-01-27 10:13:52 -06:00
Benjamin Berg
35d24b2fa6 gdesktopappinfo: Handle task completion from spawn function
This allows delaying the return of the task until all dbus calls (in
particular the ones to setup the scope) have finished.

This fixes the behaviour of the previous commit which would not
correctly move the process into the scope if the application exited
right after the task returned.
2022-01-27 10:13:52 -06:00
Benjamin Berg
ee61859c22 gdesktopappinfo: Move launched applications into transient scope
Try to move the spawned executable into its own systemd scope. To avoid
possible race conditions and ensure proper accounting, we delay the
execution of the real command until after the DBus call to systemd has
finished.

From the two approaches we can take here, this is better in the sense
that we have a child that the API consumer can watch. API consumers
should not be doing this, however, gnome-session needs to watch children
during session startup. Until gnome-session is fixed, we will not be
able to change this.

The alternative approach is to delegate launching itself to systemd by
creating a transient .service unit instead. This is cleaner and has e.g.
the advantage that systemd will take care of log redirection and similar
issues.

Note that this patch is incomplete. The DBus call is done in a "fire and
forget" manner, which is fine in most cases, but means that "gio open"
will fail to move the child into the new scope as gio quits before the
DBus call finishes.
2022-01-27 10:13:52 -06:00
Benjamin Berg
6d0c0be031 tests: Iterate mainloop during launch test
When launching an application, we wait for the DBus response from
systemd before executing the binary. Because of this the main loop needs
to be iterated for spawning to completed and the file to be created.

Without this the test will time out if GLib was able to connect to the
session bus.
2022-01-27 10:13:52 -06:00
Goran Vidović
b3023ecc28 Update Croatian translation 2021-10-27 17:15:22 +00:00
Fabio Tomat
a413d98d62 Update Friulian translation 2021-09-25 18:13:16 +00:00
Philip Withnall
d99d7967a2 2.68.4
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2.68.4
2021-08-19 16:25:53 +01:00
Emmanuele Bassi
4e13a16029 Merge branch 'backport-2174-newline-glib-2-68' into 'glib-2-68'
Backport !2174 “data-to-c.py: generate new-line at the end of the file” to glib-2-68

See merge request GNOME/glib!2175
2021-08-19 15:21:54 +00:00
Philip Withnall
94ef9408f7 Merge branch 'glib-2-68-backport-g-win32-app-info-fixes' into 'glib-2-68'
Backport GWin32AppInfo fixes to glib-2-68

See merge request GNOME/glib!2220
2021-08-09 13:01:30 +00:00
Jonathan Boeing
ee94434632
gwin32packageparser: Fix read past end of buffer
g_win32_package_parser_enum_packages() reads beyond the end of a buffer
when doing a memcpy.  With app verifier enabled on Windows, it causes
the application to crash on startup.

This change limits the memcpy to the size of the source string.

Fixes: #2454
2021-08-09 14:13:15 +02:00
Руслан Ижбулатов
771a6e557a
GWin32AppInfo: Fix missing initialization
The value should be initialized to NULL before calling
g_win32_registry_key_get_value_w(), to ensure that cleanup
can be done unconditionally afterward.
2021-08-09 14:12:35 +02:00
Руслан Ижбулатов
d0ef6399d4
GWin32AppInfo: re-trigger registry watcher from the callback
To ensure that the watch is properly re-set every time, call
watch_keys() from the watch callback. Previously the watch was only
renewed after a data update was done in a worker thread, which made
no sense, since the update function was implemented in such a way
that it can (and should) be re-triggered on each key change, until
the changes stop coming, and that can only happen if we renew
the registry watcher right away.
2021-08-09 14:12:16 +02:00
Руслан Ижбулатов
22e5e428de
GWin32RegistryKey: ensure reqeueing works correctly
If a key watch is renewed from the key watch callback, it results
in the callback being NULL, since we clear it after we call it.

Rearrange the function to make sure that the changes done by the
callback function are preserved properly.
2021-08-09 14:12:07 +02:00
Руслан Ижбулатов
d6a734a44c
GWin32RegistryKey: Change STATUS_SUCCESS handling
This function can, in fact, return STATUS_SUCCESS. We shouldn't
assert that it doesn't.

For now interpret it just like STATUS_PENDING (i.e. APC will be called),
see how it goes (it isn't documented how the function behaves in this
case, we have to play it by ear).

Note that while we *can* use a better-documented RegNotifyChangeKeyValue() here,
it communicates back to us via event objects, which means that the registry
watcher would have to interact with the main loop directly and insert its
events (plural; one event per key) there. That would make the API more complicated.
Whereas the internal NT function communicates by calling an APC - we're good
as long as something somewhere puts the thread in alertable state.
2021-08-09 14:11:39 +02:00
Simon McVittie
6d9e493264 Merge branch 'backport-2208-string-replace-loop-glib-2-68' into 'glib-2-68'
Backport !2208 “g_string_replace: Don't replace empty string more than once per location” to glib-2-68

See merge request GNOME/glib!2209
2021-08-02 14:38:02 +00:00
Simon McVittie
4ce606878e g_string_replace: Document behaviour of zero-length match pattern
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-08-02 13:49:19 +01:00
Simon McVittie
79fa8db828 test_string_replace: Exercise zero-length replacements
Previously, these would have done 2**32 replacements, and the first one
would have consumed 6GB of memory in the process. They now match what
Python `str.replace()` does.

Reproduces: https://gitlab.gnome.org/GNOME/glib/-/issues/2452
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-08-02 13:49:19 +01:00
Simon McVittie
c70eb3f0aa g_string_replace: Don't replace empty string more than once per location
This matches the behaviour of Python `str.replace()`, and avoids carrying
out 2**32 replacements before n wraps around, which is almost certainly
not what we want.

Resolves: https://gitlab.gnome.org/GNOME/glib/-/issues/2452
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-08-02 13:49:19 +01:00
Simon McVittie
d587690534 test_string_replace: Expand test coverage
These are taken from another project (steam-runtime-tools) where I
implemented a similar replace method before realising that more recent
GLib versions had g_string_replace().

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-08-02 13:49:19 +01:00
Simon McVittie
5162562903 test_string_replace: Make the test table-driven
This makes it straightforward to add more test-cases.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-08-02 13:49:19 +01:00
Simon McVittie
3798abd5ea test_string_replace: Make types agree
g_string_replace() returns guint, not gint.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-08-02 13:49:19 +01:00
Michael Catanzaro
be84555c73 tests: Add missing return value check in string test
Coverity noticed that we were not testing the return value here. Good
Coverity!
2021-08-02 13:49:19 +01:00
Quentin PAGÈS
66a9196329 Update Occitan translation 2021-07-29 17:04:03 +00:00
Ondrej Holy
7cce6b5c7f Merge branch 'backport-2185-trash-fix-glib-2-68' into 'glib-2-68'
Backport !2185 “glocalfile: Fix the global trash dir detection” to glib-2-68

See merge request GNOME/glib!2186
2021-07-12 11:10:23 +00:00
markus
d7ba35360a glocalfile: Fix the global trash dir detection
The `g_file_trash` function fails with the `Unable to find or create trash
directory` error when the global `.Trash` directory exists. This is because
the commit 7f2af262 introduced the `gboolean success` variable to signalize
the detection of the trash folder, but didn't set it in all code branches.
Since for a time this variable was not initialized the bug wasn't visible
when the trash folder existed. The bug became effective after the `success`
variable was initialized with `FALSE` by the commit c983ded0. Let's explicitly
set the `success` variable in all branches to fix the global trash dir
detection.

Fixes: https://gitlab.gnome.org/GNOME/glib/-/issues/2439
2021-07-12 11:35:03 +01:00
Chao-Hsiung Liao
ebe1dbd860 Update Chinese (Taiwan) translation 2021-07-10 05:18:32 +00:00
Emmanuele Bassi
63e7864d1a Merge branch 'backport-2180-close_range-glib-2-68' into 'glib-2-68'
Backport !2180 “correctly use 3 parameters for close_range” to glib-2-68

See merge request GNOME/glib!2183
2021-07-09 12:27:02 +00:00
Khem Raj
6e59d21b27 correctly use 3 parameters for close_range
libc implementation has 3 parameter e.g.
https://www.freebsd.org/cgi/man.cgi?query=close_range&sektion=2&format=html

Signed-off-by: Khem Raj <raj.khem@gmail.com>
2021-07-09 12:24:56 +01:00
Michael Olbrich
0d236c39ee data-to-c.py: generate new-line at the end of the file
This is necessary when building glib with icecc. Icecc splits the build
process into two parts. The file is locally preprocessed with
-fdirectives-only to resolve any includes. This adds linemarkers to the
intermediate file. Without the new-line at the end of the file this:

 #include "gconstructor_as_data.h"
 #include "glib/glib-private.h"

Is turned into this:

const char gconstructor_code[] = "...";# 1 "glib/glib-private.h"
...

The result is a compile error:

In file included from ../glib/gio/glib-compile-resources.c:45:
gio/gconstructor_as_data.h:1: error: stray '#' in program
gio/gconstructor_as_data.h:1: error: expected identifier or '(' before numeric constant
In file included from ../glib/glib/glib-private.h:22,
                 from gio/gconstructor_as_data.h:2,
                 from ../glib/gio/glib-compile-resources.c:45:
../glib/glib/gwakeup.h:27:1: error: unknown type name 'GWakeup'
../glib/glib/gwakeup.h:28:42: error: unknown type name 'GWakeup'
../glib/glib/gwakeup.h:30:42: error: unknown type name 'GWakeup'
../glib/glib/gwakeup.h:32:42: error: unknown type name 'GWakeup'
../glib/glib/gwakeup.h:33:42: error: unknown type name 'GWakeup'
In file included from gio/gconstructor_as_data.h:2,
                 from ../glib/gio/glib-compile-resources.c:45:
../glib/glib/glib-private.h:98:3: error: unknown type name 'GWakeup'
../glib/glib/glib-private.h:99:58: error: unknown type name 'GWakeup'
../glib/glib/glib-private.h💯58: error: unknown type name 'GWakeup'
../glib/glib/glib-private.h:102:58: error: unknown type name 'GWakeup'
../glib/glib/glib-private.h:103:58: error: unknown type name 'GWakeup'
In file included from gio/gconstructor_as_data.h:2,
                 from ../glib/gio/glib-compile-resources.c:45:
../glib/glib/glib-private.h:164:53: warning: file "../glib/gio/glib-compile-resources.c" linemarker ignored due to incorrect nesting

To avoid this, generate gconstructor_as_data.h with a new-line at the end
of the file.

Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
2021-07-02 14:29:29 +01:00
Dingzhong Chen
d3dc7a8727 Update Chinese (China) translation 2021-06-24 23:17:59 +08:00
Simon McVittie
14a1eb525e Merge branch 'backport-2155-local-file-monitor-deadlock-glib-2-68' into 'glib-2-68'
Backport !2155 “glocalfilemonitor: Avoid a deadlock on finalization” to glib-2-68

See merge request GNOME/glib!2158
2021-06-15 18:40:11 +00:00
Philip Withnall
f49710b8aa glocalfilemonitor: Avoid a deadlock on finalization
If `g_file_monitor_source_dispatch()` drops the last reference to its
`GLocalFileMonitor`, a deadlock will occur, because disposing the
`GLocalFileMonitor` causes synchronous disposal of the
`GFileMonitorSource`, and hence an attempt to re-lock the already-locked
mutex in the `GFileMonitorSource`.

Fix that by dropping the reference to the `GLocalFileMonitor` after
unlocking.

Diagnosed by Ting-Wei Lan. The bug was originally introduced by me in
commit 592a13b483.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-06-15 13:26:23 +01:00
Philip Withnall
8249f624ed 2.68.3
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2.68.3
2021-06-10 19:55:29 +01:00
Emmanuele Bassi
b2c7013fbc Merge branch 'backport-2140-file-replace-contents-etags-glib-2-68' into 'glib-2-68'
Backport !2138 “glocalfileoutputstream: Fix ETag check when replacing through a symlink” to glib-2-68

See merge request GNOME/glib!2141
2021-06-10 12:49:34 +00:00
Philip Withnall
aa4aafe30b glocalfileoutputstream: Fix ETag check when replacing through a symlink
Since commit 87e19535fe, the ETag check when writing out a file through
a symlink (following the symlink) has been incorrectly using the ETag
value of the symlink, rather than the target file. This is incorrect
because the ETag should represent the file content, not its metadata or
links to it.

Fix that, and add a unit test.

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

Fixes: #2417
2021-06-07 14:28:03 +01:00
Emmanuele Bassi
bb6aa99e2c Merge branch 'backport-2128-inotify-leak-glib-2-68' into 'glib-2-68'
Backport !2128 “inotify: Fix a memory leak” to glib-2-68

See merge request GNOME/glib!2133
2021-06-07 13:23:41 +00:00
Emmanuele Bassi
599910dfea Merge branch 'backport-2136-tls-cert-parsing-glib-2-68' into 'glib-2-68'
Backport !2136 “tlscertificate: Avoid possible invalid read” to glib-2-68

See merge request GNOME/glib!2137
2021-06-07 13:22:58 +00:00
Peter Bloomfield
afd31d93b5 tests/tls-certificate: Add context to the new test
Add a comment to `pem_parser_no_sentinel()` to explain what it is
testing and how it works.
2021-06-07 09:38:37 +01:00
Peter Bloomfield
bdd36797fc tlscertificate: Avoid possible invalid read
In various places, do not read past the end of the data.
Fixes https://gitlab.gnome.org/GNOME/glib/-/issues/2416
2021-06-07 09:38:37 +01:00
Peter Bloomfield
955d376b85 tests/tls-certificate: Add a unit test
Test whether g_tls_certificate_new_from_pem() can handle a
non-nul-terminated PEM.

(Fixed minor conflict when cherry-picking.)

Helps https://gitlab.gnome.org/GNOME/glib/-/issues/2416
2021-06-07 09:38:09 +01:00
Gaël Bonithon
d25d6d70f3 inotify: Fix a memory leak
Fixes: #2311
2021-06-04 11:57:41 +01:00