Fix error handling of wayland message box

Zenity return a small integer on success which may be the same as EXIT_FAILURE. Use a bigger integer for error reporting from child process.
This commit is contained in:
Mathieu Eyraud 2021-04-21 13:39:31 +02:00 committed by Ryan C. Gordon
parent 12dd412b0b
commit a5825576fb

View file

@ -26,7 +26,7 @@
#include "SDL.h" #include "SDL.h"
#include <stdlib.h> /* fgets */ #include <stdlib.h> /* fgets */
#include <stdio.h> /* FILE, STDOUT_FILENO, fdopen, fclose */ #include <stdio.h> /* FILE, STDOUT_FILENO, fdopen, fclose */
#include <unistd.h> /* pid_t, pipe, fork, close, dup2, execvp, _exit, EXIT_FAILURE */ #include <unistd.h> /* pid_t, pipe, fork, close, dup2, execvp, _exit */
#include <sys/wait.h> /* waitpid, WIFEXITED, WEXITSTATUS */ #include <sys/wait.h> /* waitpid, WIFEXITED, WEXITSTATUS */
#include <string.h> /* strerr */ #include <string.h> /* strerr */
#include <errno.h> #include <errno.h>
@ -57,7 +57,7 @@ Wayland_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
close(fd_pipe[0]); /* no reading from pipe */ close(fd_pipe[0]); /* no reading from pipe */
/* write stdout in pipe */ /* write stdout in pipe */
if (dup2(fd_pipe[1], STDOUT_FILENO) == -1) { if (dup2(fd_pipe[1], STDOUT_FILENO) == -1) {
_exit(EXIT_FAILURE); _exit(128);
} }
argv[argc++] = "--icon-name"; argv[argc++] = "--icon-name";
@ -102,7 +102,7 @@ Wayland_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
* https://pubs.opengroup.org/onlinepubs/9699919799/functions/fexecve.html -> rational * https://pubs.opengroup.org/onlinepubs/9699919799/functions/fexecve.html -> rational
*/ */
execvp("zenity", (char **)argv); execvp("zenity", (char **)argv);
_exit(EXIT_FAILURE); _exit(129);
} else if (pid1 < 0) { } else if (pid1 < 0) {
close(fd_pipe[0]); close(fd_pipe[0]);
close(fd_pipe[1]); close(fd_pipe[1]);
@ -111,7 +111,7 @@ Wayland_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
int status; int status;
if (waitpid(pid1, &status, 0) == pid1) { if (waitpid(pid1, &status, 0) == pid1) {
if (WIFEXITED(status)) { if (WIFEXITED(status)) {
if (WEXITSTATUS(status) >= 0) { if (WEXITSTATUS(status) < 128) {
int i; int i;
size_t output_len = 1; size_t output_len = 1;
char* output = NULL; char* output = NULL;