Commit Graph

17 Commits

Author SHA1 Message Date
Adam Jackson
365cbbfc4b os, shm: fcntl()'s third argument is integer, not pointer
All of these uses were attempting to set FD_CLOEXEC, which happens to be
(1<<0). Since flags is going to be aligned in memory, its address is
never going to have the low bit set, so we were never actually setting
what we meant to.

Fixes: xorg/xserver#1114
2020-12-18 09:36:30 -05:00
Jon Turney
7b4b030df8 configure: Check for sigprocmask
MinGW defines SIG_BLOCK, but doesn't have signal masks, so rather than
checking for SIG_BLOCK, add a configure check for sigprocmask.

v2:
Also add check to meson.build
2019-05-18 14:59:38 +00:00
Alan Coopersmith
4ad21c3247 Add ddxInputThread call from os layer into ddx layer
Allows ddx's to run additional code as necessary to set up the
input thread.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2019-02-25 15:48:03 +00:00
Michal Srb
71348e99a8 os/inputthread: Force unlock when stopping thread.
The inputthread is kept locked all the time while X server's VT is not active.
If the X server is terminated while not active, it will be stuck forever in
InputThreadFini waiting for the thread to join, but it wouldn't because it is
locked.

Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=103782
Signed-off-by: Michal Srb <msrb@suse.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2018-01-24 16:27:31 -05:00
Peter Hutterer
1b12249fd6 os: log a bug whenever WriteToClient is called from the input thread
The input thread should generate events, not send them. Make it easier to
find the instances where it's doing so.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Tested-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Olivier Fourdan <ofourdan@redhat.com>
2017-02-27 09:25:08 +10:00
Chris Wilson
dcb63deb1b inputthread: Initialise inputThreadInfo->changed before use
==8734== Thread 2 InputThread:
==8734== Conditional jump or move depends on uninitialised value(s)
==8734==    at 0x2FDB05: InputThreadDoWork (inputthread.c:333)
==8734==    by 0x6924423: start_thread (pthread_create.c:333)
==8734==    by 0x6C229BE: clone (clone.S:105)

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-02-23 09:11:13 +10:00
Peter Hutterer
5cb3283386 inputthread: On Linux leave the main thread's name as-is
On Linux, setting the main thread's name changes the program name
(/proc/self/comm). Setting it to MainThread breaks scripts that rely on
the command name, e.g. ps -C Xorg.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2016-10-27 09:53:01 +10:00
Mihail Konev
5dcb0666b8 os/inputthread: Ensure pollfd refreshing
When putting a device node into a poll-request list, do not overwrite a
"please-remove" element with the same fd, so that a closed device file
is ospoll_remove'd prior to being ospoll_add'ed.

Before, the opposite order was possible, resulting in ospoll_add
considering the newly opened file being already polled, should it have a
fd for which the "please-remove" has not been procesed yet. In this
case, no further events would be seen from the device.

Signed-off-by: Mihail Konev <k.mvc@ya.ru>
Regressed-in: 52d6a1e832
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=97880
Patchwork: https://patchwork.freedesktop.org/patch/113763/
Hit-and-Reduced-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-and-Reduced-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Keith Packard <keithp@keithp.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
2016-10-15 13:39:26 -07:00
Alan Coopersmith
c4799f186b os: Use pthread_setname_np to set thread names if available
Autoconf logic borrowed from glib

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
Tested-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
2016-09-13 16:55:26 -04:00
Jeremy Huddleston Sequoia
065eb66124 os/inputthread: Fix setting of cloexec on file descriptors
O_CLOEXEC is not a file bit.  It is not setable with F_SETFL.  One must
use it when calling open(2).  To set it cloexec on an existing fd,
F_SETFD and FD_CLOEXEC must be used.

This also fixes a build failure regression on configurations that don't
have O_CLOEXEC defined.

cf: http://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html
Regressed-in: 30ac756798

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
Reviewed-by: Julien Cristau <jcristau@debian.org>
2016-09-13 16:10:56 -04:00
Keith Packard
bf31d6f43e os: Allow re-registering fd with InputThreadRegisterDev
Calling InputThreadRegisterDev twice with the same fd should replace
the existing function and args instead of creating a new entry with
the same fd.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-08-12 10:33:21 +10:00
Peter Hutterer
2df2815d6a os: append, rather than prepend, any new input thread fds
xf86AddEnabledDevice() prepends the new fd to the list,
xf86RemoveEnabledDevice() then searches for a matching fd and removes that
entry. If this is done for the same fd (and since we lose all information but
the actual fd) we usually unregister virtual devices in reverse order, causing
a dereference of already released memory.

Case in point:
- the wacom driver calls xf86AddEnabledDevice() once for the physical device,
  then multiple times for the virtual subdevices
- when the physical device is unplugged, the driver calls
  xf86RemoveEnabledDevice() for the physical device
- all we have is the fd, so we end up removing the last virtual device from
  the fd set
- xf86DeleteInput() frees the physical device's pInfo
- the fd goes crazy with ENODEV, but a read_input() now passes the already
  freed pInfo for the physical device
- boom

Fix this by appending to the fd list to provide bug-for-bug compatibility with
the old SIGIO code. This needs to be fixed in the driver, but meanwhile not
crashing the server provides for better user experience.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Keith Packard <keithp@keithp.com>
2016-08-11 11:41:51 +10:00
Keith Packard
30bc0732f9 os: Use ospoll for input thread [v2]
Replace use of select(2) to avoid fd limits. Note that
InputThreadFillPipe used select as well, but none of the files passed
were non-blocking, so there was no need for that code at all.

v2: Keep ospoll API usage single threaded to avoid re-entrancy issues

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2016-07-21 15:04:47 -04:00
Keith Packard
8d3a368d89 os: InputThreadFillPipe doesn't need select or poll
The file descriptors passed to InputThreadFillPipe are always
blocking, so there's no need to use Select (or poll).

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2016-07-18 15:27:51 -04:00
Keith Packard
f0756793e4 os: Lock input while messing with input device list
The list of input devices may be changed by hotplugging while the
server is active, and those changes may come from either the main
thread or the input thread. That means the list of input devices needs
to be protected by a mutex.

This prevents input drivers from receiving I/O ready callbacks after
removing a device.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-06-01 10:31:52 -07:00
Keith Packard
06bdc3bc1a os: fix input_mutex_count off-by-one in input_force_unlock
input_force_unlock was mis-using input_mutex_lock and leaving it set
to -1. As this is  executed from OsInit at each server generation, on
the second time through, the mutex would be left locked (!) due to the
trylock call. This caused input to fail after the first server reset.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-05-29 19:21:15 -07:00
Keith Packard
30ac756798 Create a threaded mechanism for input [v7]
The current SIGIO signal handler method, used at generation of input events,
has a bunch of oddities. This patch introduces an alternative way using a
thread, which is used to select() all input device file descriptors.

A mutex was used to control the access to input structures by the main and input
threads. Two pipes to emit alert events (such hotplug ones) and guarantee the
proper communication between them was also used.

Co-authored-by: Fernando Carrijo <fcarrijo@freedesktop.org>
Signed-off-by: Tiago Vignatti <tiago.vignatti@nokia.com>

v2: Fix non-Xorg link. Enable where supported by default.

    This also splits out the actual enabling of input threads to
    DDX-specific patches which follow

v3: Make the input lock recursive

v4: Use regular RECURSIVE_MUTEXes instead of rolling our own
    Respect the --disable-input-thread configuration option by
    providing stubs that expose the same API/ABI.

    Respond to style comments from Peter Hutterer.

v5: use __func__ in inputthread debug and error mesages.

    Respond to style comments from Peter Hutterer.

v6: use AX_PTHREAD instead of inlining pthread tests.

    Suggested by Emil Velikov <emil.l.velikov@gmail.com>

v7: Use pthread_sigmask instead of sigprocmask when using threads

    Suggested by Adam Jackson <ajax@redhat.com>

Signed-off-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2016-05-26 16:07:54 -07:00