diff options
author | Matthieu Herrb <matthieu@cvs.openbsd.org> | 2019-07-27 07:57:27 +0000 |
---|---|---|
committer | Matthieu Herrb <matthieu@cvs.openbsd.org> | 2019-07-27 07:57:27 +0000 |
commit | d4a0bed4b91da9de86c311c7fef9a8aa9a6f500c (patch) | |
tree | a1b439049dee87bc951e190db93f5bbe8b43b0b5 /xserver/os | |
parent | b6bc775539a31f663f9e22ce3ccaf0aa96adf3b6 (diff) |
Update to xserver 1.20.5. Tested by jsg@
Diffstat (limited to 'xserver/os')
-rw-r--r-- | xserver/os/Makefile.in | 14 | ||||
-rw-r--r-- | xserver/os/WaitFor.c | 24 | ||||
-rw-r--r-- | xserver/os/auth.c | 16 | ||||
-rw-r--r-- | xserver/os/backtrace.c | 1 | ||||
-rw-r--r-- | xserver/os/client.c | 86 | ||||
-rw-r--r-- | xserver/os/connection.c | 154 | ||||
-rw-r--r-- | xserver/os/inputthread.c | 2 | ||||
-rw-r--r-- | xserver/os/io.c | 37 | ||||
-rw-r--r-- | xserver/os/log.c | 4 | ||||
-rw-r--r-- | xserver/os/mitauth.c | 4 | ||||
-rw-r--r-- | xserver/os/oscolor.c | 5 | ||||
-rw-r--r-- | xserver/os/osdep.h | 31 | ||||
-rw-r--r-- | xserver/os/osinit.c | 6 | ||||
-rw-r--r-- | xserver/os/ospoll.c | 276 | ||||
-rw-r--r-- | xserver/os/timingsafe_memcmp.c | 2 | ||||
-rw-r--r-- | xserver/os/utils.c | 105 | ||||
-rw-r--r-- | xserver/os/xdmcp.c | 12 |
17 files changed, 476 insertions, 303 deletions
diff --git a/xserver/os/Makefile.in b/xserver/os/Makefile.in index 2589f56c7..a9089ae6b 100644 --- a/xserver/os/Makefile.in +++ b/xserver/os/Makefile.in @@ -78,7 +78,7 @@ CONFIG_HEADER = $(top_builddir)/include/do-not-use-config.h \ $(top_builddir)/include/xorg-config.h \ $(top_builddir)/include/xkb-config.h \ $(top_builddir)/include/xwin-config.h \ - $(top_builddir)/include/kdrive-config.h \ + $(top_builddir)/include/xwayland-config.h \ $(top_builddir)/include/version-config.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = @@ -345,6 +345,7 @@ RANLIB = @RANLIB@ RAWCPP = @RAWCPP@ RAWCPPFLAGS = @RAWCPPFLAGS@ RELEASE_DATE = @RELEASE_DATE@ +SCANNER_ARG = @SCANNER_ARG@ SDK_REQUIRED_MODULES = @SDK_REQUIRED_MODULES@ SED = @SED@ SELINUX_CFLAGS = @SELINUX_CFLAGS@ @@ -363,15 +364,18 @@ SYSCONFDIR = @SYSCONFDIR@ SYSTEMD_DAEMON_CFLAGS = @SYSTEMD_DAEMON_CFLAGS@ SYSTEMD_DAEMON_LIBS = @SYSTEMD_DAEMON_LIBS@ TRADITIONALCPPFLAGS = @TRADITIONALCPPFLAGS@ -TSLIB_CFLAGS = @TSLIB_CFLAGS@ -TSLIB_LIBS = @TSLIB_LIBS@ UDEV_CFLAGS = @UDEV_CFLAGS@ UDEV_LIBS = @UDEV_LIBS@ UTILS_SYS_LIBS = @UTILS_SYS_LIBS@ VENDOR_NAME_SHORT = @VENDOR_NAME_SHORT@ VERSION = @VERSION@ +WAYLAND_EGLSTREAM_CFLAGS = @WAYLAND_EGLSTREAM_CFLAGS@ +WAYLAND_EGLSTREAM_DATADIR = @WAYLAND_EGLSTREAM_DATADIR@ +WAYLAND_EGLSTREAM_LIBS = @WAYLAND_EGLSTREAM_LIBS@ WAYLAND_PROTOCOLS_DATADIR = @WAYLAND_PROTOCOLS_DATADIR@ WAYLAND_SCANNER = @WAYLAND_SCANNER@ +WAYLAND_SCANNER_CFLAGS = @WAYLAND_SCANNER_CFLAGS@ +WAYLAND_SCANNER_LIBS = @WAYLAND_SCANNER_LIBS@ WINDOWSDRI_CFLAGS = @WINDOWSDRI_CFLAGS@ WINDOWSDRI_LIBS = @WINDOWSDRI_LIBS@ WINDOWSWM_CFLAGS = @WINDOWSWM_CFLAGS@ @@ -379,6 +383,8 @@ WINDOWSWM_LIBS = @WINDOWSWM_LIBS@ WINDRES = @WINDRES@ X11EXAMPLES_DEP_CFLAGS = @X11EXAMPLES_DEP_CFLAGS@ X11EXAMPLES_DEP_LIBS = @X11EXAMPLES_DEP_LIBS@ +XCONFIGDIR = @XCONFIGDIR@ +XCONFIGFILE = @XCONFIGFILE@ XDMCP_CFLAGS = @XDMCP_CFLAGS@ XDMCP_LIBS = @XDMCP_LIBS@ XDMXCONFIG_DEP_CFLAGS = @XDMXCONFIG_DEP_CFLAGS@ @@ -450,8 +456,6 @@ XWIN_SERVER_NAME = @XWIN_SERVER_NAME@ XWIN_SYS_LIBS = @XWIN_SYS_LIBS@ YACC = @YACC@ YFLAGS = @YFLAGS@ -__XCONFIGDIR__ = @__XCONFIGDIR__@ -__XCONFIGFILE__ = @__XCONFIGFILE__@ abi_ansic = @abi_ansic@ abi_extension = @abi_extension@ abi_videodrv = @abi_videodrv@ diff --git a/xserver/os/WaitFor.c b/xserver/os/WaitFor.c index 613608faf..dc33c1648 100644 --- a/xserver/os/WaitFor.c +++ b/xserver/os/WaitFor.c @@ -90,24 +90,6 @@ SOFTWARE. #define GetErrno() errno #endif -/* like ffs, but uses fd_mask instead of int as argument, so it works - when fd_mask is longer than an int, such as common 64-bit platforms */ -/* modifications by raphael */ -int -mffs(fd_mask mask) -{ - int i; - - if (!mask) - return 0; - i = 1; - while (!(mask & 1)) { - i++; - mask >>= 1; - } - return i; -} - #ifdef DPMSExtension #include <X11/extensions/dpmsconst.h> #endif @@ -208,13 +190,13 @@ WaitForSomething(Bool are_ready) /* deal with any blocked jobs */ if (workQueue) { ProcessWorkQueue(); - are_ready = clients_are_ready(); } + timeout = check_timers(); + are_ready = clients_are_ready(); + if (are_ready) timeout = 0; - else - timeout = check_timers(); BlockHandler(&timeout); if (NewOutputPending) diff --git a/xserver/os/auth.c b/xserver/os/auth.c index c7b333ca2..d3254349d 100644 --- a/xserver/os/auth.c +++ b/xserver/os/auth.c @@ -42,6 +42,7 @@ from The Open Group. #include "dixstruct.h" #include <sys/types.h> #include <sys/stat.h> +#include <errno.h> #ifdef WIN32 #include <X11/Xw32defs.h> #endif @@ -90,8 +91,7 @@ static struct protocol protocols[] = { #endif }; -#define NUM_AUTHORIZATION (sizeof (protocols) /\ - sizeof (struct protocol)) +#define NUM_AUTHORIZATION ARRAY_SIZE(protocols) /* * Initialize all classes of authorization by reading the @@ -120,9 +120,15 @@ LoadAuthorization(void) if (!authorization_file) return 0; + errno = 0; f = Fopen(authorization_file, "r"); - if (!f) + if (!f) { + LogMessageVerb(X_ERROR, 0, + "Failed to open authorization file \"%s\": %s\n", + authorization_file, + errno != 0 ? strerror(errno) : "Unknown error"); return -1; + } while ((auth = XauReadAuth(f)) != 0) { for (i = 0; i < NUM_AUTHORIZATION; i++) { @@ -302,6 +308,8 @@ GenerateAuthorization(unsigned name_length, return -1; } +#endif /* XCSECURITY */ + void GenerateRandomData(int len, char *buf) { @@ -315,5 +323,3 @@ GenerateRandomData(int len, char *buf) close(fd); #endif } - -#endif /* XCSECURITY */ diff --git a/xserver/os/backtrace.c b/xserver/os/backtrace.c index 9e3e38edf..619bf145e 100644 --- a/xserver/os/backtrace.c +++ b/xserver/os/backtrace.c @@ -78,6 +78,7 @@ xorg_backtrace(void) break; } + off = 0; ret = unw_get_proc_name(&cursor, procname, 256, &off); if (ret && ret != -UNW_ENOMEM) { if (ret != -UNW_EUNSPEC) diff --git a/xserver/os/client.c b/xserver/os/client.c index ef5e3935d..213492d6c 100644 --- a/xserver/os/client.c +++ b/xserver/os/client.c @@ -142,45 +142,7 @@ DetermineClientCmd(pid_t pid, const char **cmdname, const char **cmdargs) if (pid == -1) return; -#ifdef __sun /* Solaris */ - /* Solaris does not support /proc/pid/cmdline, but makes information - * similar to what ps shows available in a binary structure in the - * /proc/pid/psinfo file. */ - if (snprintf(path, sizeof(path), "/proc/%d/psinfo", pid) < 0) - return; - fd = open(path, O_RDONLY); - if (fd < 0) { - ErrorF("Failed to open %s: %s\n", path, strerror(errno)); - return; - } - else { - psinfo_t psinfo = { 0 }; - char *sp; - - totsize = read(fd, &psinfo, sizeof(psinfo_t)); - close(fd); - if (totsize <= 0) - return; - - /* pr_psargs is the first PRARGSZ (80) characters of the command - * line string - assume up to the first space is the command name, - * since it's not delimited. While there is also pr_fname, that's - * more limited, giving only the first 16 chars of the basename of - * the file that was exec'ed, thus cutting off many long gnome - * command names, or returning "isapython2.6" for all python scripts. - */ - psinfo.pr_psargs[PRARGSZ - 1] = '\0'; - sp = strchr(psinfo.pr_psargs, ' '); - if (sp) - *sp++ = '\0'; - - if (cmdname) - *cmdname = strdup(psinfo.pr_psargs); - - if (cmdargs && sp) - *cmdargs = strdup(sp); - } -#elif defined(__OpenBSD__) +#if defined(__OpenBSD__) /* on OpenBSD use kvm_getargv() */ { kvm_t *kd; @@ -221,7 +183,11 @@ DetermineClientCmd(pid_t pid, const char **cmdname, const char **cmdargs) return; fd = open(path, O_RDONLY); if (fd < 0) +#ifdef __sun + goto fallback; +#else return; +#endif /* Read the contents of /proc/pid/cmdline. It should contain the * process name and arguments. */ @@ -256,6 +222,48 @@ DetermineClientCmd(pid_t pid, const char **cmdname, const char **cmdargs) *cmdargs = args; } } + return; +#endif + +#ifdef __sun /* Solaris */ + fallback: + /* Solaris prior to 11.3.5 does not support /proc/pid/cmdline, but + * makes information similar to what ps shows available in a binary + * structure in the /proc/pid/psinfo file. */ + if (snprintf(path, sizeof(path), "/proc/%d/psinfo", pid) < 0) + return; + fd = open(path, O_RDONLY); + if (fd < 0) { + ErrorF("Failed to open %s: %s\n", path, strerror(errno)); + return; + } + else { + psinfo_t psinfo = { 0 }; + char *sp; + + totsize = read(fd, &psinfo, sizeof(psinfo_t)); + close(fd); + if (totsize <= 0) + return; + + /* pr_psargs is the first PRARGSZ (80) characters of the command + * line string - assume up to the first space is the command name, + * since it's not delimited. While there is also pr_fname, that's + * more limited, giving only the first 16 chars of the basename of + * the file that was exec'ed, thus cutting off many long gnome + * command names, or returning "isapython2.6" for all python scripts. + */ + psinfo.pr_psargs[PRARGSZ - 1] = '\0'; + sp = strchr(psinfo.pr_psargs, ' '); + if (sp) + *sp++ = '\0'; + + if (cmdname) + *cmdname = strdup(psinfo.pr_psargs); + + if (cmdargs && sp) + *cmdargs = strdup(sp); + } #endif } diff --git a/xserver/os/connection.c b/xserver/os/connection.c index 862f6c622..3a083c01c 100644 --- a/xserver/os/connection.c +++ b/xserver/os/connection.c @@ -142,96 +142,6 @@ set_poll_client(ClientPtr client); static void set_poll_clients(void); -#if !defined(WIN32) -int *ConnectionTranslation = NULL; -int ConnectionTranslationSize = 0; -#else -/* - * On NT fds are not small integers, they are unrelated, and there is - * not even a known maximum value, so use something quite arbitrary for now. - * Do storage is a hash table of size 256. Collisions are handled in a linked - * list. - */ - -struct _ct_node { - struct _ct_node *next; - int key; - int value; -}; - -struct _ct_node *ct_head[256]; - -void -InitConnectionTranslation(void) -{ - memset(ct_head, 0, sizeof(ct_head)); -} - -int -GetConnectionTranslation(int conn) -{ - struct _ct_node *node = ct_head[conn & 0xff]; - - while (node != NULL) { - if (node->key == conn) - return node->value; - node = node->next; - } - return 0; -} - -void -SetConnectionTranslation(int conn, int client) -{ - struct _ct_node **node = ct_head + (conn & 0xff); - - if (client == 0) { /* remove entry */ - while (*node != NULL) { - if ((*node)->key == conn) { - struct _ct_node *temp = *node; - - *node = (*node)->next; - free(temp); - return; - } - node = &((*node)->next); - } - return; - } - else { - while (*node != NULL) { - if ((*node)->key == conn) { - (*node)->value = client; - return; - } - node = &((*node)->next); - } - *node = malloc(sizeof(struct _ct_node)); - (*node)->next = NULL; - (*node)->key = conn; - (*node)->value = client; - return; - } -} - -void -ClearConnectionTranslation(void) -{ - unsigned i; - - for (i = 0; i < 256; i++) { - struct _ct_node *node = ct_head[i]; - - while (node != NULL) { - struct _ct_node *temp = node; - - node = node->next; - free(temp); - } - } -} -#endif - static XtransConnInfo *ListenTransConns = NULL; static int *ListenTransFds = NULL; static int ListenTransCount; @@ -252,7 +162,7 @@ lookup_trans_conn(int fd) return NULL; } -/* Set MaxClients and lastfdesc, and allocate ConnectionTranslation */ +/* Set MaxClients */ void InitConnectionLimits(void) @@ -262,15 +172,6 @@ InitConnectionLimits(void) #ifdef DEBUG ErrorF("InitConnectionLimits: MaxClients = %d\n", MaxClients); #endif - -#if !defined(WIN32) - if (!ConnectionTranslation) { - ConnectionTranslation = xnfallocarray(MaxClients, sizeof(int)); - ConnectionTranslationSize = MaxClients; - } -#else - InitConnectionTranslation(); -#endif } /* @@ -352,13 +253,6 @@ CreateWellKnownSockets(void) int i; int partial; -#if !defined(WIN32) - for (i = 0; i < ConnectionTranslationSize; i++) - ConnectionTranslation[i] = 0; -#else - ClearConnectionTranslation(); -#endif - /* display is initialized to "0" by main(). It is then set to the display * number if specified on the command line. */ @@ -744,15 +638,6 @@ AllocNewConnection(XtransConnInfo trans_conn, int fd, CARD32 conn_time) return NullClient; } client->local = ComputeLocalClient(client); -#if !defined(WIN32) - if (fd >= ConnectionTranslationSize) { - ConnectionTranslationSize *= 2; - ConnectionTranslation = xnfreallocarray(ConnectionTranslation, ConnectionTranslationSize, sizeof (int)); - } - ConnectionTranslation[fd] = client->index; -#else - SetConnectionTranslation(fd, client->index); -#endif ospoll_add(server_poll, fd, ospoll_trigger_edge, ClientReady, @@ -788,7 +673,6 @@ EstablishNewConnections(ClientPtr clientUnused, void *closure) OsCommPtr oc; XtransConnInfo trans_conn, new_trans_conn; int status; - int clientid; connect_time = GetTimeInMillis(); /* kill off stragglers */ @@ -810,10 +694,6 @@ EstablishNewConnections(ClientPtr clientUnused, void *closure) newconn = _XSERVTransGetConnectionNumber(new_trans_conn); - clientid = GetConnectionTranslation(newconn); - if (clientid && (client = clients[clientid])) - CloseDownClient(client); - _XSERVTransSetOption(new_trans_conn, TRANS_NONBLOCKING, 1); if (trans_conn->flags & TRANS_NOXAUTH) @@ -884,24 +764,23 @@ ErrorConnMax(XtransConnInfo trans_conn) /************ * CloseDownFileDescriptor: - * Remove this file descriptor and it's I/O buffers, etc. + * Remove this file descriptor ************/ -static void +void CloseDownFileDescriptor(OsCommPtr oc) { - int connection = oc->fd; - if (oc->trans_conn) { + int connection = oc->fd; +#ifdef XDMCP + XdmcpCloseDisplay(connection); +#endif + ospoll_remove(server_poll, connection); _XSERVTransDisconnect(oc->trans_conn); _XSERVTransClose(oc->trans_conn); + oc->trans_conn = NULL; + oc->fd = -1; } -#ifndef WIN32 - ConnectionTranslation[connection] = 0; -#else - SetConnectionTranslation(connection, 0); -#endif - ospoll_remove(server_poll, connection); } /***************** @@ -919,9 +798,6 @@ CloseDownConnection(ClientPtr client) if (oc->output) FlushClient(client, oc, (char *) NULL, 0); -#ifdef XDMCP - XdmcpCloseDisplay(oc->fd); -#endif CloseDownFileDescriptor(oc); FreeOsBuffers(oc); free(client->osPrivate); @@ -1216,10 +1092,12 @@ set_poll_client(ClientPtr client) { OsCommPtr oc = (OsCommPtr) client->osPrivate; - if (listen_to_client(client)) - ospoll_listen(server_poll, oc->fd, X_NOTIFY_READ); - else - ospoll_mute(server_poll, oc->fd, X_NOTIFY_READ); + if (oc->trans_conn) { + if (listen_to_client(client)) + ospoll_listen(server_poll, oc->trans_conn->fd, X_NOTIFY_READ); + else + ospoll_mute(server_poll, oc->trans_conn->fd, X_NOTIFY_READ); + } } static void diff --git a/xserver/os/inputthread.c b/xserver/os/inputthread.c index dc4eb9f20..97e59d21f 100644 --- a/xserver/os/inputthread.c +++ b/xserver/os/inputthread.c @@ -410,6 +410,8 @@ InputThreadPreInit(void) if (!inputThreadInfo) FatalError("input-thread: could not allocate memory"); + inputThreadInfo->changed = FALSE; + inputThreadInfo->thread = 0; xorg_list_init(&inputThreadInfo->devs); inputThreadInfo->fds = ospoll_create(); diff --git a/xserver/os/io.c b/xserver/os/io.c index 70f07f3be..b099f0967 100644 --- a/xserver/os/io.c +++ b/xserver/os/io.c @@ -108,15 +108,14 @@ static ConnectionOutputPtr FreeOutputs = (ConnectionOutputPtr) NULL; static OsCommPtr AvailableInput = (OsCommPtr) NULL; #define get_req_len(req,cli) ((cli)->swapped ? \ - lswaps((req)->length) : (req)->length) + bswap_16((req)->length) : (req)->length) #include <X11/extensions/bigreqsproto.h> #define get_big_req_len(req,cli) ((cli)->swapped ? \ - lswapl(((xBigReq *)(req))->length) : \ + bswap_32(((xBigReq *)(req))->length) : \ ((xBigReq *)(req))->length) -#define MAX_TIMES_PER 10 #define BUFSIZE 16384 #define BUFWATERMARK 32768 @@ -184,10 +183,12 @@ YieldControl(void) } static void -YieldControlNoInput(int fd) +YieldControlNoInput(ClientPtr client) { + OsCommPtr oc = client->osPrivate; YieldControl(); - ospoll_reset_events(server_poll, fd); + if (oc->trans_conn) + ospoll_reset_events(server_poll, oc->fd); } static void @@ -227,7 +228,6 @@ ReadRequestFromClient(ClientPtr client) { OsCommPtr oc = (OsCommPtr) client->osPrivate; ConnectionInputPtr oci = oc->input; - int fd = oc->fd; unsigned int gotnow, needed; int result; register xReq *request; @@ -358,7 +358,7 @@ ReadRequestFromClient(ClientPtr client) if (0) #endif { - YieldControlNoInput(fd); + YieldControlNoInput(client); return 0; } } @@ -395,7 +395,7 @@ ReadRequestFromClient(ClientPtr client) } if (gotnow < needed) { /* Still don't have enough; punt. */ - YieldControlNoInput(fd); + YieldControlNoInput(client); return 0; } } @@ -464,12 +464,12 @@ ReadRequestFromClient(ClientPtr client) return needed; } -#if XTRANS_SEND_FDS int ReadFdFromClient(ClientPtr client) { int fd = -1; +#if XTRANS_SEND_FDS if (client->req_fds > 0) { OsCommPtr oc = (OsCommPtr) client->osPrivate; @@ -477,17 +477,22 @@ ReadFdFromClient(ClientPtr client) fd = _XSERVTransRecvFd(oc->trans_conn); } else LogMessage(X_ERROR, "Request asks for FD without setting req_fds\n"); +#endif + return fd; } int WriteFdToClient(ClientPtr client, int fd, Bool do_close) { +#if XTRANS_SEND_FDS OsCommPtr oc = (OsCommPtr) client->osPrivate; return _XSERVTransSendFd(oc->trans_conn, fd, do_close); -} +#else + return -1; #endif +} /***************************************************************** * InsertFakeRequest @@ -500,7 +505,6 @@ InsertFakeRequest(ClientPtr client, char *data, int count) { OsCommPtr oc = (OsCommPtr) client->osPrivate; ConnectionInputPtr oci = oc->input; - int fd = oc->fd; int gotnow, moveup; NextAvailableInput(oc); @@ -539,7 +543,7 @@ InsertFakeRequest(ClientPtr client, char *data, int count) (gotnow >= (int) (get_req_len((xReq *) oci->bufptr, client) << 2))) mark_client_ready(client); else - YieldControlNoInput(fd); + YieldControlNoInput(client); return TRUE; } @@ -554,7 +558,6 @@ ResetCurrentRequest(ClientPtr client) { OsCommPtr oc = (OsCommPtr) client->osPrivate; register ConnectionInputPtr oci = oc->input; - int fd = oc->fd; register xReq *request; int gotnow, needed; @@ -563,7 +566,7 @@ ResetCurrentRequest(ClientPtr client) oci->lenLastReq = 0; gotnow = oci->bufcnt + oci->buffer - oci->bufptr; if (gotnow < sizeof(xReq)) { - YieldControlNoInput(fd); + YieldControlNoInput(client); } else { request = (xReq *) oci->bufptr; @@ -582,7 +585,7 @@ ResetCurrentRequest(ClientPtr client) YieldControl(); } else - YieldControlNoInput(fd); + YieldControlNoInput(client); } } @@ -653,9 +656,7 @@ AbortClient(ClientPtr client) OsCommPtr oc = client->osPrivate; if (oc->trans_conn) { - _XSERVTransDisconnect(oc->trans_conn); - _XSERVTransClose(oc->trans_conn); - oc->trans_conn = NULL; + CloseDownFileDescriptor(oc); mark_client_ready(client); } } diff --git a/xserver/os/log.c b/xserver/os/log.c index 91e55a532..803639ef0 100644 --- a/xserver/os/log.c +++ b/xserver/os/log.c @@ -194,6 +194,8 @@ LogFilePrep(const char *fname, const char *backup, const char *idstring) { char *logFileName = NULL; + /* the format string below is controlled by the user, + this code should never be called with elevated privileges */ if (asprintf(&logFileName, fname, idstring) == -1) FatalError("Cannot allocate space for the log file name\n"); @@ -296,7 +298,7 @@ LogInit(const char *fname, const char *backup) void LogSetDisplay(void) { - if (saved_log_fname) { + if (saved_log_fname && strstr(saved_log_fname, "%s")) { char *logFileName; logFileName = LogFilePrep(saved_log_fname, saved_log_backup, display); diff --git a/xserver/os/mitauth.c b/xserver/os/mitauth.c index e75d700e1..a268f62f9 100644 --- a/xserver/os/mitauth.c +++ b/xserver/os/mitauth.c @@ -133,8 +133,6 @@ MitRemoveCookie(unsigned short data_length, const char *data) return 0; } -#ifdef XCSECURITY - static char cookie[16]; /* 128 bits */ XID @@ -161,5 +159,3 @@ MitGenerateCookie(unsigned data_length, } return id; } - -#endif /* XCSECURITY */ diff --git a/xserver/os/oscolor.c b/xserver/os/oscolor.c index 017aab1f2..af83c6ada 100644 --- a/xserver/os/oscolor.c +++ b/xserver/os/oscolor.c @@ -49,6 +49,7 @@ SOFTWARE. #endif #include <X11/keysym.h> +#include "dix.h" #include "os.h" typedef struct _builtinColor { @@ -1628,8 +1629,6 @@ static const BuiltinColor BuiltinColors[] = { {154, 205, 50, 7602}, /* YellowGreen */ }; -#define NUM_BUILTIN_COLORS (sizeof (BuiltinColors) / sizeof (BuiltinColors[0])) - Bool OsLookupColor(int screen, char *name, @@ -1642,7 +1641,7 @@ OsLookupColor(int screen, int r; low = 0; - high = NUM_BUILTIN_COLORS - 1; + high = ARRAY_SIZE(BuiltinColors) - 1; while (high >= low) { mid = (low + high) / 2; c = &BuiltinColors[mid]; diff --git a/xserver/os/osdep.h b/xserver/os/osdep.h index 3cd1216a7..ff55f890b 100644 --- a/xserver/os/osdep.h +++ b/xserver/os/osdep.h @@ -55,14 +55,7 @@ SOFTWARE. #include <X11/Xdmcp.h> #endif -#ifdef _POSIX_SOURCE #include <limits.h> -#else -#define _POSIX_SOURCE -#include <limits.h> -#undef _POSIX_SOURCE -#endif - #include <stddef.h> #include <X11/Xos.h> @@ -140,6 +133,9 @@ extern int FlushClient(ClientPtr /*who */ , extern void FreeOsBuffers(OsCommPtr /*oc */ ); +void +CloseDownFileDescriptor(OsCommPtr oc); + #include "dix.h" #include "ospoll.h" @@ -148,31 +144,10 @@ extern struct ospoll *server_poll; Bool listen_to_client(ClientPtr client); -#if !defined(WIN32) || defined(__CYGWIN__) -extern int *ConnectionTranslation; -extern int ConnectionTranslationSize; -static inline int GetConnectionTranslation(int conn) { - if (conn >= ConnectionTranslationSize) - return 0; - return ConnectionTranslation[conn]; -} -#else -extern int GetConnectionTranslation(int conn); -extern void SetConnectionTranslation(int conn, int client); -extern void ClearConnectionTranslation(void); -#endif - extern Bool NewOutputPending; extern WorkQueuePtr workQueue; -/* in WaitFor.c */ -#if defined(WIN32) && !defined(__CYGWIN__) -typedef long int fd_mask; -#endif -#define ffs mffs -extern int mffs(fd_mask); - /* in access.c */ extern Bool ComputeLocalClient(ClientPtr client); diff --git a/xserver/os/osinit.c b/xserver/os/osinit.c index 684ee040a..a8aa8b0bc 100644 --- a/xserver/os/osinit.c +++ b/xserver/os/osinit.c @@ -52,6 +52,7 @@ SOFTWARE. #include <X11/X.h> #include "os.h" #include "osdep.h" +#include "opaque.h" #include <X11/Xos.h> #include <signal.h> #include <errno.h> @@ -74,8 +75,6 @@ SOFTWARE. #define ADMPATH "/usr/adm/X%smsgs" #endif -extern char *display; - #ifdef RLIMIT_DATA int limitDataSpace = -1; #endif @@ -151,6 +150,9 @@ OsSigHandler(int signo) } #endif + if (signo != SIGQUIT) + CoreDump = TRUE; + FatalError("Caught signal %d (%s). Server aborting\n", signo, strsignal(signo)); } diff --git a/xserver/os/ospoll.c b/xserver/os/ospoll.c index 51bd02dc7..db9e73811 100644 --- a/xserver/os/ospoll.c +++ b/xserver/os/ospoll.c @@ -32,7 +32,19 @@ #include "ospoll.h" #include "list.h" -#if !HAVE_OSPOLL && HAVE_EPOLL_CREATE1 +#if !HAVE_OSPOLL && defined(HAVE_POLLSET_CREATE) +#include <sys/pollset.h> +#define POLLSET 1 +#define HAVE_OSPOLL 1 +#endif + +#if !HAVE_OSPOLL && defined(HAVE_PORT_CREATE) +#include <port.h> +#define PORT 1 +#define HAVE_OSPOLL 1 +#endif + +#if !HAVE_OSPOLL && defined(HAVE_EPOLL_CREATE1) #include <sys/epoll.h> #define EPOLL 1 #define HAVE_OSPOLL 1 @@ -44,7 +56,28 @@ #define HAVE_OSPOLL 1 #endif -#if EPOLL +#if POLLSET + +// pollset-based implementation (as seen on AIX) +struct ospollfd { + int fd; + int xevents; + short revents; + enum ospoll_trigger trigger; + void (*callback)(int fd, int xevents, void *data); + void *data; +}; + +struct ospoll { + pollset_t ps; + struct ospollfd *fds; + int num; + int size; +}; + +#endif + +#if EPOLL || PORT #include <sys/epoll.h> /* epoll-based implementation */ @@ -101,10 +134,10 @@ ospoll_find(struct ospoll *ospoll, int fd) while (lo <= hi) { int m = (lo + hi) >> 1; -#if EPOLL +#if EPOLL || PORT int t = ospoll->fds[m]->fd; #endif -#if POLL +#if POLL || POLLSET int t = ospoll->fds[m].fd; #endif @@ -118,7 +151,7 @@ ospoll_find(struct ospoll *ospoll, int fd) return -(lo + 1); } -#if EPOLL +#if EPOLL || PORT static void ospoll_clean_deleted(struct ospoll *ospoll) { @@ -168,6 +201,27 @@ array_delete(void *base, size_t num, size_t size, size_t pos) struct ospoll * ospoll_create(void) { +#if POLLSET + struct ospoll *ospoll = calloc(1, sizeof (struct ospoll)); + + ospoll->ps = pollset_create(-1); + if (ospoll->ps < 0) { + free (ospoll); + return NULL; + } + return ospoll; +#endif +#if PORT + struct ospoll *ospoll = calloc(1, sizeof (struct ospoll)); + + ospoll->epoll_fd = port_create(); + if (ospoll->epoll_fd < 0) { + free (ospoll); + return NULL; + } + xorg_list_init(&ospoll->deleted); + return ospoll; +#endif #if EPOLL struct ospoll *ospoll = calloc(1, sizeof (struct ospoll)); @@ -187,7 +241,15 @@ ospoll_create(void) void ospoll_destroy(struct ospoll *ospoll) { -#if EPOLL +#if POLLSET + if (ospoll) { + assert (ospoll->num == 0); + pollset_destroy(ospoll->ps); + free(ospoll->fds); + free(ospoll); + } +#endif +#if EPOLL || PORT if (ospoll) { assert (ospoll->num == 0); close(ospoll->epoll_fd); @@ -213,6 +275,65 @@ ospoll_add(struct ospoll *ospoll, int fd, void *data) { int pos = ospoll_find(ospoll, fd); +#if POLLSET + if (pos < 0) { + if (ospoll->num == ospoll->size) { + struct ospollfd *new_fds; + int new_size = ospoll->size ? ospoll->size * 2 : MAXCLIENTS * 2; + + new_fds = reallocarray(ospoll->fds, new_size, sizeof (ospoll->fds[0])); + if (!new_fds) + return FALSE; + ospoll->fds = new_fds; + ospoll->size = new_size; + } + pos = -pos - 1; + array_insert(ospoll->fds, ospoll->num, sizeof (ospoll->fds[0]), pos); + ospoll->num++; + + ospoll->fds[pos].fd = fd; + ospoll->fds[pos].xevents = 0; + ospoll->fds[pos].revents = 0; + } + ospoll->fds[pos].trigger = trigger; + ospoll->fds[pos].callback = callback; + ospoll->fds[pos].data = data; +#endif +#if PORT + struct ospollfd *osfd; + + if (pos < 0) { + osfd = calloc(1, sizeof (struct ospollfd)); + if (!osfd) + return FALSE; + + if (ospoll->num >= ospoll->size) { + struct ospollfd **new_fds; + int new_size = ospoll->size ? ospoll->size * 2 : MAXCLIENTS * 2; + + new_fds = reallocarray(ospoll->fds, new_size, sizeof (ospoll->fds[0])); + if (!new_fds) { + free (osfd); + return FALSE; + } + ospoll->fds = new_fds; + ospoll->size = new_size; + } + + osfd->fd = fd; + osfd->xevents = 0; + + pos = -pos - 1; + array_insert(ospoll->fds, ospoll->num, sizeof (ospoll->fds[0]), pos); + ospoll->fds[pos] = osfd; + ospoll->num++; + } else { + osfd = ospoll->fds[pos]; + } + osfd->data = data; + osfd->callback = callback; + osfd->trigger = trigger; +#endif #if EPOLL struct ospollfd *osfd; @@ -301,6 +422,24 @@ ospoll_remove(struct ospoll *ospoll, int fd) pos = ospoll_find(ospoll, fd); if (pos >= 0) { +#if POLLSET + struct ospollfd *osfd = &ospoll->fds[pos]; + struct poll_ctl ctl = { .cmd = PS_DELETE, .fd = fd }; + pollset_ctl(ospoll->ps, &ctl, 1); + + array_delete(ospoll->fds, ospoll->num, sizeof (ospoll->fds[0]), pos); + ospoll->num--; +#endif +#if PORT + struct ospollfd *osfd = ospoll->fds[pos]; + port_dissociate(ospoll->epoll_fd, PORT_SOURCE_FD, fd); + + array_delete(ospoll->fds, ospoll->num, sizeof (ospoll->fds[0]), pos); + ospoll->num--; + osfd->callback = NULL; + osfd->data = NULL; + xorg_list_add(&osfd->deleted, &ospoll->deleted); +#endif #if EPOLL struct ospollfd *osfd = ospoll->fds[pos]; struct epoll_event ev; @@ -323,6 +462,19 @@ ospoll_remove(struct ospoll *ospoll, int fd) } } +#if PORT +static void +epoll_mod(struct ospoll *ospoll, struct ospollfd *osfd) +{ + int events = 0; + if (osfd->xevents & X_NOTIFY_READ) + events |= EPOLLIN; + if (osfd->xevents & X_NOTIFY_WRITE) + events |= EPOLLOUT; + port_associate(ospool->epoll_fd, PORT_SOURCE_FD, osfd->fd, events, osfd); +} +#endif + #if EPOLL static void epoll_mod(struct ospoll *ospoll, struct ospollfd *osfd) @@ -346,7 +498,20 @@ ospoll_listen(struct ospoll *ospoll, int fd, int xevents) int pos = ospoll_find(ospoll, fd); if (pos >= 0) { -#if EPOLL +#if POLLSET + struct poll_ctl ctl = { .cmd = PS_MOD, .fd = fd }; + if (xevents & X_NOTIFY_READ) { + ctl.events |= POLLIN; + ospoll->fds[pos].revents &= ~POLLIN; + } + if (xevents & X_NOTIFY_WRITE) { + ctl.events |= POLLOUT; + ospoll->fds[pos].revents &= ~POLLOUT; + } + pollset_ctl(ospoll->ps, &ctl, 1); + ospoll->fds[pos].xevents |= xevents; +#endif +#if EPOLL || PORT struct ospollfd *osfd = ospoll->fds[pos]; osfd->xevents |= xevents; epoll_mod(ospoll, osfd); @@ -370,7 +535,23 @@ ospoll_mute(struct ospoll *ospoll, int fd, int xevents) int pos = ospoll_find(ospoll, fd); if (pos >= 0) { -#if EPOLL +#if POLLSET + struct ospollfd *osfd = &ospoll->fds[pos]; + osfd->xevents &= ~xevents; + struct poll_ctl ctl = { .cmd = PS_DELETE, .fd = fd }; + pollset_ctl(ospoll->ps, &ctl, 1); + if (osfd->xevents) { + ctl.cmd = PS_ADD; + if (osfd->xevents & X_NOTIFY_READ) { + ctl.events |= POLLIN; + } + if (osfd->xevents & X_NOTIFY_WRITE) { + ctl.events |= POLLOUT; + } + pollset_ctl(ospoll->ps, &ctl, 1); + } +#endif +#if EPOLL || PORT struct ospollfd *osfd = ospoll->fds[pos]; osfd->xevents &= ~xevents; epoll_mod(ospoll, osfd); @@ -389,6 +570,64 @@ int ospoll_wait(struct ospoll *ospoll, int timeout) { int nready; +#if POLLSET +#define MAX_EVENTS 256 + struct pollfd events[MAX_EVENTS]; + + nready = pollset_poll(ospoll->ps, events, MAX_EVENTS, timeout); + for (int i = 0; i < nready; i++) { + struct pollfd *ev = &events[i]; + int pos = ospoll_find(ospoll, ev->fd); + struct ospollfd *osfd = &ospoll->fds[pos]; + short revents = ev->revents; + short oldevents = osfd->revents; + + osfd->revents = (revents & (POLLIN|POLLOUT)); + if (osfd->trigger == ospoll_trigger_edge) + revents &= ~oldevents; + if (revents) { + int xevents = 0; + if (revents & POLLIN) + xevents |= X_NOTIFY_READ; + if (revents & POLLOUT) + xevents |= X_NOTIFY_WRITE; + if (revents & (~(POLLIN|POLLOUT))) + xevents |= X_NOTIFY_ERROR; + osfd->callback(osfd->fd, xevents, osfd->data); + } + } +#endif +#if PORT +#define MAX_EVENTS 256 + port_event_t events[MAX_EVENTS]; + uint_t nget = 1; + + nready = 0; + if (port_getn(ospoll->epoll_fd, events, MAX_EVENTS, &nget, &timeout) == 0) { + nready = nget; + } + for (int i = 0; i < nready; i++) { + port_event_t *ev = &events[i]; + struct ospollfd *osfd = ev->portev_user; + uint32_t revents = ev->portev_events; + int xevents = 0; + + if (revents & EPOLLIN) + xevents |= X_NOTIFY_READ; + if (revents & EPOLLOUT) + xevents |= X_NOTIFY_WRITE; + if (revents & (~(EPOLLIN|EPOLLOUT))) + xevents |= X_NOTIFY_ERROR; + + if (osfd->callback) + osfd->callback(osfd->fd, xevents, osfd->data); + + if (osfd->trigger == ospoll_trigger_level && !osfd->deleted) { + epoll_mod(ospoll, osfd); + } + } + ospoll_clean_deleted(ospoll); +#endif #if EPOLL #define MAX_EVENTS 256 struct epoll_event events[MAX_EVENTS]; @@ -451,6 +690,22 @@ ospoll_wait(struct ospoll *ospoll, int timeout) void ospoll_reset_events(struct ospoll *ospoll, int fd) { +#if POLLSET + int pos = ospoll_find(ospoll, fd); + + if (pos < 0) + return; + + ospoll->fds[pos].revents = 0; +#endif +#if PORT + int pos = ospoll_find(ospoll, fd); + + if (pos < 0) + return; + + epoll_mod(ospoll, ospoll->fds[pos]); +#endif #if POLL int pos = ospoll_find(ospoll, fd); @@ -468,7 +723,10 @@ ospoll_data(struct ospoll *ospoll, int fd) if (pos < 0) return NULL; -#if EPOLL +#if POLLSET + return ospoll->fds[pos].data; +#endif +#if EPOLL || PORT return ospoll->fds[pos]->data; #endif #if POLL diff --git a/xserver/os/timingsafe_memcmp.c b/xserver/os/timingsafe_memcmp.c index 65679c87a..4eaba627e 100644 --- a/xserver/os/timingsafe_memcmp.c +++ b/xserver/os/timingsafe_memcmp.c @@ -14,10 +14,10 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include <dix-config.h> #include <limits.h> #include <string.h> #include <X11/Xfuncproto.h> -#include <dix-config.h> #include "os.h" int diff --git a/xserver/os/utils.c b/xserver/os/utils.c index 05dbeb781..331fe1aa2 100644 --- a/xserver/os/utils.c +++ b/xserver/os/utils.c @@ -83,19 +83,7 @@ __stdcall unsigned long GetTickCount(void); #include <X11/fonts/libxfont2.h> #include "osdep.h" #include "extension.h" -#ifdef X_POSIX_C_SOURCE -#define _POSIX_C_SOURCE X_POSIX_C_SOURCE #include <signal.h> -#undef _POSIX_C_SOURCE -#else -#if defined(_POSIX_SOURCE) -#include <signal.h> -#else -#define _POSIX_SOURCE -#include <signal.h> -#undef _POSIX_SOURCE -#endif -#endif #ifndef WIN32 #include <sys/wait.h> #endif @@ -135,6 +123,7 @@ Bool noDamageExtension = FALSE; Bool noDbeExtension = FALSE; #endif #ifdef DPMSExtension +#include "dpmsproc.h" Bool noDPMSExtension = FALSE; #endif #ifdef GLXEXT @@ -508,19 +497,20 @@ GetTimeInMicros(void) struct timeval tv; #ifdef MONOTONIC_CLOCK struct timespec tp; + static clockid_t uclockid; - if (!clockid) { + if (!uclockid) { if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0) - clockid = CLOCK_MONOTONIC; + uclockid = CLOCK_MONOTONIC; else - clockid = ~0L; + uclockid = ~0L; } - if (clockid != ~0L && clock_gettime(clockid, &tp) == 0) + if (uclockid != ~0L && clock_gettime(uclockid, &tp) == 0) return (CARD64) tp.tv_sec * (CARD64)1000000 + tp.tv_nsec / 1000; #endif X_GETTIMEOFDAY(&tv); - return (CARD64) tv.tv_sec * (CARD64)1000000000 + (CARD64) tv.tv_usec * 1000; + return (CARD64) tv.tv_sec * (CARD64)1000000 + (CARD64) tv.tv_usec; } #endif @@ -1028,7 +1018,7 @@ ProcessCommandLine(int argc, char *argv[]) #endif else if (strcmp(argv[i], "-dumbSched") == 0) { InputThreadEnable = FALSE; -#if HAVE_SETITIMER +#ifdef HAVE_SETITIMER SmartScheduleSignalEnable = FALSE; #endif } @@ -1230,7 +1220,7 @@ XNFstrdup(const char *s) void SmartScheduleStopTimer(void) { -#if HAVE_SETITIMER +#ifdef HAVE_SETITIMER struct itimerval timer; if (!SmartScheduleSignalEnable) @@ -1246,7 +1236,7 @@ SmartScheduleStopTimer(void) void SmartScheduleStartTimer(void) { -#if HAVE_SETITIMER +#ifdef HAVE_SETITIMER struct itimerval timer; if (!SmartScheduleSignalEnable) @@ -1259,7 +1249,7 @@ SmartScheduleStartTimer(void) #endif } -#if HAVE_SETITIMER +#ifdef HAVE_SETITIMER static void SmartScheduleTimer(int sig) { @@ -1307,7 +1297,7 @@ SmartSchedulePause(void) void SmartScheduleInit(void) { -#if HAVE_SETITIMER +#ifdef HAVE_SETITIMER if (SmartScheduleEnable() < 0) { perror("sigaction for smart scheduler"); SmartScheduleSignalEnable = FALSE; @@ -1464,7 +1454,7 @@ Popen(const char *command, const char *type) } /* Ignore the smart scheduler while this is going on */ -#if HAVE_SETITIMER +#ifdef HAVE_SETITIMER if (SmartSchedulePause() < 0) { close(pdes[0]); close(pdes[1]); @@ -1479,7 +1469,7 @@ Popen(const char *command, const char *type) close(pdes[0]); close(pdes[1]); free(cur); -#if HAVE_SETITIMER +#ifdef HAVE_SETITIMER if (SmartScheduleEnable() < 0) perror("signal"); #endif @@ -1656,7 +1646,7 @@ Pclose(void *iop) /* allow EINTR again */ OsReleaseSignals(); -#if HAVE_SETITIMER +#ifdef HAVE_SETITIMER if (SmartScheduleEnable() < 0) { perror("signal"); return -1; @@ -1751,6 +1741,69 @@ System(const char *cmdline) } #endif +Bool +PrivsElevated(void) +{ + static Bool privsTested = FALSE; + static Bool privsElevated = TRUE; + + if (!privsTested) { +#if defined(WIN32) + privsElevated = FALSE; +#else + if ((getuid() != geteuid()) || (getgid() != getegid())) { + privsElevated = TRUE; + } + else { +#if defined(HAVE_ISSETUGID) + privsElevated = issetugid(); +#elif defined(HAVE_GETRESUID) + uid_t ruid, euid, suid; + gid_t rgid, egid, sgid; + + if ((getresuid(&ruid, &euid, &suid) == 0) && + (getresgid(&rgid, &egid, &sgid) == 0)) { + privsElevated = (euid != suid) || (egid != sgid); + } + else { + printf("Failed getresuid or getresgid"); + /* Something went wrong, make defensive assumption */ + privsElevated = TRUE; + } +#else + if (getuid() == 0) { + /* running as root: uid==euid==0 */ + privsElevated = FALSE; + } + else { + /* + * If there are saved ID's the process might still be privileged + * even though the above test succeeded. If issetugid() and + * getresgid() aren't available, test this by trying to set + * euid to 0. + */ + unsigned int oldeuid; + + oldeuid = geteuid(); + + if (seteuid(0) != 0) { + privsElevated = FALSE; + } + else { + if (seteuid(oldeuid) != 0) { + FatalError("Failed to drop privileges. Exiting\n"); + } + privsElevated = TRUE; + } + } +#endif + } +#endif + privsTested = TRUE; + } + return privsElevated; +} + /* * CheckUserParameters: check for long command line arguments and long * environment variables. By default, these checks are only done when @@ -1832,7 +1885,7 @@ CheckUserParameters(int argc, char **argv, char **envp) char *a, *e = NULL; #if CHECK_EUID - if (geteuid() == 0 && getuid() != geteuid()) + if (PrivsElevated()) #endif { /* Check each argv[] */ diff --git a/xserver/os/xdmcp.c b/xserver/os/xdmcp.c index d8c81fbf8..62adead84 100644 --- a/xserver/os/xdmcp.c +++ b/xserver/os/xdmcp.c @@ -569,10 +569,9 @@ XdmcpRegisterDisplayClass(const char *name, int length) } static void -xdmcp_start(void) +xdmcp_reset(void) { timeOutRtx = 0; - get_xdmcp_sock(); if (xdmcpSocket >= 0) SetNotifyFd(xdmcpSocket, XdmcpSocketNotify, X_NOTIFY_READ, NULL); #if defined(IPv6) && defined(AF_INET6) @@ -583,6 +582,13 @@ xdmcp_start(void) send_packet(); } +static void +xdmcp_start(void) +{ + get_xdmcp_sock(); + xdmcp_reset(); +} + /* * initialize XDMCP; create the socket, compute the display * number, set up the state machine @@ -611,7 +617,7 @@ XdmcpReset(void) { state = XDM_INIT_STATE; if (state != XDM_OFF) - xdmcp_start(); + xdmcp_reset(); } /* |