linux: xf86OpenConsole remove root-rights check for keeptty option

There is no reason why keeptty cannot be used without root-rights.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
linux: xf86OpenConsole: Don't detach from controlling tty when it is our vt

Detaching from our controlling tty makes little sense when it is the same
as the vt we're asked to run on. So automatically assume -keeptty in this case.

This is useful to do because when not running as root the server can only make
various VT related ioctls when it does not detach from the tty.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
xf86Xinput: Modify API for server-managed fd support

With systemd-logind support, the xserver, rather than the drivers will be
responsible for opening/closing the fd for input devices.

This commit adds a new capabilities field to the InputDriverRec and a
XI86_DRV_CAP_SERVER_FD flag for drivers to indicate that they support server
managed fds.

This commit adds a new XI86_SERVER_FD flag to indicate to drivers when the
server is managing the fd and they should not open/close it. Note that even
if drivers declare they support server managed fds there is no guarantee they
will actually get them.

Since this changes the input driver ABI, this commit bumps it.

systemd-logind tracks devices by their chardev major + minor numbers, since
we are breaking ABI anyways also add major and minor fields for easy storage /
retrieval of these.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
OdevAttribute: Add config_odev_get_attribute helper

Add a config_odev_get_attribute helper, and replace the diy looping over all
the attributes done in various places with calls to this helper.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
OdevAttribute: config_odev_add_attribute: replace existing values

If an attribute already exists replace its value rather than adding a
duplicate attribute with the new value to the list.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
OdevAttribute: Add support for integer attributes

Add a couple of new functions for dealing with storing integer values into
OdevAttributes.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
OdevAttribute: Remove unowned flag from OdevAttributes head

The OdevAttributes struct should just be a head of the attributes list, and
not contain various unrelated flags. Instead add a flags field to
struct xf86_platform_device and use that.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
hotplug: Extend OdevAttributes for server-managed fd support

With systemd-logind support, the xserver, rather than the drivers will be
responsible for opening/closing the fd for drm nodes.

This commit adds a fd member to OdevAttributes to store the fd to pass it
along to the driver.

systemd-logind tracks devices by their chardev major + minor numbers, so
also add OdevAttributes to store the major and minor.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
systemd-logind: Add systemd-logind "core"

This commits add the bulk of the systemd-logind integration code, but does
not hook it up yet other then calling its init and fini functions, which
don't do that much.

Note the configure bits check for udev since systemd-logind use will only be
supported in combination with udev. Besides that it only checks for dbus
since all communication with systemd-logind is happening over dbus, so
no further libs are needed.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
systemd-logind: Hookup systemd-logind integration

This commits makes the changes necessary outside of the systemd-logind core
to make the server use systemd-logind managed fds for input devices and drm
nodes.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
systemd-logind: Add delayed input device probing

With systemd-logind we cannot probe input devices while switched away, so
if we're switched away, put the pInfo on a list, and probe everything on
that list on VT-Enter.

This is using an array grown by re-alloc, rather than a xorg_list since
creating a new data-type to store a pInfo + list-entry just for this seems
overkill.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
config-udev: Don't try to add drm devices twice

Before this commit we were trying to add most drm devices twice, once
from xf86platformProbe() and once from config_udev_init().

This results in somewhat confusing messages in Xorg.log, ie:

(II) xfree86: Adding drm device (/dev/dri/card0)
Later followed by:
(II) config/udev: Adding drm device (/dev/dri/card0)

By filtering out duplicate drm devices we avoid these confusing messages.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Peter Hutterer <peter.hutterer@who-t.net>
xf86OpenSerial: Add support server managed fds

Try to get a server managed fd from the Options before trying to open the
device node ourselves.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
dix: Clear any existing selections before initializing privates

If there is a selection left over from a previous execution of the
main loop, and that selection has privates allocated for it, the X
server will crash. This is because dixResetPrivates() resets the
privates refcounts to zero without accounting for the reference held
by the selection object. When the selection is then deleted in
InitSelections() after the call to dixResetPrivates(), the refcount
for its privates type goes negative and bad things happen.

To fix this, we should delete any existing selections before calling
dixResetPrivates(). This will properly release the selection's
privates and avoid the crash.

A more thorough description of the problem and a test case to
reproduce the crash is available at a previous mail:
  "Negative Selection devPrivates refcount?"
  By Andrew Eikum to xorg-devel on 10 Dec 2013
  http://lists.freedesktop.org/archives/xorg-devel/2013-December/039492.html

Signed-off-by: Andrew Eikum <aeikum@codeweavers.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
Fix xephyr build in --disable-glamor case

It broke after commit 9fe052d90cca90fdf750d3a45b151be2ac7f0ebd
"xephyr: Build support for rendering with glamor using a -glamor
option."

See http://tinderbox.x.org/builds/2014-03-07-0004/logs/xserver/#build

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Signed-off-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Eric Anholt <eric@anholt.net>
Merge remote-tracking branch 'jwrdecoede/for-keith'
xserver: fix build since system-logind.h

on tinderbox and irc

Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Matthieu Herrb <matthieu@herrb.eu>
Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
hashtabletest: Fix warning: format ‘%ld’ expects argument of type ...

This fixes the following compiler warning:

hashtabletest.c: In function ‘print_xid’:
hashtabletest.c:15:5: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 2 has type ‘XID’ [-Wformat=]
     printf("%ld", *x);
     ^

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
config_odev_add*_attribute: Don't add the attribute to the list twice

Don't do the xorg_list_append a 2nd time when updating existing attributes,
while at it add a helper function for this to avoid code duplication.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
systemd-logind: Fix vt-enter not working when using a legacy video driver

If there is only a single non kms video device (tested with the vesa driver),
then we will never get a resume signal for a drm node, so also call vtenter
when we get a resume for an input device.

Notes:
1) vtenter checks if it is ok to do the vtenter, so if there are kms video
devices the calls for input device resumes are a nop
2) This assumes that there will always be at least one server event fd
supporting input device. Since all non legacy input-drivers will be patched
to supported server fds this seems a safe assumption.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>