mirror of
https://github.com/X11Libre/xserver.git
synced 2026-10-28 02:21:08 +00:00
xquartz: bundle_trampoline.c: fall back to ASL when os_log is unavailable
Commit ee9cb28c3 switched the trampoline's error reporting to
os_log_error(), which only exists on macOS 10.12 and later, breaking the
build for older deployment targets.
Add HAS_OS_LOG to osxcompat.h, keyed on MAC_OS_X_VERSION_MIN_REQUIRED
like the other compat checks, and route logging through
a trampoline_log_error() macro that uses asl_log() when os_log is not
available. The os_log-only %{public}s specifier is wrapped in a PUBLIC_S
macro that expands to plain %s for ASL.
Signed-off-by: Sergey Fedorov <barracuda@macos-powerpc.org>
This commit is contained in:
parent
942379ce91
commit
027067d485
3 changed files with 23 additions and 6 deletions
|
|
@ -26,9 +26,10 @@
|
|||
* prior written authorization.
|
||||
*/
|
||||
|
||||
#include "osxcompat.h"
|
||||
|
||||
#include <mach-o/dyld.h>
|
||||
#include <libgen.h>
|
||||
#include <os/log.h>
|
||||
#include <spawn.h>
|
||||
#include <sys/syslimits.h>
|
||||
#include <errno.h>
|
||||
|
|
@ -37,6 +38,17 @@
|
|||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* os_log is only available on 10.12 and later, fall back to ASL on older systems */
|
||||
#ifdef HAS_OS_LOG
|
||||
#include <os/log.h>
|
||||
#define trampoline_log_error(...) os_log_error(OS_LOG_DEFAULT, __VA_ARGS__)
|
||||
#define PUBLIC_S "%{public}s"
|
||||
#else
|
||||
#include <asl.h>
|
||||
#define trampoline_log_error(...) asl_log(NULL, NULL, ASL_LEVEL_ERR, __VA_ARGS__)
|
||||
#define PUBLIC_S "%s"
|
||||
#endif
|
||||
|
||||
/* We want XQuartz.app to inherit a login shell environment. This is handled by the X11.sh
|
||||
* script which re-execs the main binary from a login shell environment. However, recent
|
||||
* versions of macOS require that the main executable of an app be Mach-O for full system
|
||||
|
|
@ -60,7 +72,7 @@ static char *executable_path(void) {
|
|||
free(buf);
|
||||
buf = calloc(1, bufsize);
|
||||
if (_NSGetExecutablePath(buf, &bufsize) != 0) {
|
||||
os_log_error(OS_LOG_DEFAULT, "Failed to determine executable path");
|
||||
trampoline_log_error("Failed to determine executable path");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
|
@ -78,7 +90,7 @@ int main(int argc, char **argv, char **envp) {
|
|||
asprintf(&executable, "%s/X11", executable_directory);
|
||||
}
|
||||
if (access(executable, X_OK) != 0) {
|
||||
os_log_error(OS_LOG_DEFAULT, "Cannot execute %{public}s: %{public}s", executable, strerror(errno));
|
||||
trampoline_log_error("Cannot execute " PUBLIC_S ": " PUBLIC_S, executable, strerror(errno));
|
||||
abort();
|
||||
}
|
||||
|
||||
|
|
@ -87,19 +99,19 @@ int main(int argc, char **argv, char **envp) {
|
|||
posix_spawnattr_t attr;
|
||||
int error = posix_spawnattr_init(&attr);
|
||||
if (error != 0) {
|
||||
os_log_error(OS_LOG_DEFAULT, "posix_spawnattr_init failed: %{public}s", strerror(error));
|
||||
trampoline_log_error("posix_spawnattr_init failed: " PUBLIC_S, strerror(error));
|
||||
abort();
|
||||
}
|
||||
error = posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETEXEC);
|
||||
if (error != 0) {
|
||||
os_log_error(OS_LOG_DEFAULT, "posix_spawnattr_setflags failed: %{public}s", strerror(error));
|
||||
trampoline_log_error("posix_spawnattr_setflags failed: " PUBLIC_S, strerror(error));
|
||||
abort();
|
||||
}
|
||||
|
||||
pid_t child_pid;
|
||||
error = posix_spawn(&child_pid, executable, NULL, &attr, argv, envp);
|
||||
if (error != 0) {
|
||||
os_log_error(OS_LOG_DEFAULT, "posix_spawn failed for %{public}s: %{public}s", executable, strerror(error));
|
||||
trampoline_log_error("posix_spawn failed for " PUBLIC_S ": " PUBLIC_S, executable, strerror(error));
|
||||
abort();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -99,6 +99,7 @@ x11 = executable('X11',
|
|||
[
|
||||
'bundle_trampoline.c',
|
||||
],
|
||||
include_directories: ['..'],
|
||||
c_args: xquartz_defs,
|
||||
link_args: execlinkargs,
|
||||
install: true,
|
||||
|
|
|
|||
|
|
@ -40,6 +40,10 @@
|
|||
#define HAS_ASL_LOG_DESCRIPTOR
|
||||
#endif
|
||||
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
|
||||
#define HAS_OS_LOG
|
||||
#endif
|
||||
|
||||
#if __OBJC__
|
||||
#ifdef __clang__
|
||||
#define OBJC_AUTORELEASEPOOL_BEGIN @autoreleasepool {
|
||||
|
|
|
|||
Loading…
Reference in a new issue