From 622eca906855e4dd5b45ad0abe58c76c8e61ccae Mon Sep 17 00:00:00 2001 From: gbeauche <> Date: Tue, 18 Apr 2006 22:17:31 +0000 Subject: [PATCH] Handle MacOS X bundles, search order: BasiliskII.app in the same directory as BasiliskIIGUI.app, or /Applications/BasiliskII.app if none was found. Also make yet another arrangement for MacOS X "difference". This scenario was not working: WarningAlert -> ErrorAlert, the latter was not performed because the exit status was not properly filled in sip->si_status... --- BasiliskII/src/Unix/prefs_editor_gtk.cpp | 29 +++++++++++++++++++----- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/BasiliskII/src/Unix/prefs_editor_gtk.cpp b/BasiliskII/src/Unix/prefs_editor_gtk.cpp index 3870d2df..1cabf437 100644 --- a/BasiliskII/src/Unix/prefs_editor_gtk.cpp +++ b/BasiliskII/src/Unix/prefs_editor_gtk.cpp @@ -1678,7 +1678,14 @@ static void sigchld_handler(int sig, siginfo_t *sip, void *) { D(bug("Child %d exitted with status = %x\n", sip->si_pid, sip->si_status)); - int status = sip->si_status; + // XXX perform a new wait because sip->si_status is sometimes not + // the exit _value_ on MacOS X but rather the usual status field + // from waitpid() -- we could arrange this code in some other way... + int status; + if (waitpid(sip->si_pid, &status, 0) < 0) + status = sip->si_status; + if (WIFEXITED(status)) + status = WEXITSTATUS(status); if (status & 0x80) status |= -1 ^0xff; @@ -1741,15 +1748,25 @@ int main(int argc, char *argv[]) } // Search and run the BasiliskII executable - // XXX it can be in a bundle on MacOS X + char *p; strcpy(g_app_path, argv[0]); - char *p = strrchr(g_app_path, '/'); - p = p ? p + 1 : g_app_path; - *p = '\0'; - strcat(g_app_path, "BasiliskII"); + if ((p = strstr(g_app_path, "BasiliskIIGUI.app/Contents/MacOS")) != NULL) { + strcpy(p, "BasiliskII.app/Contents/MacOS/BasiliskII"); + if (access(g_app_path, X_OK) < 0) { + char str[256]; + sprintf(str, GetString(STR_NO_B2_EXE_FOUND), g_app_path, strerror(errno)); + WarningAlert(str); + strcpy(g_app_path, "/Applications/BasiliskII.app/Contents/MacOS/BasiliskII"); + } + } else { + p = strrchr(g_app_path, '/'); + p = p ? p + 1 : g_app_path; + strcpy(p, "BasiliskII"); + } int pid = fork(); if (pid == 0) { + D(bug("Trying to execute %s\n", g_app_path)); execlp(g_app_path, g_app_path, "--gui-connection", gui_connection_path, (char *)NULL); #ifdef _POSIX_PRIORITY_SCHEDULING // XXX get a chance to run the parent process so that to not confuse/upset GTK...