mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-25 02:18:55 +02:00
Add g_spawn_check_exit_status()
Many (if not "almost all") programs that spawn other programs via g_spawn_sync() or the like simply want to check whether or not the child exited successfully, but doing so requires use of platform-specific functionality and there's actually a fair amount of boilerplate involved. This new API will help drain a *lot* of mostly duplicated code in GNOME, from gnome-session to gdm. And we can see that some bits even inside GLib were doing it wrong; for example checking the exit status on Unix, but ignoring it on Windows. https://bugzilla.gnome.org/show_bug.cgi?id=679691
This commit is contained in:
@@ -33,9 +33,6 @@
|
||||
#ifdef G_OS_WIN32
|
||||
#include <io.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_WAIT_H
|
||||
#include <sys/wait.h>
|
||||
#endif
|
||||
|
||||
#include <gio/gmemoryoutputstream.h>
|
||||
#include <gio/gzlibcompressor.h>
|
||||
@@ -331,14 +328,14 @@ end_element (GMarkupParseContext *context,
|
||||
g_propagate_error (error, my_error);
|
||||
goto cleanup;
|
||||
}
|
||||
#ifdef HAVE_SYS_WAIT_H
|
||||
if (!WIFEXITED (status) || WEXITSTATUS (status) != 0)
|
||||
|
||||
/* Ugly...we shoud probably just let stderr be inherited */
|
||||
if (!g_spawn_check_exit_status (status, NULL))
|
||||
{
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
_("Error processing input file with xmllint:\n%s"), stderr_child);
|
||||
goto cleanup;
|
||||
}
|
||||
#endif
|
||||
|
||||
g_free (stderr_child);
|
||||
g_free (real_file);
|
||||
@@ -387,14 +384,13 @@ end_element (GMarkupParseContext *context,
|
||||
g_propagate_error (error, my_error);
|
||||
goto cleanup;
|
||||
}
|
||||
#ifdef HAVE_SYS_WAIT_H
|
||||
if (!WIFEXITED (status) || WEXITSTATUS (status) != 0)
|
||||
|
||||
if (!g_spawn_check_exit_status (status, NULL))
|
||||
{
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
_("Error processing input file with to-pixdata:\n%s"), stderr_child);
|
||||
goto cleanup;
|
||||
}
|
||||
#endif
|
||||
|
||||
g_free (stderr_child);
|
||||
g_free (real_file);
|
||||
|
Reference in New Issue
Block a user