FlushClient() does drops the output buffer, when it becomes empty.
This previously wasn't any problem and actually intented, because we've
returned from the write path directly after FlushClient() was called.
But now we've changed the call order, so it's called from within
OutputBufferMakeRoom(), so we need to make sure we always got valid
output buffer before trying to access it.
For the future, we should think about whether dropping output buffers
really makes sense at all. Instead we could leave them as they are
(over the client's lifetime) and maybe just trim when they've went
too big.
Fixes: 1c13cfa6ca
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Reducing the ifdef-zoo a bit by moving the platform specific socket
close calls into separate function. On win32, this also checks the
retval and potentially query for error. On Unix, just calling close().
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Reducing the ifdef-zoo a bit by moving the platform specific socket
ioctl calls into separate function. On win32, this also checks the
retval and potentially query for error. On Unix, just calling ioctl().
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Reduce the ifdef-zoo a bit by moving win32 specific socket layer init
into a separate function (that's no-op on non-win32).
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
A socket() call either returns a valid socket fd or -1, there's no need for
trying to check whether the returned fd is out of the OS's allowed range
of fd's, because if it would, the kernel would return error anyways.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Since nobody's passing in extra data here anymore, this function
can be radically simplified now.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Move up the check for broken/NULL transport connection in order to
simplify the code a bit more.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
First step for simplifying the output path - this is really complicated now:
FlushClient() is called in two cases:
a) we really need to send out critical data (eg. critical events now),
here we have no extra data
b) going to write new data in the output buffer, but it's already full
here we do have extra data
In case b) (only called from WriteToClient()) we're first trying to write out
as much as we can, and if there's still not enough room, the buffer is resized.
The write-out path is a complex look trying to write buffered data first, then
the new data. That's even more complex since using writev() with 3 pieces
(old buffer, new data, padding), and considering each of those could be written
just partially.
By the way, there's really no need that the new data is strictly written
along with the already buffered one - practically that's not even any actual
performance optimization - so it's just making things unncessarily complicated.
Therefore reduce it to what's really needed: ensure enough room in the output
buffer (and potentially flush out or resize the buffer). In a later, remove the
whole extra data part from FlushClient(), as it's not needed anymore.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
It's such a cold and rarely used path, we really don't need writev() for
efficiency, so instead doing two trivial write()'s. And the complex size
calculation as well as extra padding isn't necessary, if we just make
the string of size 4*n.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
On WIN32 we need to include winsock2.h, but we can't include misc.h here
becaues it pulling in X11 headers that are conflicting with win32 headers.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Instead of redefining existing standard libc symbols, pick another symbol
that's mapped to the corresponding platform specific function.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
The only option left is TRANS_NONBLOCKING, and we only enable and
never disable it. Thus trim down the code into one function for
exactly that.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
It's not used anywhere, so no need to keep it around anymore.
We can also dispose the corresponding connection driver's procs here.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Win32 does not have utsname(), but gethostname(), so we need a separate
implementation of _XSERVTransGetHostname() here.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
It's better coding style to include the header with prototypes for
our own functions directly, instead of relying on it being included
indirectly.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Low level OS specific code should not depend on higher level protocol
headers. This also removes yet another conflict with win32/mingw headers.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
`arg` is also a parameter of that functions, so we really shouldn't
also have a local variable by the same name.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Both are potentially tunable variables, and MAXCLIENTS is (still) used by
intel-driver, but also by os specific parts that must not include misc.h
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This patch fixes Xserver crashes when evdev or synaptics input drivers are used.
These (and maybe other) driver use alternate forms "%#..." in formats for
xf86IDrvLogVerb() function, which in turn uses signal-safe vpnprintf().
The last function does not recognize alternate forms and exits abnormally, which
causes Xserver to crash. The patch make vpnprintf() to ignore alternate forms.
Signed-off-by: Oleh Nykyforchyn <oleh.nyk@gmail.com>
xdmcp.h is using types from <X11/Xdmcp.h>, but forgot to include it.
This just popped up with building w/ -Dxdmcp=false, because that file was
included in the wrong place (osdep.h) and only conditionally.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
These defines are already public, used by consumers of SetNotifyFd(),
but also needed in places where os.h cannot be included.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
usage:
__size_assert(typename, size);
if the type's size (calculated by sizeof) doesn't match the asserted size,
an illegal dummy type will be constructed, thus compilation fails.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
The size of `int` is machine specific and may be 64 bits wide, which could
overflow the calloc'able size. Practically cannot happen here, since the
ListenTransCount can't go above MAX_CONNECTIONS, but compiler can't know
that and so spitting out a warning.
Using uint32_t really is sufficient here.
> ../os/connection.c: In function ‘CreateWellKnownSockets’:
> ../os/connection.c:274:22: warning: argument 1 range [18446744071562067968, 18446744073709551615] exceeds maximum object size 9223372036854775807 [-Walloc-size-larger-than=]
> 274 | ListenTransFds = calloc(ListenTransCount, sizeof(int));
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Since TRANS() now will always expand the same, it's better for
maintenance, having the function names written explicitly.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
These are always enablde (x11_t is defined when XSERV_t is defined),
so no need for the #ifdef's anymore.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>