x11: Minor cleanups and corrections in X11_ShowMessageBox. Reference issue #3254.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
diff --git a/src/video/x11/SDL_x11messagebox.c b/src/video/x11/SDL_x11messagebox.c
index aafccca..9bc9702 100644
--- a/src/video/x11/SDL_x11messagebox.c
+++ b/src/video/x11/SDL_x11messagebox.c
@@ -830,10 +830,11 @@ X11_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
int exitcode = 0;
close(fds[0]);
status = X11_ShowMessageBoxImpl(messageboxdata, buttonid);
- if (write(fds[1], &status, sizeof (int)) != sizeof (int))
+ if (write(fds[1], &status, sizeof (int)) != sizeof (int)) {
exitcode = 1;
- else if (write(fds[1], buttonid, sizeof (int)) != sizeof (int))
+ } else if (write(fds[1], buttonid, sizeof (int)) != sizeof (int)) {
exitcode = 1;
+ }
close(fds[1]);
_exit(exitcode); /* don't run atexit() stuff, static destructors, etc. */
} else { /* we're the parent */
@@ -846,13 +847,12 @@ X11_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
SDL_assert(rc == pid); /* not sure what to do if this fails. */
if ((rc == -1) || (!WIFEXITED(status)) || (WEXITSTATUS(status) != 0)) {
- return SDL_SetError("msgbox child process failed");
+ status = SDL_SetError("msgbox child process failed");
+ } else if ( (read(fds[0], &status, sizeof (int)) != sizeof (int)) ||
+ (read(fds[0], buttonid, sizeof (int)) != sizeof (int)) ) {
+ status = SDL_SetError("read from msgbox child process failed");
+ *buttonid = 0;
}
-
- if (read(fds[0], &status, sizeof (int)) != sizeof (int))
- status = -1;
- else if (read(fds[0], buttonid, sizeof (int)) != sizeof (int))
- status = -1;
close(fds[0]);
return status;