From 9f000842951f6b5cb40208e9254c50ec56f143e6 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 10 Feb 2017 00:22:03 +0100 Subject: os/xdmcp: Just send XDMCP keepalive packets once every three minute Backported from X.org: commit db1089eafc1c5371fa0030202de588d2e2b4f8e5 Author: Keith Packard Date: Mon Sep 21 07:16:17 2015 +0100 os/xdmcp: Just send XDMCP keepalive packets once every three minutes There was a complicated scheme to increase the time between keepalives from 3 minutes up to as much as 24 hours in an attempt to reduce network traffic from idle X terminals. X terminals receiving X traffic, or receiving user input would use the 3 minute value; X terminals without any network traffic would use a longer value. However, this was actually broken -- any activity in the X server, either client requests or user input, would end up resetting the keepalive timeout, so a user mashing on the keyboard would never discover that the XDMCP master had disappeared and have the session terminated, which was precisely the design goal of the XDMCP keepalive mechanism. Instead of attempting to fix this, accept the cost of a pair of XDMCP packets once every three minutes and just perform keepalives regularly. This will also make reworking the block and wakeup handler APIs to eliminate select masks easier. Reviewed-by: Adam Jackson Signed-off-by: Keith Packard Backported-to-NX-by: Mike Gabriel --- nx-X11/programs/Xserver/os/xdmcp.c | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/nx-X11/programs/Xserver/os/xdmcp.c b/nx-X11/programs/Xserver/os/xdmcp.c index 83e234b43..c4b71f6ec 100644 --- a/nx-X11/programs/Xserver/os/xdmcp.c +++ b/nx-X11/programs/Xserver/os/xdmcp.c @@ -88,8 +88,6 @@ static int req_socklen; static CARD32 SessionID; static CARD32 timeOutTime; static int timeOutRtx; -static CARD32 defaultKeepaliveDormancy = XDM_DEF_DORMANCY; -static CARD32 keepaliveDormancy = XDM_DEF_DORMANCY; static CARD16 DisplayNumber; static xdmcp_states XDM_INIT_STATE = XDM_OFF; #ifdef HASXDMAUTH @@ -643,6 +641,7 @@ XdmcpOpenDisplay(int sock) if (state != XDM_AWAIT_MANAGE_RESPONSE) return; state = XDM_RUN_SESSION; + timeOutTime = GetTimeInMillis() + XDM_DEF_DORMANCY * 1000; sessionSocket = sock; } @@ -706,7 +705,6 @@ XdmcpWakeupHandler( void * pReadmask) { fd_set* LastSelectMask = (fd_set*)pReadmask; - fd_set devicesReadable; #ifdef NX_TRANS_SOCKET @@ -731,16 +729,6 @@ XdmcpWakeupHandler( FD_CLR(xdmcpSocket6, LastSelectMask); } #endif - XFD_ANDSET(&devicesReadable, LastSelectMask, &EnabledDevices); - if (XFD_ANYSET(&devicesReadable)) - { - if (state == XDM_AWAIT_USER_INPUT) - restart(); - else if (state == XDM_RUN_SESSION) - keepaliveDormancy = defaultKeepaliveDormancy; - } - if (XFD_ANYSET(&AllClients) && state == XDM_RUN_SESSION) - timeOutTime = GetTimeInMillis() + keepaliveDormancy * 1000; } else if (timeOutTime && (int) (GetTimeInMillis() - timeOutTime) >= 0) { @@ -1428,16 +1416,8 @@ recv_alive_msg (unsigned length) { if (SessionRunning && AliveSessionID == SessionID) { - /* backoff dormancy period */ state = XDM_RUN_SESSION; - if ((GetTimeInMillis() - lastDeviceEventTime.milliseconds) > - keepaliveDormancy * 1000) - { - keepaliveDormancy <<= 1; - if (keepaliveDormancy > XDM_MAX_DORMANCY) - keepaliveDormancy = XDM_MAX_DORMANCY; - } - timeOutTime = GetTimeInMillis() + keepaliveDormancy * 1000; + timeOutTime = GetTimeInMillis() + XDM_DEF_DORMANCY * 1000; } else { -- cgit v1.2.3 From 289e8ce5652dda788dbed25346b3b43af70c371c Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Thu, 9 Feb 2017 12:32:16 +0000 Subject: Xserver/include/list.h: Add list.h from X.org (from X.org commit 63f83d1). --- nx-X11/programs/Xserver/include/Imakefile | 1 + nx-X11/programs/Xserver/include/list.h | 494 ++++++++++++++++++++++++++++++ 2 files changed, 495 insertions(+) create mode 100644 nx-X11/programs/Xserver/include/list.h diff --git a/nx-X11/programs/Xserver/include/Imakefile b/nx-X11/programs/Xserver/include/Imakefile index 8c89fbc2b..d1d7bd651 100644 --- a/nx-X11/programs/Xserver/include/Imakefile +++ b/nx-X11/programs/Xserver/include/Imakefile @@ -30,6 +30,7 @@ InstallDriverSDKNonExecFile(gcstruct.h,$(DRIVERSDKINCLUDEDIR)) InstallDriverSDKNonExecFile(globals.h,$(DRIVERSDKINCLUDEDIR)) InstallDriverSDKNonExecFile(input.h,$(DRIVERSDKINCLUDEDIR)) InstallDriverSDKNonExecFile(inputstr.h,$(DRIVERSDKINCLUDEDIR)) +InstallDriverSDKNonExecFile(list.h,$(DRIVERSDKINCLUDEDIR)) InstallDriverSDKNonExecFile(misc.h,$(DRIVERSDKINCLUDEDIR)) InstallDriverSDKNonExecFile(miscstruct.h,$(DRIVERSDKINCLUDEDIR)) InstallDriverSDKNonExecFile(opaque.h,$(DRIVERSDKINCLUDEDIR)) diff --git a/nx-X11/programs/Xserver/include/list.h b/nx-X11/programs/Xserver/include/list.h new file mode 100644 index 000000000..3f0574d43 --- /dev/null +++ b/nx-X11/programs/Xserver/include/list.h @@ -0,0 +1,494 @@ +/* + * Copyright © 2010 Intel Corporation + * Copyright © 2010 Francisco Jerez + * + * 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 (including the next + * paragraph) 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 AUTHORS OR COPYRIGHT HOLDERS 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. + * + */ + +#ifndef _XORG_LIST_H_ +#define _XORG_LIST_H_ + +#include /* offsetof() */ + +/** + * @file Classic doubly-link circular list implementation. + * For real usage examples of the linked list, see the file test/list.c + * + * Example: + * We need to keep a list of struct foo in the parent struct bar, i.e. what + * we want is something like this. + * + * struct bar { + * ... + * struct foo *list_of_foos; -----> struct foo {}, struct foo {}, struct foo{} + * ... + * } + * + * We need one list head in bar and a list element in all list_of_foos (both are of + * data type 'struct xorg_list'). + * + * struct bar { + * ... + * struct xorg_list list_of_foos; + * ... + * } + * + * struct foo { + * ... + * struct xorg_list entry; + * ... + * } + * + * Now we initialize the list head: + * + * struct bar bar; + * ... + * xorg_list_init(&bar.list_of_foos); + * + * Then we create the first element and add it to this list: + * + * struct foo *foo = malloc(...); + * .... + * xorg_list_add(&foo->entry, &bar.list_of_foos); + * + * Repeat the above for each element you want to add to the list. Deleting + * works with the element itself. + * xorg_list_del(&foo->entry); + * free(foo); + * + * Note: calling xorg_list_del(&bar.list_of_foos) will set bar.list_of_foos to an empty + * list again. + * + * Looping through the list requires a 'struct foo' as iterator and the + * name of the field the subnodes use. + * + * struct foo *iterator; + * xorg_list_for_each_entry(iterator, &bar.list_of_foos, entry) { + * if (iterator->something == ...) + * ... + * } + * + * Note: You must not call xorg_list_del() on the iterator if you continue the + * loop. You need to run the safe for-each loop instead: + * + * struct foo *iterator, *next; + * xorg_list_for_each_entry_safe(iterator, next, &bar.list_of_foos, entry) { + * if (...) + * xorg_list_del(&iterator->entry); + * } + * + */ + +/** + * The linkage struct for list nodes. This struct must be part of your + * to-be-linked struct. struct xorg_list is required for both the head of the + * list and for each list node. + * + * Position and name of the struct xorg_list field is irrelevant. + * There are no requirements that elements of a list are of the same type. + * There are no requirements for a list head, any struct xorg_list can be a list + * head. + */ +struct xorg_list { + struct xorg_list *next, *prev; +}; + +/** + * Initialize the list as an empty list. + * + * Example: + * xorg_list_init(&bar->list_of_foos); + * + * @param list The list to initialize + */ +static inline void +xorg_list_init(struct xorg_list *list) +{ + list->next = list->prev = list; +} + +static inline void +__xorg_list_add(struct xorg_list *entry, + struct xorg_list *prev, struct xorg_list *next) +{ + next->prev = entry; + entry->next = next; + entry->prev = prev; + prev->next = entry; +} + +/** + * Insert a new element after the given list head. The new element does not + * need to be initialised as empty list. + * The list changes from: + * head → some element → ... + * to + * head → new element → older element → ... + * + * Example: + * struct foo *newfoo = malloc(...); + * xorg_list_add(&newfoo->entry, &bar->list_of_foos); + * + * @param entry The new element to prepend to the list. + * @param head The existing list. + */ +static inline void +xorg_list_add(struct xorg_list *entry, struct xorg_list *head) +{ + __xorg_list_add(entry, head, head->next); +} + +/** + * Append a new element to the end of the list given with this list head. + * + * The list changes from: + * head → some element → ... → lastelement + * to + * head → some element → ... → lastelement → new element + * + * Example: + * struct foo *newfoo = malloc(...); + * xorg_list_append(&newfoo->entry, &bar->list_of_foos); + * + * @param entry The new element to prepend to the list. + * @param head The existing list. + */ +static inline void +xorg_list_append(struct xorg_list *entry, struct xorg_list *head) +{ + __xorg_list_add(entry, head->prev, head); +} + +static inline void +__xorg_list_del(struct xorg_list *prev, struct xorg_list *next) +{ + next->prev = prev; + prev->next = next; +} + +/** + * Remove the element from the list it is in. Using this function will reset + * the pointers to/from this element so it is removed from the list. It does + * NOT free the element itself or manipulate it otherwise. + * + * Using xorg_list_del on a pure list head (like in the example at the top of + * this file) will NOT remove the first element from + * the list but rather reset the list as empty list. + * + * Example: + * xorg_list_del(&foo->entry); + * + * @param entry The element to remove. + */ +static inline void +xorg_list_del(struct xorg_list *entry) +{ + __xorg_list_del(entry->prev, entry->next); + xorg_list_init(entry); +} + +/** + * Check if the list is empty. + * + * Example: + * xorg_list_is_empty(&bar->list_of_foos); + * + * @return True if the list contains one or more elements or False otherwise. + */ +static inline int +xorg_list_is_empty(struct xorg_list *head) +{ + return head->next == head; +} + +/** + * Returns a pointer to the container of this list element. + * + * Example: + * struct foo* f; + * f = container_of(&foo->entry, struct foo, entry); + * assert(f == foo); + * + * @param ptr Pointer to the struct xorg_list. + * @param type Data type of the list element. + * @param member Member name of the struct xorg_list field in the list element. + * @return A pointer to the data struct containing the list head. + */ +#ifndef container_of +#define container_of(ptr, type, member) \ + (type *)((char *)(ptr) - offsetof(type, member)) +#endif + +/** + * Alias of container_of + */ +#define xorg_list_entry(ptr, type, member) \ + container_of(ptr, type, member) + +/** + * Retrieve the first list entry for the given list pointer. + * + * Example: + * struct foo *first; + * first = xorg_list_first_entry(&bar->list_of_foos, struct foo, list_of_foos); + * + * @param ptr The list head + * @param type Data type of the list element to retrieve + * @param member Member name of the struct xorg_list field in the list element. + * @return A pointer to the first list element. + */ +#define xorg_list_first_entry(ptr, type, member) \ + xorg_list_entry((ptr)->next, type, member) + +/** + * Retrieve the last list entry for the given listpointer. + * + * Example: + * struct foo *first; + * first = xorg_list_last_entry(&bar->list_of_foos, struct foo, list_of_foos); + * + * @param ptr The list head + * @param type Data type of the list element to retrieve + * @param member Member name of the struct xorg_list field in the list element. + * @return A pointer to the last list element. + */ +#define xorg_list_last_entry(ptr, type, member) \ + xorg_list_entry((ptr)->prev, type, member) + +#ifdef HAVE_TYPEOF +#define __container_of(ptr, sample, member) \ + container_of(ptr, typeof(*sample), member) +#else +/* This implementation of __container_of has undefined behavior according + * to the C standard, but it works in many cases. If your compiler doesn't + * support typeof() and fails with this implementation, please try a newer + * compiler. + */ +#define __container_of(ptr, sample, member) \ + (void *)((char *)(ptr) \ + - ((char *)&(sample)->member - (char *)(sample))) +#endif + +/** + * Loop through the list given by head and set pos to struct in the list. + * + * Example: + * struct foo *iterator; + * xorg_list_for_each_entry(iterator, &bar->list_of_foos, entry) { + * [modify iterator] + * } + * + * This macro is not safe for node deletion. Use xorg_list_for_each_entry_safe + * instead. + * + * @param pos Iterator variable of the type of the list elements. + * @param head List head + * @param member Member name of the struct xorg_list in the list elements. + * + */ +#define xorg_list_for_each_entry(pos, head, member) \ + for (pos = NULL, \ + pos = __container_of((head)->next, pos, member); \ + &pos->member != (head); \ + pos = __container_of(pos->member.next, pos, member)) + +/** + * Loop through the list, keeping a backup pointer to the element. This + * macro allows for the deletion of a list element while looping through the + * list. + * + * See xorg_list_for_each_entry for more details. + */ +#define xorg_list_for_each_entry_safe(pos, tmp, head, member) \ + for (pos = NULL, \ + pos = __container_of((head)->next, pos, member), \ + tmp = __container_of(pos->member.next, pos, member); \ + &pos->member != (head); \ + pos = tmp, tmp = __container_of(pos->member.next, tmp, member)) + +/* NULL-Terminated List Interface + * + * The interface below does _not_ use the struct xorg_list as described above. + * It is mainly for legacy structures that cannot easily be switched to + * struct xorg_list. + * + * This interface is for structs like + * struct foo { + * [...] + * struct foo *next; + * [...] + * }; + * + * The position and field name of "next" are arbitrary. + */ + +/** + * Init the element as null-terminated list. + * + * Example: + * struct foo *list = malloc(); + * nt_list_init(list, next); + * + * @param list The list element that will be the start of the list + * @param member Member name of the field pointing to next struct + */ +#define nt_list_init(_list, _member) \ + (_list)->_member = NULL + +/** + * Returns the next element in the list or NULL on termination. + * + * Example: + * struct foo *element = list; + * while ((element = nt_list_next(element, next)) { } + * + * This macro is not safe for node deletion. Use nt_list_for_each_entry_safe + * instead. + * + * @param list The list or current element. + * @param member Member name of the field pointing to next struct. + */ +#define nt_list_next(_list, _member) \ + (_list)->_member + +/** + * Iterate through each element in the list. + * + * Example: + * struct foo *iterator; + * nt_list_for_each_entry(iterator, list, next) { + * [modify iterator] + * } + * + * @param entry Assigned to the current list element + * @param list The list to iterate through. + * @param member Member name of the field pointing to next struct. + */ +#define nt_list_for_each_entry(_entry, _list, _member) \ + for (_entry = _list; _entry; _entry = (_entry)->_member) + +/** + * Iterate through each element in the list, keeping a backup pointer to the + * element. This macro allows for the deletion of a list element while + * looping through the list. + * + * See nt_list_for_each_entry for more details. + * + * @param entry Assigned to the current list element + * @param tmp The pointer to the next element + * @param list The list to iterate through. + * @param member Member name of the field pointing to next struct. + */ +#define nt_list_for_each_entry_safe(_entry, _tmp, _list, _member) \ + for (_entry = _list, _tmp = (_entry) ? (_entry)->_member : NULL;\ + _entry; \ + _entry = _tmp, _tmp = (_tmp) ? (_tmp)->_member: NULL) + +/** + * Append the element to the end of the list. This macro may be used to + * merge two lists. + * + * Example: + * struct foo *elem = malloc(...); + * nt_list_init(elem, next) + * nt_list_append(elem, list, struct foo, next); + * + * Resulting list order: + * list_item_0 -> list_item_1 -> ... -> elem_item_0 -> elem_item_1 ... + * + * @param entry An entry (or list) to append to the list + * @param list The list to append to. This list must be a valid list, not + * NULL. + * @param type The list type + * @param member Member name of the field pointing to next struct + */ +#define nt_list_append(_entry, _list, _type, _member) \ + do { \ + _type *__iterator = _list; \ + while (__iterator->_member) { __iterator = __iterator->_member;}\ + __iterator->_member = _entry; \ + } while (0) + +/** + * Insert the element at the next position in the list. This macro may be + * used to insert a list into a list. + * + * struct foo *elem = malloc(...); + * nt_list_init(elem, next) + * nt_list_insert(elem, list, struct foo, next); + * + * Resulting list order: + * list_item_0 -> elem_item_0 -> elem_item_1 ... -> list_item_1 -> ... + * + * @param entry An entry (or list) to append to the list + * @param list The list to insert to. This list must be a valid list, not + * NULL. + * @param type The list type + * @param member Member name of the field pointing to next struct + */ +#define nt_list_insert(_entry, _list, _type, _member) \ + do { \ + nt_list_append((_list)->_member, _entry, _type, _member); \ + (_list)->_member = _entry; \ + } while (0) + +/** + * Delete the entry from the list by iterating through the list and + * removing any reference from the list to the entry. + * + * Example: + * struct foo *elem = + * nt_list_del(elem, list, struct foo, next); + * + * @param entry The entry to delete from the list. entry is always + * re-initialized as a null-terminated list. + * @param list The list containing the entry, set to the new list without + * the removed entry. + * @param type The list type + * @param member Member name of the field pointing to the next entry + */ +#define nt_list_del(_entry, _list, _type, _member) \ + do { \ + _type *__e = _entry; \ + if (__e == NULL || _list == NULL) break; \ + if ((_list) == __e) { \ + _list = __e->_member; \ + } else { \ + _type *__prev = _list; \ + while (__prev->_member && __prev->_member != __e) \ + __prev = nt_list_next(__prev, _member); \ + if (__prev->_member) \ + __prev->_member = __e->_member; \ + } \ + nt_list_init(__e, _member); \ + } while(0) + +/** + * DO NOT USE THIS. + * This is a remainder of the xfree86 DDX attempt of having a set of generic + * list functions. Unfortunately, the xf86OptionRec uses it and we can't + * easily get rid of it. Do not use for new code. + */ +typedef struct generic_list_rec { + void *next; +} GenericListRec, *GenericListPtr, *glp; + +#endif -- cgit v1.2.3 From 86110d6edadef2d9fbcd3ee0d008696bfcf7dcd4 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 9 Feb 2017 13:45:12 +0100 Subject: os: Add NotifyFd interfaces Backported from X.org: commit 0c41b7af4ab0c8d22b88f201293f59524d1e7317 Author: Keith Packard Date: Wed Nov 11 22:02:02 2015 -0800 os: Add NotifyFd interfaces This provides a callback-based interface to monitor file descriptors beyond the usual client and device interfaces. Modules within the server using file descriptors for reading and/or writing can call Bool SetNotifyFd(int fd, NotifyFdProcPtr notify_fd, int mask, void *data); mask can be any combination of X_NOTIFY_READ and X_NOTIFY_WRITE. When 'fd' becomes readable or writable, the notify_fd function will be called with the 'fd', the ready conditions and 'data' values as arguments, When the module no longer needs to monitor the fd, it will call void RemoveNotifyFd(int fd); RemoveNotifyFd may be called from the notify function. Reviewed-by: Adam Jackson Signed-off-by: Keith Packard Backported-to-NX-by: Mike Gabriel --- nx-X11/programs/Xserver/include/os.h | 13 +++++ nx-X11/programs/Xserver/os/WaitFor.c | 5 ++ nx-X11/programs/Xserver/os/connection.c | 94 +++++++++++++++++++++++++++++++++ nx-X11/programs/Xserver/os/osdep.h | 5 ++ nx-X11/programs/Xserver/os/osinit.c | 1 + 5 files changed, 118 insertions(+) diff --git a/nx-X11/programs/Xserver/include/os.h b/nx-X11/programs/Xserver/include/os.h index 0fd687d18..dfcc639d3 100644 --- a/nx-X11/programs/Xserver/include/os.h +++ b/nx-X11/programs/Xserver/include/os.h @@ -147,6 +147,19 @@ extern void AddEnabledDevice(int /*fd*/); extern void RemoveEnabledDevice(int /*fd*/); +typedef void (*NotifyFdProcPtr)(int fd, int ready, void *data); + +#define X_NOTIFY_NONE 0 +#define X_NOTIFY_READ 1 +#define X_NOTIFY_WRITE 2 + +extern Bool SetNotifyFd(int fd, NotifyFdProcPtr notify_fd, int mask, void *data); + +static inline void RemoveNotifyFd(int fd) +{ + (void) SetNotifyFd(fd, NULL, X_NOTIFY_NONE, NULL); +} + extern void OnlyListenToOneClient(ClientPtr /*client*/); extern void ListenToAllClients(void); diff --git a/nx-X11/programs/Xserver/os/WaitFor.c b/nx-X11/programs/Xserver/os/WaitFor.c index 0ecca8b7a..19a1b9809 100644 --- a/nx-X11/programs/Xserver/os/WaitFor.c +++ b/nx-X11/programs/Xserver/os/WaitFor.c @@ -504,6 +504,11 @@ WaitForSomething(int *pClientsReady) if (XFD_ANYSET(&tmp_set)) QueueWorkProc(EstablishNewConnections, NULL, (void *)&LastSelectMask); + + XFD_ANDSET(&tmp_set, &LastSelectMask, &NotifyReadFds); + if (XFD_ANYSET(&tmp_set)) + HandleNotifyFds(); + #ifdef DPMSExtension if (XFD_ANYSET (&devicesReadable) && (DPMSPowerLevel != DPMSModeOn)) DPMSSet(DPMSModeOn); diff --git a/nx-X11/programs/Xserver/os/connection.c b/nx-X11/programs/Xserver/os/connection.c index 458daab54..23df49883 100644 --- a/nx-X11/programs/Xserver/os/connection.c +++ b/nx-X11/programs/Xserver/os/connection.c @@ -108,6 +108,7 @@ SOFTWARE. #include #include "opaque.h" #include "dixstruct.h" +#include "list.h" #ifdef XCSECURITY #define _SECURITY_SERVER #include @@ -123,6 +124,7 @@ int lastfdesc; /* maximum file descriptor */ fd_set WellKnownConnections; /* Listener mask */ fd_set EnabledDevices; /* mask for input devices that are on */ +fd_set NotifyReadFds; /* mask for other file descriptors */ fd_set AllSockets; /* select on this */ fd_set AllClients; /* available clients */ fd_set LastSelectMask; /* mask returned from last select call */ @@ -1013,6 +1015,98 @@ RemoveEnabledDevice(int fd) FD_CLR(fd, &SavedAllSockets); } +struct notify_fd { + struct xorg_list list; + int fd; + int mask; + NotifyFdProcPtr notify; + void *data; +}; + +static struct xorg_list notify_fds; + +void +InitNotifyFds(void) +{ + struct notify_fd *s, *next; + static int been_here; + + if (been_here) + xorg_list_for_each_entry_safe(s, next, ¬ify_fds, list) + RemoveNotifyFd(s->fd); + + xorg_list_init(¬ify_fds); + been_here = 1; +} + +/***************** + * SetNotifyFd + * Registers a callback to be invoked when the specified + * file descriptor becomes readable. + *****************/ + +Bool +SetNotifyFd(int fd, NotifyFdProcPtr notify, int mask, void *data) +{ + struct notify_fd *n; + int changes; + + xorg_list_for_each_entry(n, ¬ify_fds, list) + if (n->fd == fd) + break; + + if (&n->list == ¬ify_fds) { + if (mask == 0) + return TRUE; + + n = calloc(1, sizeof (struct notify_fd)); + if (!n) + return FALSE; + n->fd = fd; + xorg_list_add(&n->list, ¬ify_fds); + } + + changes = n->mask ^ mask; + + if (changes & X_NOTIFY_READ) { + if (mask & X_NOTIFY_READ) { + FD_SET(fd, &NotifyReadFds); + AddGeneralSocket(fd); + } else { + RemoveGeneralSocket(fd); + FD_CLR(fd, &NotifyReadFds); + } + } + if (mask == 0) { + xorg_list_del(&n->list); + free(n); + } else { + n->mask = mask; + n->data = data; + n->notify = notify; + } + + return TRUE; +} + +/***************** + * HandlNotifyFds + * A WorkProc to be called when any of the registered + * file descriptors are readable. + *****************/ + +void +HandleNotifyFds(void) +{ + struct notify_fd *s, *next; + + xorg_list_for_each_entry_safe(s, next, ¬ify_fds, list) { + if (FD_ISSET(s->fd, &LastSelectMask)) { + s->notify(s->fd, X_NOTIFY_READ, s->data); + } + } +} + /***************** * OnlyListenToOneClient: * Only accept requests from one client. Continue to handle new diff --git a/nx-X11/programs/Xserver/os/osdep.h b/nx-X11/programs/Xserver/os/osdep.h index f0e8b707b..dce44e612 100644 --- a/nx-X11/programs/Xserver/os/osdep.h +++ b/nx-X11/programs/Xserver/os/osdep.h @@ -188,6 +188,10 @@ extern void FreeOsBuffers( OsCommPtr /*oc*/ ); +extern void InitNotifyFds(void); + +extern void HandleNotifyFds(void); + #include "dix.h" extern ConnectionInputPtr AllocateInputBuffer(void); @@ -199,6 +203,7 @@ extern fd_set AllClients; extern fd_set LastSelectMask; extern fd_set WellKnownConnections; extern fd_set EnabledDevices; +extern fd_set NotifyReadFds; extern fd_set ClientsWithInput; extern fd_set ClientsWriteBlocked; extern fd_set OutputPending; diff --git a/nx-X11/programs/Xserver/os/osinit.c b/nx-X11/programs/Xserver/os/osinit.c index adafa3cf4..e1986a577 100644 --- a/nx-X11/programs/Xserver/os/osinit.c +++ b/nx-X11/programs/Xserver/os/osinit.c @@ -203,6 +203,7 @@ OsInit(void) #endif been_here = TRUE; } + InitNotifyFds(); TimerInit(); #ifdef DDXOSINIT OsVendorInit(); -- cgit v1.2.3 From 9b934a44772ded19812ed4665265cc43fb751169 Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Thu, 9 Feb 2017 23:35:00 +0000 Subject: nxagent: Use SetNotifyFd to receive events. Inspired by X.org commit: commit 55c2e1a3aa587c58a74066724e11e30b3df267b8 Author: Keith Packard Date: Mon Dec 7 15:11:33 2015 -0800 xnest: Use SetNotifyFd to receive events Signed-off-by: Keith Packard Reviewed-by: Adam Jackson --- nx-X11/programs/Xserver/hw/nxagent/Display.c | 4 ++-- nx-X11/programs/Xserver/hw/nxagent/Init.c | 7 +++++++ nx-X11/programs/Xserver/hw/nxagent/Init.h | 2 ++ nx-X11/programs/Xserver/hw/nxagent/Screen.c | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/nx-X11/programs/Xserver/hw/nxagent/Display.c b/nx-X11/programs/Xserver/hw/nxagent/Display.c index 599b335f6..c683751f6 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Display.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Display.c @@ -2877,7 +2877,7 @@ void nxagentAddXConnection() "to the device set.\n", nxagentXConnectionNumber); #endif - AddEnabledDevice(nxagentXConnectionNumber); + SetNotifyFd(XConnectionNumber(nxagentDisplay), nxagentNotifyConnection, X_NOTIFY_READ, NULL); } void nxagentRemoveXConnection() @@ -2887,7 +2887,7 @@ void nxagentRemoveXConnection() "from the device set.\n", nxagentXConnectionNumber); #endif - RemoveEnabledDevice(nxagentXConnectionNumber); + RemoveNotifyFd(nxagentXConnectionNumber); } /* diff --git a/nx-X11/programs/Xserver/hw/nxagent/Init.c b/nx-X11/programs/Xserver/hw/nxagent/Init.c index 218766e06..f15f2cb0a 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Init.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Init.c @@ -58,6 +58,7 @@ is" without express or implied warranty. #include "Pointer.h" #include "Keyboard.h" #include "Handlers.h" +#include "Events.h" #include "Init.h" #include "Args.h" #include "Client.h" @@ -407,6 +408,12 @@ FIXME: These variables, if not removed at all because have probably blackRoot = TRUE; } +void +nxagentNotifyConnection(int fd, int ready, void *data) +{ + nxagentDispatchEvents(NULL); +} + void InitInput(argc, argv) int argc; char *argv[]; diff --git a/nx-X11/programs/Xserver/hw/nxagent/Init.h b/nx-X11/programs/Xserver/hw/nxagent/Init.h index 29b1100e7..34a17067f 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Init.h +++ b/nx-X11/programs/Xserver/hw/nxagent/Init.h @@ -49,4 +49,6 @@ extern int nxagentX2go; extern ServerGrabInfoRec nxagentGrabServerInfo; +void nxagentNotifyConnection(int fd, int ready, void *data); + #endif /* __Init_H__ */ diff --git a/nx-X11/programs/Xserver/hw/nxagent/Screen.c b/nx-X11/programs/Xserver/hw/nxagent/Screen.c index 3039f4139..01d8c1fc7 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Screen.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Screen.c @@ -2781,7 +2781,7 @@ int nxagentShadowInit(ScreenPtr pScreen, WindowPtr pWin) "to the device set.\n", fd); #endif - AddEnabledDevice(nxagentShadowXConnectionNumber); + SetNotifyFd(nxagentShadowXConnectionNumber, nxagentNotifyConnection, X_NOTIFY_READ, NULL); accessPixmapID = FakeClientID(serverClient -> index); -- cgit v1.2.3 From 6307e6fc72f3cd748c9dc0e601a87171131309ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20H=C3=B6glund?= Date: Thu, 9 Feb 2017 21:28:12 +0000 Subject: Move the code for resetting the DPMS mode in response to input events, from WaitForSomething to mieqProcessInputEvents. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Backported from X.org: commit 3b5b7ef5c2ab1d196806f6359e0972fd78d204dd Author: Fredrik Höglund Date: Wed Jan 3 21:05:35 2007 +0100 Move the code for resetting the DPMS mode in response to input events, from WaitForSomething to mieqProcessInputEvents. mieqProcessInputEvents already handles resetting the screen saver. Backported-to-NX-by: Mike Gabriel --- nx-X11/programs/Xserver/mi/mieq.c | 14 ++++++++++++++ nx-X11/programs/Xserver/os/WaitFor.c | 4 ---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/nx-X11/programs/Xserver/mi/mieq.c b/nx-X11/programs/Xserver/mi/mieq.c index b5d9baa31..fefb222c4 100644 --- a/nx-X11/programs/Xserver/mi/mieq.c +++ b/nx-X11/programs/Xserver/mi/mieq.c @@ -43,6 +43,12 @@ in this Software without prior written authorization from The Open Group. # include "mi.h" # include "scrnintstr.h" +#ifdef DPMSExtension +# include "dpmsproc.h" +# define DPMS_SERVER +# include +#endif + #define QUEUE_SIZE 256 typedef struct _Event { @@ -151,6 +157,14 @@ void mieqProcessInputEvents () if (screenIsSaved == SCREEN_SAVER_ON) SaveScreens (SCREEN_SAVER_OFF, ScreenSaverReset); +#ifdef DPMSExtension + else if (DPMSPowerLevel != DPMSModeOn) + SetScreenSaverTimer(); + + if (DPMSPowerLevel != DPMSModeOn) + DPMSSet(DPMSModeOn); +#endif + e = &miEventQueue.events[miEventQueue.head]; /* * Assumption - screen switching can only occur on motion events diff --git a/nx-X11/programs/Xserver/os/WaitFor.c b/nx-X11/programs/Xserver/os/WaitFor.c index 19a1b9809..d94ada1d5 100644 --- a/nx-X11/programs/Xserver/os/WaitFor.c +++ b/nx-X11/programs/Xserver/os/WaitFor.c @@ -509,10 +509,6 @@ WaitForSomething(int *pClientsReady) if (XFD_ANYSET(&tmp_set)) HandleNotifyFds(); -#ifdef DPMSExtension - if (XFD_ANYSET (&devicesReadable) && (DPMSPowerLevel != DPMSModeOn)) - DPMSSet(DPMSModeOn); -#endif if (XFD_ANYSET (&devicesReadable) || XFD_ANYSET (&clientsReadable)) break; #ifdef WIN32 -- cgit v1.2.3 From 761d74a6805e1030f2206a50834b36d807e8e107 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 9 Feb 2017 23:33:44 +0000 Subject: os: Implement support for NotifyFd X_NOTIFY_WRITE and removal of AddEnabledDevices/RemoveEnabledDevices Backported from X.org: commit be5a513fee6cbf29ef7570e57eb0436d70fbd88c Author: Keith Packard Date: Mon Dec 7 15:12:14 2015 -0800 Remove AddEnabledDevice and AddGeneralSocket APIs All uses of these interfaces should instead be using the NotifyFd API instead. Signed-off-by: Keith Packard Reviewed-by: Adam Jackson commit 4020aacd1fc5b9c63369f011aeb9120af9c55218 Author: Keith Packard Date: Wed Nov 11 22:02:03 2015 -0800 os: Implement support for NotifyFd X_NOTIFY_WRITE This adds the ability to be notified when a file descriptor is available for writing. Reviewed-by: Adam Jackson Signed-off-by: Keith Packard Backported-to-NX-by: Mike Gabriel --- nx-X11/programs/Xserver/include/os.h | 4 -- nx-X11/programs/Xserver/os/WaitFor.c | 35 +++++++++------- nx-X11/programs/Xserver/os/connection.c | 72 ++++++++++++++++++--------------- nx-X11/programs/Xserver/os/io.c | 9 +++-- nx-X11/programs/Xserver/os/osdep.h | 5 ++- 5 files changed, 69 insertions(+), 56 deletions(-) diff --git a/nx-X11/programs/Xserver/include/os.h b/nx-X11/programs/Xserver/include/os.h index dfcc639d3..99003922f 100644 --- a/nx-X11/programs/Xserver/include/os.h +++ b/nx-X11/programs/Xserver/include/os.h @@ -143,10 +143,6 @@ extern void CheckConnections(void); extern void CloseDownConnection(ClientPtr /*client*/); -extern void AddEnabledDevice(int /*fd*/); - -extern void RemoveEnabledDevice(int /*fd*/); - typedef void (*NotifyFdProcPtr)(int fd, int ready, void *data); #define X_NOTIFY_NONE 0 diff --git a/nx-X11/programs/Xserver/os/WaitFor.c b/nx-X11/programs/Xserver/os/WaitFor.c index d94ada1d5..3ac2e1c7e 100644 --- a/nx-X11/programs/Xserver/os/WaitFor.c +++ b/nx-X11/programs/Xserver/os/WaitFor.c @@ -188,9 +188,9 @@ WaitForSomething(int *pClientsReady) int curclient; int selecterr; int nready; - fd_set devicesReadable; CARD32 now = 0; Bool someReady = FALSE; + Bool someNotifyWriteReady = FALSE; #if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) fprintf(stderr, "WaitForSomething: Got called.\n"); @@ -338,7 +338,7 @@ WaitForSomething(int *pClientsReady) if (dispatchException) i = -1; #endif - else if (AnyClientsWriteBlocked) + else if (AnyWritesPending) { #if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) if (wt == NULL) @@ -353,8 +353,9 @@ WaitForSomething(int *pClientsReady) wt -> tv_sec, wt -> tv_usec); } #endif - XFD_COPYSET(&ClientsWriteBlocked, &clientsWritable); - i = Select (MaxClients, &LastSelectMask, &clientsWritable, NULL, wt); + XFD_COPYSET(&ClientsWriteBlocked, &LastSelectWriteMask); + XFD_ORSET(&LastSelectWriteMask, &NotifyWriteFds, &LastSelectWriteMask); + i = Select(MaxClients, &LastSelectMask, &LastSelectWriteMask, NULL, wt); } else { @@ -489,16 +490,22 @@ WaitForSomething(int *pClientsReady) } if (someReady) XFD_ORSET(&LastSelectMask, &ClientsWithInput, &LastSelectMask); - if (AnyClientsWriteBlocked && XFD_ANYSET (&clientsWritable)) - { - NewOutputPending = TRUE; - XFD_ORSET(&OutputPending, &clientsWritable, &OutputPending); - XFD_UNSET(&ClientsWriteBlocked, &clientsWritable); - if (! XFD_ANYSET(&ClientsWriteBlocked)) - AnyClientsWriteBlocked = FALSE; + if (AnyWritesPending) { + XFD_ANDSET(&clientsWritable, &LastSelectWriteMask, &ClientsWriteBlocked); + if (XFD_ANYSET(&clientsWritable)) { + NewOutputPending = TRUE; + XFD_ORSET(&OutputPending, &clientsWritable, &OutputPending); + XFD_UNSET(&ClientsWriteBlocked, &clientsWritable); + if (!XFD_ANYSET(&ClientsWriteBlocked) && NumNotifyWriteFd == 0) + AnyWritesPending = FALSE; + } + if (NumNotifyWriteFd != 0) { + XFD_ANDSET(&tmp_set, &LastSelectWriteMask, &NotifyWriteFds); + if (XFD_ANYSET(&tmp_set)) + someNotifyWriteReady = TRUE; + } } - XFD_ANDSET(&devicesReadable, &LastSelectMask, &EnabledDevices); XFD_ANDSET(&clientsReadable, &LastSelectMask, &AllClients); XFD_ANDSET(&tmp_set, &LastSelectMask, &WellKnownConnections); if (XFD_ANYSET(&tmp_set)) @@ -506,10 +513,10 @@ WaitForSomething(int *pClientsReady) (void *)&LastSelectMask); XFD_ANDSET(&tmp_set, &LastSelectMask, &NotifyReadFds); - if (XFD_ANYSET(&tmp_set)) + if (XFD_ANYSET(&tmp_set) || someNotifyWriteReady) HandleNotifyFds(); - if (XFD_ANYSET (&devicesReadable) || XFD_ANYSET (&clientsReadable)) + if (XFD_ANYSET (&clientsReadable)) break; #ifdef WIN32 /* Windows keyboard and mouse events are added to the input queue diff --git a/nx-X11/programs/Xserver/os/connection.c b/nx-X11/programs/Xserver/os/connection.c index 23df49883..966fe208d 100644 --- a/nx-X11/programs/Xserver/os/connection.c +++ b/nx-X11/programs/Xserver/os/connection.c @@ -48,8 +48,8 @@ SOFTWARE. * Stuff to create connections --- OS dependent * * EstablishNewConnections, CreateWellKnownSockets, ResetWellKnownSockets, - * CloseDownConnection, CheckConnections, AddEnabledDevice, - * RemoveEnabledDevice, OnlyListToOneClient, + * CloseDownConnection, CheckConnections, + * OnlyListToOneClient, * ListenToAllClients, * * (WaitForSomething is in its own file) @@ -123,18 +123,19 @@ SOFTWARE. int lastfdesc; /* maximum file descriptor */ fd_set WellKnownConnections; /* Listener mask */ -fd_set EnabledDevices; /* mask for input devices that are on */ fd_set NotifyReadFds; /* mask for other file descriptors */ +fd_set NotifyWriteFds; /* mask for other write file descriptors */ fd_set AllSockets; /* select on this */ fd_set AllClients; /* available clients */ fd_set LastSelectMask; /* mask returned from last select call */ +fd_set LastSelectWriteMask; /* mask returned from last select call */ fd_set ClientsWithInput; /* clients with FULL requests in buffer */ fd_set ClientsWriteBlocked; /* clients who cannot receive output */ fd_set OutputPending; /* clients with reply/event data ready to go */ int MaxClients = 0; +int NumNotifyWriteFd; /* Number of NotifyFd members with write set */ Bool NewOutputPending; /* not yet attempted to write some new output */ -Bool AnyClientsWriteBlocked; /* true if some client blocked on write */ - +Bool AnyWritesPending; /* true if some client blocked on write or NotifyFd with write */ Bool RunFromSmartParent; /* send SIGUSR1 to parent process */ Bool PartialNetwork; /* continue even if unable to bind all addrs */ static Pid_t ParentProcess; @@ -913,8 +914,8 @@ CloseDownFileDescriptor(OsCommPtr oc) FD_CLR(connection, &SavedClientsWithInput); } FD_CLR(connection, &ClientsWriteBlocked); - if (!XFD_ANYSET(&ClientsWriteBlocked)) - AnyClientsWriteBlocked = FALSE; + if (!XFD_ANYSET(&ClientsWriteBlocked) && NumNotifyWriteFd == 0) + AnyWritesPending = FALSE; FD_CLR(connection, &OutputPending); } @@ -997,24 +998,6 @@ CloseDownConnection(ClientPtr client) AuditF("client %d disconnected\n", client->index); } -void -AddEnabledDevice(int fd) -{ - FD_SET(fd, &EnabledDevices); - FD_SET(fd, &AllSockets); - if (GrabInProgress) - FD_SET(fd, &SavedAllSockets); -} - -void -RemoveEnabledDevice(int fd) -{ - FD_CLR(fd, &EnabledDevices); - FD_CLR(fd, &AllSockets); - if (GrabInProgress) - FD_CLR(fd, &SavedAllSockets); -} - struct notify_fd { struct xorg_list list; int fd; @@ -1036,6 +1019,7 @@ InitNotifyFds(void) RemoveNotifyFd(s->fd); xorg_list_init(¬ify_fds); + NumNotifyWriteFd = 0; been_here = 1; } @@ -1071,12 +1055,30 @@ SetNotifyFd(int fd, NotifyFdProcPtr notify, int mask, void *data) if (changes & X_NOTIFY_READ) { if (mask & X_NOTIFY_READ) { FD_SET(fd, &NotifyReadFds); - AddGeneralSocket(fd); + FD_SET(fd, &AllSockets); + if (GrabInProgress) + FD_SET(fd, &SavedAllSockets); } else { - RemoveGeneralSocket(fd); + FD_CLR(fd, &AllSockets); + if (GrabInProgress) + FD_CLR(fd, &SavedAllSockets); FD_CLR(fd, &NotifyReadFds); } } + + if (changes & X_NOTIFY_WRITE) { + if (mask & X_NOTIFY_WRITE) { + FD_SET(fd, &NotifyWriteFds); + if (!NumNotifyWriteFd++) + AnyWritesPending = TRUE; + } else { + FD_CLR(fd, &NotifyWriteFds); + if (!--NumNotifyWriteFd) + if (!XFD_ANYSET(&ClientsWriteBlocked)) + AnyWritesPending = FALSE; + } + } + if (mask == 0) { xorg_list_del(&n->list); free(n); @@ -1098,12 +1100,16 @@ SetNotifyFd(int fd, NotifyFdProcPtr notify, int mask, void *data) void HandleNotifyFds(void) { - struct notify_fd *s, *next; - - xorg_list_for_each_entry_safe(s, next, ¬ify_fds, list) { - if (FD_ISSET(s->fd, &LastSelectMask)) { - s->notify(s->fd, X_NOTIFY_READ, s->data); - } + struct notify_fd *n, *next; + + xorg_list_for_each_entry_safe(n, next, ¬ify_fds, list) { + int ready = 0; + if ((n->mask & X_NOTIFY_READ) && FD_ISSET(n->fd, &LastSelectMask)) + ready |= X_NOTIFY_READ; + if ((n->mask & X_NOTIFY_WRITE) & FD_ISSET(n->fd, &LastSelectWriteMask)) + ready |= X_NOTIFY_WRITE; + if (ready != 0) + n->notify(n->fd, ready, n->data); } } diff --git a/nx-X11/programs/Xserver/os/io.c b/nx-X11/programs/Xserver/os/io.c index 87739cfb1..92a3f0476 100644 --- a/nx-X11/programs/Xserver/os/io.c +++ b/nx-X11/programs/Xserver/os/io.c @@ -1062,7 +1062,7 @@ FlushClient(ClientPtr who, OsCommPtr oc, const void *__extraBuf, int extraCount) and not ready to accept more. Make a note of it and buffer the rest. */ FD_SET(connection, &ClientsWriteBlocked); - AnyClientsWriteBlocked = TRUE; + AnyWritesPending = TRUE; if (written < oco->count) { @@ -1134,11 +1134,12 @@ FlushClient(ClientPtr who, OsCommPtr oc, const void *__extraBuf, int extraCount) /* everything was flushed out */ oco->count = 0; /* check to see if this client was write blocked */ - if (AnyClientsWriteBlocked) + if (AnyWritesPending) { FD_CLR(oc->fd, &ClientsWriteBlocked); - if (! XFD_ANYSET(&ClientsWriteBlocked)) - AnyClientsWriteBlocked = FALSE; + if (!XFD_ANYSET(&ClientsWriteBlocked) && NumNotifyWriteFd == 0) + AnyWritesPending = FALSE; + } if (oco->size > BUFWATERMARK) { diff --git a/nx-X11/programs/Xserver/os/osdep.h b/nx-X11/programs/Xserver/os/osdep.h index dce44e612..6ac9d860e 100644 --- a/nx-X11/programs/Xserver/os/osdep.h +++ b/nx-X11/programs/Xserver/os/osdep.h @@ -201,9 +201,11 @@ extern ConnectionOutputPtr AllocateOutputBuffer(void); extern fd_set AllSockets; extern fd_set AllClients; extern fd_set LastSelectMask; +extern fd_set LastSelectWriteMask; extern fd_set WellKnownConnections; extern fd_set EnabledDevices; extern fd_set NotifyReadFds; +extern fd_set NotifyWriteFds; extern fd_set ClientsWithInput; extern fd_set ClientsWriteBlocked; extern fd_set OutputPending; @@ -218,7 +220,8 @@ extern void ClearConnectionTranslation(); #endif extern Bool NewOutputPending; -extern Bool AnyClientsWriteBlocked; +extern Bool AnyWritesPending; +extern Bool NumNotifyWriteFd; extern Bool CriticalOutputPending; extern int timesThisConnection; -- cgit v1.2.3 From f315ae066598d0dc955db081f8d0faf8d358292d Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Fri, 24 Feb 2017 13:03:30 +0000 Subject: os: Initialize NotifyFds earlier in startup Backported from X.org: commit ce6546337487c052b5dd3c04d3d8d4b09d691c3d Author: Keith Packard Date: Tue May 31 09:38:17 2016 -0700 os: Initialize NotifyFds earlier in startup If the server calls AbortServer during the first-time initialization (which can happen if you start the server on an already using DISPLAY), then the dbus code will shut down and call the notify fd interface. If the notify fd list hasn't been initialized, the server will crash. Signed-off-by: Keith Packard Reviewed-by: Peter Hutterer Backported-to-NX-by: Mike Gabriel --- nx-X11/programs/Xserver/os/osinit.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nx-X11/programs/Xserver/os/osinit.c b/nx-X11/programs/Xserver/os/osinit.c index e1986a577..08fbb8c89 100644 --- a/nx-X11/programs/Xserver/os/osinit.c +++ b/nx-X11/programs/Xserver/os/osinit.c @@ -101,10 +101,15 @@ OsInit(void) #endif if (!been_here) { + + InitNotifyFds(); + #if !defined(__SCO__) && !defined(__CYGWIN__) && !defined(__UNIXWARE__) fclose(stdin); fclose(stdout); #endif + + /* * If a write of zero bytes to stderr returns non-zero, i.e. -1, * then writing to stderr failed, and we'll write somewhere else @@ -203,7 +208,6 @@ OsInit(void) #endif been_here = TRUE; } - InitNotifyFds(); TimerInit(); #ifdef DDXOSINIT OsVendorInit(); -- cgit v1.2.3