diff options
author | Simon McVittie <smcv@collabora.com> | 2021-02-25 12:22:23 +0000 |
---|---|---|
committer | Simon McVittie <smcv@collabora.com> | 2021-02-25 12:22:34 +0000 |
commit | 2db42705a7e413953d26930880951734ab0df931 (patch) | |
tree | 4ef7a5f1f7973a142ab4edafe8d2969ddbc5d778 /glib/gspawn-win32.c | |
parent | 6259fb5be7f727fba1507315f79791ee0f2dee66 (diff) | |
download | glib-wip/wait-status.tar.gz |
Distinguish more clearly between wait status and exit statuswip/wait-status
On Unix platforms, wait() and friends yield an integer that encodes
how the process exited. Confusingly, this is usually not the same as
the integer passed to exit() or returned from main().
I find that it's clearer what is going on if we are consistent about
referring to the result of wait() as a "wait status", and the value
passed to exit() as an "exit status".
GSubprocess already gets this right: g_subprocess_get_status() returns
the wait status, while g_subprocess_get_exit_status() genuinely returns
the exit status. However, the GSpawn family of APIs has tended to
conflate the two.
Confusingly, g_spawn_check_exit_status() has always checked a wait
status, and it would not be correct to pass an exit status to it.
Deprecate it in favour of g_spawn_check_wait_status(), which does
the same thing.
Signed-off-by: Simon McVittie <smcv@collabora.com>
Diffstat (limited to 'glib/gspawn-win32.c')
-rw-r--r-- | glib/gspawn-win32.c | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/glib/gspawn-win32.c b/glib/gspawn-win32.c index 0f6579eab..c92679157 100644 --- a/glib/gspawn-win32.c +++ b/glib/gspawn-win32.c @@ -927,7 +927,7 @@ g_spawn_sync (const gchar *working_directory, gpointer user_data, gchar **standard_output, gchar **standard_error, - gint *exit_status, + gint *wait_status, GError **error) { gint outpipe = -1; @@ -1102,8 +1102,8 @@ g_spawn_sync (const gchar *working_directory, /* No helper process, exit status of actual spawned process * already available. */ - if (exit_status) - *exit_status = status; + if (wait_status) + *wait_status = status; } else { @@ -1119,8 +1119,8 @@ g_spawn_sync (const gchar *working_directory, switch (helper_report[0]) { case CHILD_NO_ERROR: - if (exit_status) - *exit_status = helper_report[1]; + if (wait_status) + *wait_status = helper_report[1]; break; default: set_child_error (helper_report, working_directory, error); @@ -1310,7 +1310,7 @@ gboolean g_spawn_command_line_sync (const gchar *command_line, gchar **standard_output, gchar **standard_error, - gint *exit_status, + gint *wait_status, GError **error) { gboolean retval; @@ -1331,7 +1331,7 @@ g_spawn_command_line_sync (const gchar *command_line, NULL, standard_output, standard_error, - exit_status, + wait_status, error); g_strfreev (argv); @@ -1372,16 +1372,16 @@ g_spawn_close_pid (GPid pid) } gboolean -g_spawn_check_exit_status (gint exit_status, +g_spawn_check_wait_status (gint wait_status, GError **error) { gboolean ret = FALSE; - if (exit_status != 0) + if (wait_status != 0) { - g_set_error (error, G_SPAWN_EXIT_ERROR, exit_status, + g_set_error (error, G_SPAWN_EXIT_ERROR, wait_status, _("Child process exited with code %ld"), - (long) exit_status); + (long) wait_status); goto out; } @@ -1390,6 +1390,13 @@ g_spawn_check_exit_status (gint exit_status, return ret; } +gboolean +g_spawn_check_exit_status (gint wait_status, + GError **error) +{ + return g_spawn_check_wait_status (wait_status, error); +} + #ifdef G_OS_WIN32 /* Binary compatibility versions. Not for newly compiled code. */ @@ -1421,12 +1428,12 @@ _GLIB_EXTERN gboolean g_spawn_sync_utf8 (const gchar *wo gpointer user_data, gchar **standard_output, gchar **standard_error, - gint *exit_status, + gint *wait_status, GError **error); _GLIB_EXTERN gboolean g_spawn_command_line_sync_utf8 (const gchar *command_line, gchar **standard_output, gchar **standard_error, - gint *exit_status, + gint *wait_status, GError **error); _GLIB_EXTERN gboolean g_spawn_command_line_async_utf8 (const gchar *command_line, GError **error); @@ -1486,7 +1493,7 @@ g_spawn_sync_utf8 (const gchar *working_directory, gpointer user_data, gchar **standard_output, gchar **standard_error, - gint *exit_status, + gint *wait_status, GError **error) { return g_spawn_sync (working_directory, @@ -1497,7 +1504,7 @@ g_spawn_sync_utf8 (const gchar *working_directory, user_data, standard_output, standard_error, - exit_status, + wait_status, error); } @@ -1505,13 +1512,13 @@ gboolean g_spawn_command_line_sync_utf8 (const gchar *command_line, gchar **standard_output, gchar **standard_error, - gint *exit_status, + gint *wait_status, GError **error) { return g_spawn_command_line_sync (command_line, standard_output, standard_error, - exit_status, + wait_status, error); } |