Commit Graph

23317 Commits

Author SHA1 Message Date
Philip Withnall
a34b674134 gspawn-win32: Refactor internal spawn functions
This should introduce no functional changes, but condenses the variants
of the internal spawn implementation down to be more like `gspawn.c`.

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

Helps: #2097
2021-02-16 13:44:00 +00:00
Philip Withnall
ba403908a2 gspawn-win32: Rename a variable for consistency with the public headers
I realise Windows uses handles rather than PIDs, but given that there
are multiple platform-specific implementations of the public
`g_spawn_*()` API, I think it is less confusing for them all to use the
same naming scheme.

This introduces no functional changes.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-02-16 13:44:00 +00:00
Philip Withnall
fd0b20d537 gspawn: Minor improvements to documentation formatting
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-02-16 13:44:00 +00:00
Philip Withnall
67a589e505 gsubprocess: Use new source/target FD mapping functionality in g_spawn()
This improves performance by eliminating the use of a
`GSpawnChildSetupFunc` in the common case (since that setup code has now
moved into `g_spawn*()` itself), and enables the use of the fix to avoid
the child error reporting FD being overwritten by target FD mappings,
introduced via `g_spawn_async_with_pipes_and_fds()`.

It reworks how the source/target FD mapping is stored within
`GSubprocessLauncher` to match what `g_spawn*()` uses. The two
approaches are equivalent.

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

Fixes: #2097
2021-02-16 13:44:00 +00:00
Philip Withnall
b31f3f5f80 gspawn: Add new g_spawn_async_with_pipes_and_fds() API
This is a simple wrapper around the new source/target FD mapping
functionality in `fork_exec()`.

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

Helps: #2097
2021-02-16 13:44:00 +00:00
Philip Withnall
52dc7cb9dd tests: Add setlocale() call to spawn-singlethread
This allows non-ASCII characters to be used in test messages from it.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-02-16 13:44:00 +00:00
Philip Withnall
c5f3ba7f01 gspawn: Avoid merged FDs being closed on exec()
If `stdout_fd` was set to (say) 6, and `stderr_fd` was set to 1, the
`set_cloexec()` call for setting up `stderr` would set the new `stdout`
for the forked process to be closed in the pending `exec()`.

This would cause the child process to error when writing to `stdout`.

This situation happens when using `G_SUBPROCESS_FLAGS_STDERR_MERGE`.

Add some conditions to prevent setting `CLOEXEC` in such cases.

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

Helps: #2097
2021-02-16 13:44:00 +00:00
Philip Withnall
f20f0d385e gspawn: Avoid custom FDs conflicting with the child_err_report_fd
It was previously possible to specify the FD number which
`child_err_report_fd` was assigned, as a target FD in the FD mapping set
up using `g_subprocess_launcher_take_fd()`.

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

Fixes: #2097
2021-02-16 13:44:00 +00:00
Philip Withnall
7be9767cc4 gspawn: Handle arbitrary FD passing and renumbering between fork/exec
This effectively moves some of the functionality of `GSubprocess`
(`g_subprocess_launcher_take_fd()`) into `g_spawn*()`, which should make
implementation a little simpler.

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

Helps: #2097
2021-02-16 13:44:00 +00:00
Philip Withnall
cddcd24b52 gspawn: Combine fork_exec() implementations
This is an internal change which won’t affect the public API. It should
introduce no functional changes, but simplifies the code a little.

The arguments from `fork_exec_with_pipes()` have been added to
`fork_exec_with_fds()`. `child_close_fds` has been dropped since it’s
now an implementation detail within the function.

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

Helps: #2097
2021-02-16 13:44:00 +00:00
Philip Withnall
4946569730 Merge branch 'fix_more_warnings' into 'master'
Fix more warnings

See merge request GNOME/glib!1940
2021-02-16 13:11:43 +00:00
Emmanuel Fleury
0dde9f3744 Fix signedness warning in gio/gmemoryoutputstream.c
gio/gmemoryoutputstream.c: In function ‘g_memory_output_stream_seek’:
gio/gmemoryoutputstream.c:792:44: error: comparison of integer expressions of different signedness: ‘goffset’ {aka ‘long int’} and ‘gsize’ {aka ‘long unsigned int’}
  792 |   if (priv->realloc_fn == NULL && absolute > priv->len)
      |                                            ^
2021-02-16 13:32:26 +01:00
Emmanuel Fleury
e939550cad Fix signedness warning in gio/gdummyfile.c
gio/gdummyfile.c: In function ‘unescape_string’:
gio/gdummyfile.c:485:32: error: comparison of integer expressions of different signedness: ‘long int’ and ‘size_t’ {aka ‘long unsigned int’}
  485 |   g_warn_if_fail (out - result <= strlen (escaped_string));
      |                                ^~
2021-02-16 13:32:26 +01:00
Emmanuel Fleury
18097c8acb Fix signedness warning in gio/gbufferedinputstream.c:g_buffered_input_stream_seek()
gio/gbufferedinputstream.c: In function ‘g_buffered_input_stream_seek’:
gio/gbufferedinputstream.c:899:18: error: comparison of integer expressions of different signedness: ‘goffset’ {aka ‘long int’} and ‘gsize’ {aka ‘long unsigned int’}
  899 |       if (offset <= priv->end - priv->pos && offset >= -priv->pos)
      |                  ^~
gio/gbufferedinputstream.c:899:53: error: comparison of integer expressions of different signedness: ‘goffset’ {aka ‘long int’} and ‘gsize’ {aka ‘long unsigned int’}
  899 |       if (offset <= priv->end - priv->pos && offset >= -priv->pos)
      |                                                     ^~
2021-02-16 13:32:26 +01:00
Emmanuel Fleury
ebb3427f22 Fix signedness warnings in gio/gapplication-tool.c
gio/gapplication-tool.c: In function ‘app_help’:
glib/gmacros.h:806:26: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘size_t’ {aka ‘long unsigned int’}
gio/gapplication-tool.c:121:26: note: in expansion of macro ‘MAX’
  121 |               maxwidth = MAX(maxwidth, strlen (_(substvars[i].var)));
      |                          ^~~
gio/gapplication-tool.c: In function ‘app_help’:
glib/gmacros.h:806:26: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘size_t’ {aka ‘long unsigned int’}
gio/gapplication-tool.c:140:20: note: in expansion of macro ‘MAX’
  140 |         maxwidth = MAX(maxwidth, strlen (topics[i].command));
      |                    ^~~
2021-02-16 13:32:26 +01:00
Emmanuel Fleury
02126e0a07 Fix missing initializer warnings in gio/gapplication-tool.c
gio/gapplication-tool.c:51:3: error: missing initializer for field ‘synopsis’ of ‘const struct help_topic’
   51 |   },
      |   ^
gio/gapplication-tool.c:54:3: error: missing initializer for field ‘synopsis’ of ‘const struct help_topic’
   54 |   },
      |   ^
2021-02-16 13:32:26 +01:00
Emmanuel Fleury
e89bd4cc15 Fix several signedness warnings in gio/gapplication-tool.c
gio/gapplication-tool.c: In function ‘app_help’:
gio/gapplication-tool.c:90:21: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘long unsigned int’
   90 |       for (i = 0; i < G_N_ELEMENTS (topics); i++)
      |                     ^
gio/gapplication-tool.c:117:25: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘long unsigned int’
  117 |           for (i = 0; i < G_N_ELEMENTS (substvars); i++)
      |                         ^
gio/gapplication-tool.c:121:25: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘long unsigned int’
  121 |           for (i = 0; i < G_N_ELEMENTS (substvars); i++)
      |                         ^
gio/gapplication-tool.c:137:21: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘long unsigned int’
  137 |       for (i = 0; i < G_N_ELEMENTS (topics); i++)
      |                     ^
gio/gapplication-tool.c:140:21: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘long unsigned int’
  140 |       for (i = 0; i < G_N_ELEMENTS (topics); i++)
      |                     ^
2021-02-16 13:32:25 +01:00
Emmanuel Fleury
80e2dc3a7a Fix signedness warning in gio/gdbus-tool.c
gio/gdbus-tool.c:1183:95: error: comparison of integer expressions of different signedness: ‘guint’ {aka ‘unsigned int’} and ‘int’
 1183 |           if ((fd_id = g_unix_fd_list_append (fd_list, g_variant_get_handle (value), &error)) == -1)
      |                                                                                               ^~
2021-02-16 13:32:25 +01:00
Sebastian Dröge
7ec5405c5a Merge branch '587-seek-behaviour' into 'master'
ginputstream: Don’t skip off the end of resizable streams

Closes #587

See merge request GNOME/glib!1952
2021-02-16 08:31:06 +00:00
Philip Withnall
8323997f3f glocalfileinputstream: Drop custom skip vfunc implementation
Since the previous commit, the generic `GInputStream` implementation of
`skip()` is now equivalent, and results in the same calls to `lseek()`.

Heavily based on an approach by Dan Winship in
https://bugzilla.gnome.org/show_bug.cgi?id=681374.

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

Helps: #587
2021-02-15 23:10:41 +00:00
Philip Withnall
58c6e0e5d4 ginputstream: Don’t skip off the end of resizable streams
The default implementation of `g_input_stream_skip()` can skip off the
end of resizable streams, as that’s the behaviour of `g_seekable_seek()`
for that type of stream.

This has previously been fixed for local file input streams (commit
89f9615835), and a unit test added there.
However, the fix should be more generally made in `GInputStream`.

This commit reworks an old patch by Dan Winship on
https://bugzilla.gnome.org/show_bug.cgi?id=681374, which took that
approach.

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

Fixes: #587
2021-02-15 23:10:41 +00:00
Philip Withnall
58dd7a37c9 Merge branch 'wip/smcv/armel-atomic-pointer-get' into 'master'
gatomic: Make fallback g_atomic_pointer_get type-safe

See merge request GNOME/glib!1949
2021-02-15 21:47:41 +00:00
Jordi Mas
fec8f18a7d Update Catalan translation 2021-02-15 20:42:14 +01:00
Emin Tufan Çetin
707de30350 Update Turkish translation 2021-02-15 13:59:26 +00:00
Philip Withnall
63467c559e gspawn: Remove spurious blank lines
This introduces no functional changes.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-02-15 12:28:56 +00:00
Philip Withnall
12a627be55 gspawn: Reindent some arguments
They were indented incorrectly and I’m about to add some additional
ones.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2021-02-15 12:28:56 +00:00
Philip Withnall
3dec1b2c00 Merge branch '2319-memdup-deprecation' into 'master'
gstrfuncs: Deprecate g_memdup() in favour of g_memdup2()

Closes #2319

See merge request GNOME/glib!1928
2021-02-15 12:19:31 +00:00
Simon McVittie
985bb56996 Merge branch '2322-fflush-test-dbus' into 'master'
gtestdbus: Flush stdout and stderr before forking a monitor process

Closes #2322

See merge request GNOME/glib!1950
2021-02-15 10:58:06 +00:00
Philip Withnall
9db166f24d Merge branch 'double-zero' into 'master'
Add a test for parsing 0 as double

See merge request GNOME/glib!1951
2021-02-15 10:49:34 +00:00
Philip Withnall
1e21abf0c4 gtestdbus: Flush stdout and stderr before forking a monitor process
This is a workaround for the fact that forking without execing is not
easy to do correctly, and `GTestDBus` doesn’t do it correctly. However,
`GTestDBus` is de-facto deprecated and so putting any more effort in is
a waste.

This fixes an issue where a test would print duplicate output when
outputting to a fully-buffered FD, such as a pipe. This is because the
buffer is non-empty before the `fork()`, and ends up duplicated in the
parent and child processes, both of which later flush the duplicated
buffer contents.

Diagnosed and fix suggested by Simon McVittie.

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

Fixes: #2322
2021-02-15 10:33:32 +00:00
Daniel Mustieles
b9248b0e24 Updated Spanish translation 2021-02-15 10:47:38 +01:00
Simon McVittie
d2b4ba55cb gatomic: Make fallback g_atomic_pointer_get type-safe
Since !1715, g_atomic_pointer_get (&x) has usually returned the type of
x, rather than a generic pointer, in C++ code (where x is any pointer,
or any pointer-sized integer such as guintptr). glib/tests/cxx.cpp
asserts that this is the case.

However, this was only implemented for the lock-free fast-path, not
for the slow path used in platforms with an ARMv5 baseline (and
therefore no atomic instructions) such as Debian armel.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-02-14 23:38:35 +00:00
Sebastian Dröge
c20dd3edbf Merge branch 'wip/smcv/sv-sv' into 'master'
tests: Use a more realistic language code than sv_SV

See merge request GNOME/glib!1948
2021-02-14 16:28:12 +00:00
Simon McVittie
ee53840fa6 tests: Use a more realistic language code than sv_SV
Swedish as spoken in El Salvador is not listed in
/usr/share/i18n/SUPPORTED, and in any case is probably not what we meant.
A more plausible language code would be Swedish as spoken in Sweden.

Prompted by improving the Debian packaging of GLib to generate most of
the language codes mentioned in the tests, so that we can have better
test coverage.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-02-14 14:43:12 +00:00
Sebastian Dröge
a1098548f6 Merge branch 'revert-6bdd1536' into 'master'
Revert "Merge branch 'wip/pwithnall/macos-ci-disable' into 'master'"

See merge request GNOME/glib!1947
2021-02-14 13:15:49 +00:00
Balázs Úr
2c22e6269b Update Hungarian translation 2021-02-13 23:29:17 +00:00
Matthias Clasen
5bad389e63 Add a test for parsing 0 as double
Add a test for #2329.
2021-02-13 14:41:44 -05:00
Anders Jonsson
a75feb14fd Update Swedish translation 2021-02-13 19:30:08 +00:00
Daniel Șerbănescu
667a2057c8 Update Romanian translation 2021-02-13 10:46:13 +00:00
Bartłomiej Piotrowski
52f09fb4ff Revert "Merge branch 'wip/pwithnall/macos-ci-disable' into 'master'"
This reverts merge request !1939
2021-02-12 19:41:11 +00:00
Fran Dieguez
7c87d267c3 Update Galician translation 2021-02-12 19:03:20 +00:00
Yuri Chornoivan
347c0b856b Update Ukrainian translation 2021-02-12 17:58:12 +00:00
Simon McVittie
600c873b3e Merge branch '1804-gdbus-require-same-user' into 'master'
Resolve "Add G_DBUS_SERVER_FLAGS_AUTHENTICATION_REQUIRE_SAME_USER flag"

Closes #1804

See merge request GNOME/glib!1814
2021-02-12 16:38:01 +00:00
Philip Withnall
2f91caf77e tests: Add a basic test for require-same-user D-Bus auth flag
It’s not feasible to test that the require-same-user flag can cause
authentication to fail, as that would require the build environment to
have two users available. We can, however, test that it passes when
authenticating a client and server running under the same user account.

I have manually tested that the new flag works, by running the following
as user A:
```
`$prefix/gdbus-daemon --print-env &`
gdbus call --session --dest org.freedesktop.DBus --object-path /org/freedesktop/DBus --method org.freedesktop.DBus.ListNames
```

And then running the `gdbus call` command again as user B (with the same
value for `DBUS_SESSION_BUS_ADDRESS` in the environment), which
produces:
```
Error connecting: Unexpected lack of content trying to read a line
```
(an authentication rejection)

Commenting out the use of
`G_DBUS_SERVER_FLAGS_AUTHENTICATION_REQUIRE_SAME_USER` from
`gdbusdaemon.c`, the `gdbus call` command succeeds for both users.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-02-11 16:12:40 +00:00
Philip Withnall
5d0ffe73b7 gdbusdaemon: Use require-same-user flag to avoid auth observer signal
This doesn’t change the `GDBusDaemon` behaviour, but does simplify the
code a little.

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

Helps: #1804
2021-02-11 16:12:40 +00:00
Philip Withnall
1a6aa9a493 gdbus: Add flags to require authentication as the same user
This eliminates a common use case for the
`GDBusAuthObserver::authorize-authenticated-peer` signal, which is often
implemented incorrectly by people.

Suggested by Simon McVittie.

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

Fixes: #1804
2021-02-11 16:12:40 +00:00
Philip Withnall
137a9bdcc2 gdbusauth: Use g_clear_object() to simplify the code a little
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-02-11 16:06:27 +00:00
Philip Withnall
a1db705bc2 Merge branch 'wip/gdbus-flags-from-the-future' into 'master'
gdbus: Reject attempts to set future connection or server flags

See merge request GNOME/glib!1934
2021-02-11 11:53:13 +00:00
Philip Withnall
490b638e72 Merge branch 'byte-array-take' into 'master'
gbytearray: Do not accept too large byte arrays

See merge request GNOME/glib!1942
2021-02-11 10:27:42 +00:00
Krzesimir Nowak
acb7b0ec69 gbytearray: Do not accept too large byte arrays
GByteArray uses guint for storing the length of the byte array, but it
also has a constructor (g_byte_array_new_take) that takes length as a
gsize. gsize may be larger than guint (64 bits for gsize vs 32 bits
for guint). It is possible to call the function with a value greater
than G_MAXUINT, which will result in silent length truncation. This
may happen as a result of unreffing GBytes into GByteArray, so rather
be loud about it.

(Test case tweaked by Philip Withnall.)
2021-02-11 10:14:15 +00:00