summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Huddleston Sequoia <jeremyhu@apple.com>2021-01-27 13:33:22 -0800
committerJeremy Huddleston Sequoia <jeremyhu@apple.com>2021-02-01 16:21:39 -0800
commitc0b2d3e099a60f55b18ca9c30373000f12d40fe2 (patch)
tree5cf7ebb8b845d8d43cef33a5478a5a7831adb8d0
parentcc9cf6f085be6e8264f925a11d67a12ad47a042b (diff)
xquartz: Remove support for Lion and earlier versions of macOS
Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
-rw-r--r--hw/xquartz/Makefile.am6
-rw-r--r--hw/xquartz/X11Controller.m8
-rw-r--r--hw/xquartz/console_redirect.c331
-rw-r--r--hw/xquartz/console_redirect.h46
-rw-r--r--hw/xquartz/mach-startup/bundle-main.c22
5 files changed, 4 insertions, 409 deletions
diff --git a/hw/xquartz/Makefile.am b/hw/xquartz/Makefile.am
index ebd3e1bc7..85355a8ac 100644
--- a/hw/xquartz/Makefile.am
+++ b/hw/xquartz/Makefile.am
@@ -33,8 +33,7 @@ libXquartz_la_SOURCES = \
quartzCocoa.m \
quartzKeyboard.c \
quartzStartup.c \
- quartzRandR.c \
- console_redirect.c
+ quartzRandR.c
libXquartz_la_LIBADD = $(top_builddir)/pseudoramiX/libPseudoramiX.la
@@ -51,5 +50,4 @@ EXTRA_DIST = \
quartzKeyboard.h \
quartzRandR.h \
sanitizedCarbon.h \
- sanitizedCocoa.h \
- console_redirect.h
+ sanitizedCocoa.h
diff --git a/hw/xquartz/X11Controller.m b/hw/xquartz/X11Controller.m
index 81ad3c639..bc976bf5f 100644
--- a/hw/xquartz/X11Controller.m
+++ b/hw/xquartz/X11Controller.m
@@ -347,10 +347,8 @@ extern char *bundle_id_prefix;
const char *newargv[4];
char buf[128];
char *s;
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
int stdout_pipe[2];
int stderr_pipe[2];
-#endif
newargv[0] = [X11App prefs_get_string:@PREFS_LOGIN_SHELL default:"/bin/sh"];
newargv[1] = "-c";
@@ -363,7 +361,6 @@ extern char *bundle_id_prefix;
setenv("DISPLAY", buf, TRUE);
}
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
if (&asl_log_descriptor) {
char *asl_sender;
aslmsg amsg = asl_new(ASL_TYPE_MSG);
@@ -395,7 +392,6 @@ extern char *bundle_id_prefix;
asl_free(amsg);
}
-#endif
/* Do the fork-twice trick to avoid having to reap zombies */
child1 = fork();
@@ -413,13 +409,11 @@ extern char *bundle_id_prefix;
_exit(1);
case 0: /* child2 */
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
if (&asl_log_descriptor) {
/* Replace our stdout/stderr */
dup2(stdout_pipe[1], STDOUT_FILENO);
dup2(stderr_pipe[1], STDERR_FILENO);
}
-#endif
/* close all open files except for standard streams */
max_files = sysconf(_SC_OPEN_MAX);
@@ -442,13 +436,11 @@ extern char *bundle_id_prefix;
waitpid(child1, &status, 0);
}
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
if (&asl_log_descriptor) {
/* Close the write ends of the pipe */
close(stdout_pipe[1]);
close(stderr_pipe[1]);
}
-#endif
}
- (void) app_selected:sender
diff --git a/hw/xquartz/console_redirect.c b/hw/xquartz/console_redirect.c
deleted file mode 100644
index 245086ad0..000000000
--- a/hw/xquartz/console_redirect.c
+++ /dev/null
@@ -1,331 +0,0 @@
-/*
- * Copyright (c) 2011-2012 Apple Inc. All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation files
- * (the "Software"), to deal in the Software without restriction,
- * including without limitation the rights to use, copy, modify, merge,
- * publish, distribute, sublicense, and/or sell copies of the Software,
- * and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
- * HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Except as contained in this notice, the name(s) of the above
- * copyright holders shall not be used in advertising or otherwise to
- * promote the sale, use or other dealings in this Software without
- * prior written authorization.
- */
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#else
-#define DEBUG_CONSOLE_REDIRECT 1
-#endif
-
-#include <assert.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/event.h>
-#include <asl.h>
-#include <errno.h>
-#include <fcntl.h>
-
-#include "console_redirect.h"
-
-#define BUF_SIZE 512
-
-#include <dispatch/dispatch.h>
-
-static dispatch_queue_t redirect_serial_q;
-static dispatch_group_t read_source_group;
-
-typedef struct {
- int level;
- aslclient asl;
- aslmsg msg;
-
- /* Buffered reading */
- char *buf;
- char *w;
-
- dispatch_source_t read_source;
-} asl_redirect;
-
-static asl_redirect *redirect_fds = NULL;
-static int n_redirect_fds = 0;
-
-/* Read from the FD until there is no more to read and redirect to ASL.
- * Preconditions:
- * 1: pthread_mutex_lock lock is held (pthreads) or called
- * from the appropriate serial queue for operating on
- * redirect_fds
- * 2: fd corresponds to a valid entry in redirect_fds
- *
- * Return values:
- * If the pipe is closed, EOF is returned regardless of how many bytes
- * were processed. If the pipe is still open, the number of read bytes
- * is returned.
- */
-static inline int
-_read_redirect(int fd, int flush)
-{
- int total_read = 0;
- int nbytes;
- asl_redirect *aslr = &redirect_fds[fd];
-
- while ((nbytes =
- read(fd, aslr->w,
- BUF_SIZE - (aslr->w - aslr->buf) - 1)) > 0) {
- char *s, *p;
-
- /* Increment our returned number read */
- total_read += nbytes;
-
- /* Increment our write location */
- aslr->w += nbytes;
- aslr->w[0] = '\0';
-
- /* One line at a time */
- for (p = aslr->buf; p < aslr->w; p = s + 1) {
- // Find null or \n
- for (s = p; *s && *s != '\n'; s++) ;
- if (*s == '\n') {
- *s = '\0';
- }
-
- if (s < aslr->w || aslr->buf == p) {
- /* Either the first of multiple messages or one message which is larger than our buffer */
- asl_log(aslr->asl, aslr->msg, aslr->level, "%s", p);
- }
- else {
- /* We reached the end of the buffer, move this chunk to the start. */
- memmove(aslr->buf, p, BUF_SIZE - (p - aslr->buf));
- aslr->w = aslr->buf + (s - p);
- break;
- }
- }
-
- if (p == aslr->w) {
- /* Start writing at the beginning in the case where we flushed */
- aslr->w = aslr->buf;
- }
- }
-
- /* Flush if requested or we're at EOF */
- if (flush || nbytes == 0) {
- if (aslr->w > aslr->buf) {
- *aslr->w = '\0';
- asl_log(aslr->asl, aslr->msg, aslr->level, "%s", aslr->buf);
- }
- }
-
- if (nbytes == 0)
- return EOF;
- return total_read;
-}
-
-static void
-read_from_source(void *_source)
-{
- dispatch_source_t source = (dispatch_source_t)_source;
- int fd = dispatch_source_get_handle(source);
- if (_read_redirect(fd, 0) == EOF) {
- dispatch_source_cancel(source);
- }
-}
-
-static void
-cancel_source(void *_source)
-{
- dispatch_source_t source = (dispatch_source_t)_source;
- int fd = dispatch_source_get_handle(source);
- asl_redirect *aslr = &redirect_fds[fd];
-
- /* Flush the buffer */
- _read_redirect(fd, 1);
-
- close(fd);
- free(aslr->buf);
- memset(aslr, 0, sizeof(*aslr));
- dispatch_release(source);
- dispatch_group_leave(read_source_group);
-}
-
-
-static void
-redirect_atexit(void)
-{
- /* stdout is linebuffered, so flush the buffer */
- if (redirect_fds[STDOUT_FILENO].buf)
- fflush(stdout);
-
- {
- int i;
-
- /* Cancel all of our dispatch sources, so they flush to ASL */
- for (i = 0; i < n_redirect_fds; i++)
- if (redirect_fds[i].read_source)
- dispatch_source_cancel(redirect_fds[i].read_source);
-
- /* Wait at least three seconds for our sources to flush to ASL */
- dispatch_group_wait(read_source_group,
- dispatch_time(DISPATCH_TIME_NOW, 3LL *
- NSEC_PER_SEC));
- }
-}
-
-static void
-xq_asl_init(void *ctx __unused)
-{
- assert((redirect_fds = calloc(16, sizeof(*redirect_fds))) != NULL);
- n_redirect_fds = 16;
-
- redirect_serial_q = dispatch_queue_create("com.apple.asl-redirect", NULL);
- assert(redirect_serial_q != NULL);
-
- read_source_group = dispatch_group_create();
- assert(read_source_group != NULL);
-
- atexit(redirect_atexit);
-}
-
-int
-xq_asl_log_fd(aslclient asl, aslmsg msg, int level, int fd)
-{
- int err __block = 0;
- static dispatch_once_t once_control;
- dispatch_once_f(&once_control, NULL, xq_asl_init);
-
- if (fd < 0)
- return EBADF;
-
-#define BLOCK_DONE return
- dispatch_sync(redirect_serial_q, ^
- {
- /* Reallocate if we need more space */
- if (fd >= n_redirect_fds) {
- size_t new_n = 1 << (fls(fd) + 1);
- asl_redirect *new_array =
- realloc(redirect_fds, new_n *
- sizeof(*redirect_fds));
- if (!new_array) {
- err = errno;
- BLOCK_DONE;
- }
- redirect_fds = new_array;
- memset(redirect_fds + n_redirect_fds, 0, (new_n -
- n_redirect_fds) * sizeof(*redirect_fds));
- n_redirect_fds = new_n;
- }
-
- /* If we're already listening on it, return error. */
- if (redirect_fds[fd].buf != NULL) {
- err = EBADF;
- BLOCK_DONE;
- }
-
- /* Initialize our buffer */
- redirect_fds[fd].buf = (char *)malloc(BUF_SIZE);
- if (redirect_fds[fd].buf == NULL) {
- err = errno;
- BLOCK_DONE;
- }
- redirect_fds[fd].w = redirect_fds[fd].buf;
-
- /* Store our ASL settings */
- redirect_fds[fd].level = level;
- redirect_fds[fd].asl = asl;
- redirect_fds[fd].msg = msg;
-
- /* Don't block on reads from this fd */
- fcntl(fd, F_SETFL,
- O_NONBLOCK);
-
- /* Start listening */
- {
- dispatch_source_t read_source =
- dispatch_source_create(
- DISPATCH_SOURCE_TYPE_READ, fd, 0,
- redirect_serial_q);
- redirect_fds[fd].read_source = read_source;
- dispatch_set_context(read_source, read_source);
- dispatch_source_set_event_handler_f(read_source,
- read_from_source);
- dispatch_source_set_cancel_handler_f(read_source,
- cancel_source);
- dispatch_group_enter(read_source_group);
- dispatch_resume(read_source);
- }
- }
- );
-#undef BLOCK_DONE
-
- return err;
-}
-
-int
-xq_asl_capture_fd(aslclient asl, aslmsg msg, int level, int fd)
-{
- int pipepair[2];
-
- /* Create pipe */
- if (pipe(pipepair) == -1)
- return errno;
-
- /* Close the read fd but not the write fd on exec */
- if (fcntl(pipepair[0], F_SETFD, FD_CLOEXEC) == -1)
- return errno;
-
- /* Replace the existing fd */
- if (dup2(pipepair[1], fd) == -1) {
- close(pipepair[0]);
- close(pipepair[1]);
- return errno;
- }
-
- /* If we capture STDOUT_FILENO, make sure we linebuffer stdout */
- if (fd == STDOUT_FILENO)
- setlinebuf(stdout);
-
- /* Close the duplicate fds since they've been reassigned */
- close(pipepair[1]);
-
- /* Hand off the read end of our pipe to xq_asl_log_fd */
- return xq_asl_log_fd(asl, msg, level, pipepair[0]);
-}
-
-#ifdef DEBUG_CONSOLE_REDIRECT
-int
-main(int argc __unused, char * *argv __unused)
-{
- xq_asl_capture_fd(NULL, NULL, ASL_LEVEL_NOTICE, STDOUT_FILENO);
- xq_asl_capture_fd(NULL, NULL, ASL_LEVEL_ERR, STDERR_FILENO);
-
- fprintf(stderr, "TEST ERR1\n");
- fprintf(stdout, "TEST OUT1\n");
- fprintf(stderr, "TEST ERR2\n");
- fprintf(stdout, "TEST OUT2\n");
- system("/bin/echo SYST OUT");
- system("/bin/echo SYST ERR >&2");
- fprintf(stdout, "TEST OUT3\n");
- fprintf(stdout, "TEST OUT4\n");
- fprintf(stderr, "TEST ERR3\n");
- fprintf(stderr, "TEST ERR4\n");
-
- exit(0);
-}
-#endif
diff --git a/hw/xquartz/console_redirect.h b/hw/xquartz/console_redirect.h
deleted file mode 100644
index 7b80de405..000000000
--- a/hw/xquartz/console_redirect.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/* Copyright (c) 2011-2012 Apple Inc.
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation files
- * (the "Software"), to deal in the Software without restriction,
- * including without limitation the rights to use, copy, modify, merge,
- * publish, distribute, sublicense, and/or sell copies of the Software,
- * and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
- * HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Except as contained in this notice, the name(s) of the above
- * copyright holders shall not be used in advertising or otherwise to
- * promote the sale, use or other dealings in this Software without
- * prior written authorization.
- */
-
-#ifndef _XQUARTZ_CONSOLE_REDIRECT_H_
-#define _XQUARTZ_CONSOLE_REDIRECT_H_
-
-#include <asl.h>
-
-/* The given fd is replaced with a pipe. Anything written to it will will be
- * logged to ASL.
- */
-int
-xq_asl_capture_fd(aslclient asl, aslmsg msg, int level, int fd);
-
-/* The given fd is read from and passed along to ASL until all write ends of the
- * pipe are closed. Once the last writer has closed the pipe, we close our end.
- */
-int
-xq_asl_log_fd(aslclient asl, aslmsg msg, int level, int fd);
-
-#endif
diff --git a/hw/xquartz/mach-startup/bundle-main.c b/hw/xquartz/mach-startup/bundle-main.c
index 47a02bcb3..b7d5ebef7 100644
--- a/hw/xquartz/mach-startup/bundle-main.c
+++ b/hw/xquartz/mach-startup/bundle-main.c
@@ -57,8 +57,6 @@
#include "mach_startup.h"
#include "mach_startupServer.h"
-#include "console_redirect.h"
-
/* From darwinEvents.c ... but don't want to pull in all the server cruft */
void
DarwinListenOnOpenFD(int fd);
@@ -520,24 +518,8 @@ setup_console_redirect(const char *bundle_id)
asl_set_filter(aslc, ASL_FILTER_MASK_UPTO(ASL_LEVEL_WARNING));
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
-# if MAC_OS_X_VERSION_MIN_REQUIRED < 1080
- if (asl_log_descriptor)
-# endif
- {
- asl_log_descriptor(aslc, NULL, ASL_LEVEL_INFO, STDOUT_FILENO, ASL_LOG_DESCRIPTOR_WRITE);
- asl_log_descriptor(aslc, NULL, ASL_LEVEL_NOTICE, STDERR_FILENO, ASL_LOG_DESCRIPTOR_WRITE);
- }
-# if MAC_OS_X_VERSION_MIN_REQUIRED < 1080
- else {
- xq_asl_capture_fd(aslc, NULL, ASL_LEVEL_INFO, STDOUT_FILENO);
- xq_asl_capture_fd(aslc, NULL, ASL_LEVEL_NOTICE, STDERR_FILENO);
- }
-# endif
-#else
- xq_asl_capture_fd(aslc, NULL, ASL_LEVEL_INFO, STDOUT_FILENO);
- xq_asl_capture_fd(aslc, NULL, ASL_LEVEL_NOTICE, STDERR_FILENO);
-#endif
+ asl_log_descriptor(aslc, NULL, ASL_LEVEL_INFO, STDOUT_FILENO, ASL_LOG_DESCRIPTOR_WRITE);
+ asl_log_descriptor(aslc, NULL, ASL_LEVEL_NOTICE, STDERR_FILENO, ASL_LOG_DESCRIPTOR_WRITE);
}
static void