xfree86: add VT owner interface

This is just a simple interface to avoid accessing x86Screens[0]
directly.

Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Dave Airlie <airlied@gmail.com>
(cherry picked from commit d61ea1f64db45201c1a2b39c39293c5768d98092)
xf86: use new xf86VTOwner interface in a few places

This replaces some previous uses of direct xf86Screens[0] accesses.

Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Dave Airlie <airlied@gmail.com>
(cherry picked from commit 5b359cf6135ca173d8f65cb92926332f07f91efe)
xf86: don't hotplug output devices while VT switched.

We don't want to hotplug output devices while we are VT switched,
as we get races between multiple X servers on the device open, and
drm device master status. This just queues device opens until we return
from VT switch.

Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Dave Airlie <airlied@redhat.com>
(cherry picked from commit 22cab8a28a433d03a4e6ba97f9a160271d73cb52)
hw/xfree86: Only report SetDesiredModes() failed if at least one modeset fails

commit 6703a7c7cf1a349c137e247a0c8eb462ff7b07be
Author: Keith Packard <keithp@keithp.com>
Date:   Tue Jan 8 20:24:32 2013 -0800

    hw/xfree86: Require only one working CRTC to start the server.

changed the logic to try to set the mode on all connected outputs rather
than abort upon the first failure. The return error code was then
tweaked such that it reported success if it set a mode on any crtc.
However, this confuses the headless case where we never enable any crtcs
and also, importantly, never fail to set a crtc.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=59190

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Also-written-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
Reviewed-by: Keith Packard <keithp@keithp.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
(cherry picked from commit 451ba4bd41b82acd4aec6236ba121e00cfeb311b)
dix: don't set non-exisiting flags on touch events

Unlike pointer/keyboard events, the flags field for ET_Touch* is a set of
server-internal defines that we need to convert to XI protocol defines.
Currently only two of those defines actually translate to the protocol, so
make sure we don't send internal garbage down the wire.

No effect to current clients since they shouldn't look at undefined bits
anyway.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
(cherry picked from commit b86b3d10bb2fee1a922b8831e8bb415c339f3d99)
Xi: Use correct destination when swapping barrier events

Write the swapped values to the destination rather than the source.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Jasper St. Pierre <jstpierre@mecheye.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
(cherry picked from commit dbba50a1280cbda9ecff6f37884b4c5756c30bab)
Xi: Do not handle ET_TouchOwnership in ProcessTouchEvent

The event struct is different, causing memory corruption on 1.13 and 1.14,

as can be witnessed in https://bugs.freedesktop.org/show_bug.cgi?id=56578

Signed-off-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
(cherry picked from commit 7347f39f94d8cebbf73ce1a2f94d1abdaf7ff383)
xfree86: change a log message

This path is technically executed through config/udev, but having two
messages in the form "config/udev: Adding drm device" makes it appear as if
the udev filters are wrong and it's trying to add the same device twice. In
fact, it's only one device, only added once, but a duplicate log message.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Dave Airlie <airlied@redhat.com>
(cherry picked from commit 131f883f85b9b734e5e5652f16ba1d3b5f4de12f)
Xi: fix swapped grab mode args for keyboard devices in XIGrabDevice

The protocol says that the grab_mode argument applies to the device
being grabbed and paired_device_mode to the paired master
device. GrabDevice() however takes in a pointer mode and a keyboard
mode and so we have to swap the values according the type of device
being grabbed.

Signed-off-by: Rui Matos <tiagomatos@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
(cherry picked from commit 9003399708936481083424b4ff8f18a16b88b7b3)
Never try to execute BellProcPtr NULL.

This prevents xts XI/XDeviceBell-2 test
from segfaulting the server.

Signed-off-by: Knut Petersen <Knut_Petersen@t-online.de>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
(cherry picked from commit 4bff442ec5aa4b93a3f5c11782d4b7b9d1ae13ac)
dix: copy event in TouchConvertToPointerEvent correctly

Fixes reading random memory read beyond the end of original event.

sizeof device_event: 424
sizeof internal_event: 2800

Signed-off-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
(cherry picked from commit 98b94c36d6b1d286bbd4cb414e54b4b95a1484b0)
ephyr: Fix crash on 24bpp host framebuffer

Use bytes_per_line and bits_per_pixel from the created XImage to fix
    https://bugzilla.redhat.com/show_bug.cgi?id=518960

Signed-off-by: Daniel Martin <consume.noise@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
(cherry picked from commit bd58ebe4cf3b0ce60f87fb26a3715f774dabd349)
dix: send the current axis value in DeviceChangedEvents (#62321)

X.Org Bug 62321 <http://bugs.freedesktop.org/show_bug.cgi?id=62321>

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Keith Packard <keithp@keithp.com>
(cherry picked from commit 23d1bc69f305edd5a6e2cfec3dfc84befda0881c)
If neither HAL nor udev backends are enabled, warn the user

If both are missing,  input device hotplugging will not work out of the box.
While we still have a DBus-API or the user may want to set AAD off all the
time, the most likely source of this is misconfiguration (i.e. lack of the
udev/hal devel packages).

Message printed last to make it more obvious to the user.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Keith Packard <keithp@keithp.com>
(cherry picked from commit 623981ddaeb8836f3b0939e527c0e943f9c4e974)
os: document pnprintf as sigsafe snprintf

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
(cherry picked from commit 44fc062f85df7288c17d2d64b73aa4957b91fd6d)
os: support pnprintf length modifiers for integers

Mainly for %ld, smaller than int is propagated anyway, and %lld isn't really
used.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Keith Packard <keithp@keithp.com>
(cherry picked from commit 5ea21560dd071ea4ab87430000d087fd5fe1f092)
os: support %% in pnprintf

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Keith Packard <keithp@keithp.com>
(cherry picked from commit 58ef34ee6d0f68aa28f6f1a26e56f49ec85ed9bf)
os: support %c in pnprintf

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Keith Packard <keithp@keithp.com>
(cherry picked from commit d903d17d7f006fa333265b8476063b189c20d082)
os: complain about unsupported pnprintf directives

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Keith Packard <keithp@keithp.com>
(cherry picked from commit d9848fb4b182ca21bacf28ed7410d1a502cb000e)
os: Use ErrorFSigSafe from FatalError and it's friends

Backtrace logging etc. is already sigsafe, but the actual FatalError message
in response is not yet, leading to amusing logs like this:

    (EE) Segmentation fault at address 0x0
    (EE) BUG: triggered 'if (inSignalContext)'
    (EE) BUG: log.c:499 in LogVMessageVerb()
    (EE) Warning: attempting to log data in a signal unsafe manner while in
    signal context.
    Please update to check inSignalContext and/or use LogMessageVerbSigSafe() or
    ErrorFSigSafe().
    The offending log format message is:

    Fatal server error:

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Keith Packard <keithp@keithp.com>
(cherry picked from commit 042c6d861f7bb7038ddcdd6b59766fd9094d0e52)