Commit Graph

1071 Commits

Author SHA1 Message Date
Enrico Weigelt, metux IT consult
435de433cd os: io: fix NULL output buffer after FlushClient()
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>
2025-08-07 14:00:25 +02:00
Enrico Weigelt, metux IT consult
97f3ff8c7e os: cross platform socket close() wrapper
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>
2025-08-07 12:40:35 +02:00
Enrico Weigelt, metux IT consult
ec20354aec os: cross platform ioctl() wrapper
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>
2025-08-07 12:40:35 +02:00
Enrico Weigelt, metux IT consult
fe795fa7b8 os: generic socket layer init function
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>
2025-08-07 12:40:35 +02:00
Enrico Weigelt, metux IT consult
fdf43d4176 os: io: FlushClient() consolidate error/abort code path
remove some redundancy in the error path

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-07 12:36:20 +02:00
Enrico Weigelt, metux IT consult
0d8e9ee708 os: xtranssock: drop weird check of "out of range" socket
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>
2025-08-05 12:18:19 +02:00
Enrico Weigelt, metux IT consult
e6e2b88cff io: os: simplify FlushClient()
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>
2025-08-04 15:55:36 +02:00
Enrico Weigelt, metux IT consult
1298653ddb os: io: FlushClient(): check for broken connection earlier
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>
2025-08-04 15:55:36 +02:00
Enrico Weigelt, metux IT consult
1c13cfa6ca os: io: factor out making room in output buffer
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>
2025-08-04 15:55:36 +02:00
Enrico Weigelt, metux IT consult
a3a068d6d3 os: connection: simplify connection error sending
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>
2025-08-04 15:47:09 +02:00
Enrico Weigelt, metux IT consult
235a8e0f91 os: ospoll: include winsock2.h on WIN32 instead of misc.h
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>
2025-07-31 17:41:20 +02:00
Enrico Weigelt, metux IT consult
d9f82ada19 os: xtranssock: win32: use separate symbol for socket close
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>
2025-07-31 17:32:03 +02:00
Enrico Weigelt, metux IT consult
2353d7a710 os: xtrans: replace _XSERVTransSetOption() by _XSERVTransNonBlock()
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>
2025-07-31 17:30:52 +02:00
Enrico Weigelt, metux IT consult
ad53be3a32 os: xtrans: drop use of FNDELAY
That's an ancient symbol, which had been replaced by O_NDELAY long ago.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-31 17:10:58 +02:00
Enrico Weigelt, metux IT consult
399c51bb6d os: xtrans: drop _XSERVTransReadv() et al
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>
2025-07-31 17:09:37 +02:00
Enrico Weigelt, metux IT consult
a317ae39ad os: xtrans: _XSERVTransGetHostname() variant for mingw target
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>
2025-07-31 17:05:49 +02:00
Enrico Weigelt, metux IT consult
3031e96abf os: xprintf: fix includes
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>
2025-07-31 17:01:10 +02:00
Enrico Weigelt, metux IT consult
8c3d608d4e os: xserver_poll: skip defining symbols already defined by mingw
mingw already has struct pollfd and POLL* defines.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-31 15:28:08 +02:00
Enrico Weigelt, metux IT consult
9fdb2482de os: xtrans: drop define of EINPROGRESS
Never used anywhere and conflicts with system headers.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-31 15:24:30 +02:00
Enrico Weigelt, metux IT consult
90d0c2d4a0 os: xtrans: drop unused TRANS_CLOSEONEXEC
Not used anywhere, so no need to keep it around anymore.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-31 15:23:27 +02:00
Enrico Weigelt, metux IT consult
d9db02d700 os: ospoll: use stdbool instead of X11's Bool
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>
2025-07-31 15:22:07 +02:00
Enrico Weigelt, metux IT consult
93f57f68a2 os: xserver_poll: replace own typedef by size_t
No need to have an own typedef here, just use standard size_t.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-31 14:50:05 +02:00
Enrico Weigelt, metux IT consult
e1b1c2f514 os: ospoll: use realloc() instead of reallocarray()
MacOS doesn't support reallocarray(), and we can't include os.h here
on win32/mingw.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-31 14:49:23 +02:00
Enrico Weigelt, metux IT consult
8299ef3d81 os: xtrans: fix shadowed variable
`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>
2025-07-30 20:40:51 +02:00
Enrico Weigelt, metux IT consult
53691f7174 os: xtranssock: undefine before redefining EADDRINUSE
prevent warning on doubly defined preprocessor symbol.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-30 19:09:44 +02:00
Enrico Weigelt, metux IT consult
9986e17950 meson: move MAXCLIENTS and LIMITCLIENTS into dix-config.h
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>
2025-07-30 14:55:40 +02:00
Oleh Nykyforchyn
0c23d26fb8 xserver: os/log.c: ignore alternate forms in log formats
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>
2025-07-29 16:21:02 +02:00
Enrico Weigelt, metux IT consult
879bc0012d os: xdmcp: fix missing include of <X11/Xdmcp.h>
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>
2025-07-28 16:20:58 +02:00
Enrico Weigelt, metux IT consult
296e7cb842 os: ospoll: add missing include of <assert.h>
We're using assert() here, so need to include <assert.h>

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-25 16:20:52 +02:00
Enrico Weigelt, metux IT consult
31c75dd68b os: ospoll: add missing include of <string.h>
Needed for memmove()

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-25 16:20:27 +02:00
Enrico Weigelt, metux IT consult
1292b4bd39 os: ospoll: drop not needed including of X11 headers
Those just conflicting with win32/mingw headers on type `BOOL`.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-25 16:10:01 +02:00
Enrico Weigelt, metux IT consult
2bee97548e os: move X_NOTIFY_* defines to separate header
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>
2025-07-25 15:21:13 +02:00
Enrico Weigelt, metux IT consult
4fa6849f43 os: xtrans: drop define of EPROTOTYPE
Never used anywhere and conflicts with system headers.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-25 12:44:14 +02:00
Enrico Weigelt, metux IT consult
ee1f0a3ac4 os: xtrans: drop define of ECONNREFUSED
Never used anywhere and conflicts with system headers.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-25 12:30:12 +02:00
Enrico Weigelt, metux IT consult
4ee55d09b0 os: xtrans: fix _XSERVTransWSAStartup() prototype
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-25 09:56:31 +02:00
Enrico Weigelt, metux IT consult
f0cc20eb68 os: osdep: add macro for compile-time type size assert
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>
2025-07-19 02:38:26 +02:00
Enrico Weigelt, metux IT consult
f5062223ec os: xtrans: fix calloc overflow warning
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>
2025-07-18 22:29:38 +02:00
Enrico Weigelt, metux IT consult
d1bb5dc457 os: xtrans: expand TRANS() macro to _XSERVTrans
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>
2025-07-18 22:29:38 +02:00
Enrico Weigelt, metux IT consult
689351067c os: xtrans: drop GetReopenInfo()
Not used anywhere, so no need to keep it around anymore.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-18 22:29:38 +02:00
Enrico Weigelt, metux IT consult
80d1cb5095 os: xtrans: drop ifdefs on NAMEDNODENAME
It's always defined, so no ifdefs needed.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-18 22:29:38 +02:00
Enrico Weigelt, metux IT consult
f7a1627659 os: xtrans: drop DEV_PTMX
Not used anywhere.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-18 22:29:38 +02:00
Enrico Weigelt, metux IT consult
03653eb403 os: xtrans: drop TRANS_CLIENT code pathes
Not needed in server-only code base.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-18 22:29:38 +02:00
Enrico Weigelt, metux IT consult
a830e4eff5 os: xtrans: drop XSERV_t and x11_t defines
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>
2025-07-18 22:29:38 +02:00
Enrico Weigelt, metux IT consult
499751751d os: xtrans: drop ifdef TRANS_REOPEN
It's always defined, so the guards aren't necessary.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-18 22:29:38 +02:00
Enrico Weigelt, metux IT consult
b17fe4128b os: xtrans: drop ifdef TRANS_SERVER
it's always defined, no extra guards needed.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-18 22:29:38 +02:00
Enrico Weigelt, metux IT consult
1f49e6ae8f os: xtrans: drop NEED_UTSNAME
All our supported platforms have this utsname.h.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-18 22:29:38 +02:00
Enrico Weigelt, metux IT consult
fb5f76f856 os: xtrans: drop _WILLWINSOCK_
Not used anywhere.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-18 22:29:38 +02:00
Enrico Weigelt, metux IT consult
214e1c0ca1 os: xtrans: drop own VErrorF() and ErrorF()
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-18 22:29:38 +02:00
Enrico Weigelt, metux IT consult
16053efd50 os: xtrans: replace bzero by memset
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-18 22:29:38 +02:00
Enrico Weigelt, metux IT consult
4ca4c167ff os: xtrans: drop XIM_t
Not defined anywhere.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-18 22:29:38 +02:00