View | Details | Raw Unified | Return to bug 196678 | Differences between
and this patch

Collapse All | Expand All

(-)x11-servers/xephyr/Makefile (-2 lines)
Lines 16-23 Link Here
16
DESCR=		${.CURDIR}/pkg-descr
16
DESCR=		${.CURDIR}/pkg-descr
17
17
18
SLAVE_PORT=	yes
18
SLAVE_PORT=	yes
19
OPTIONS_EXCLUDE=DEVD HAL SUID
20
21
USE_XORG=	x11 xcb
19
USE_XORG=	x11 xcb
22
20
23
CONFIGURE_ARGS+=--enable-xephyr --disable-dmx --disable-xnest --disable-xvfb \
21
CONFIGURE_ARGS+=--enable-xephyr --disable-dmx --disable-xnest --disable-xvfb \
(-)x11-servers/xorg-dmx/Makefile (-2 lines)
Lines 11-18 Link Here
11
DESCR=		${.CURDIR}/pkg-descr
11
DESCR=		${.CURDIR}/pkg-descr
12
12
13
SLAVE_PORT=	yes
13
SLAVE_PORT=	yes
14
OPTIONS_EXCLUDE=DEVD HAL SUID
15
16
USE_XORG=	dmx dmxproto x11 xaw7 xext xfixes xi xmu xpm xrender xres xt xtst
14
USE_XORG=	dmx dmxproto x11 xaw7 xext xfixes xi xmu xpm xrender xres xt xtst
17
15
18
CONFIGURE_ARGS+=--enable-dmx --disable-xephyr --disable-xnest --disable-xvfb \
16
CONFIGURE_ARGS+=--enable-dmx --disable-xephyr --disable-xnest --disable-xvfb \
(-)x11-servers/xorg-nestserver/Makefile (-6 / +1 lines)
Lines 2-8 Link Here
2
# $FreeBSD$
2
# $FreeBSD$
3
3
4
PORTNAME=	xorg-nestserver
4
PORTNAME=	xorg-nestserver
5
PORTVERSION=	1.19.1
6
PORTEPOCH=	2
5
PORTEPOCH=	2
7
6
8
COMMENT=	Nesting X server from X.Org
7
COMMENT=	Nesting X server from X.Org
Lines 11-26 Link Here
11
10
12
MASTERDIR=	${.CURDIR}/../xorg-server
11
MASTERDIR=	${.CURDIR}/../xorg-server
13
DESCR=		${.CURDIR}/pkg-descr
12
DESCR=		${.CURDIR}/pkg-descr
14
DISTINFO_FILE=	${.CURDIR}/distinfo
15
PATCHDIR=	${.CURDIR}/files
16
13
17
RUN_DEPENDS=	xkeyboard-config>=2.5:x11/xkeyboard-config
14
RUN_DEPENDS=	xkeyboard-config>=2.5:x11/xkeyboard-config
18
15
19
SLAVE_PORT=	yes
16
SLAVE_PORT=	yes
20
OPTIONS_EXCLUDE=DEVD HAL SUID
17
USE_XORG=	x11 xext
21
18
22
USE_XORG=	x11 xext xfont2
23
24
CONFIGURE_ARGS+=--enable-xnest --disable-dmx --disable-xephyr --disable-xvfb \
19
CONFIGURE_ARGS+=--enable-xnest --disable-dmx --disable-xephyr --disable-xvfb \
25
		--disable-xwayland
20
		--disable-xwayland
26
21
(-)x11-servers/xorg-nestserver/distinfo (-3 lines)
Lines 1-3 Link Here
1
TIMESTAMP = 1484388904
2
SHA256 (xorg/xserver/xorg-server-1.19.1.tar.bz2) = 79ae2cf39d3f6c4a91201d8dad549d1d774b3420073c5a70d390040aa965a7fb
3
SIZE (xorg/xserver/xorg-server-1.19.1.tar.bz2) = 6041792
(-)x11-servers/xorg-server/Makefile (-51 / +27 lines)
Lines 2-8 Link Here
2
# $FreeBSD$
2
# $FreeBSD$
3
3
4
PORTNAME?=	xorg-server
4
PORTNAME?=	xorg-server
5
PORTVERSION?=	1.18.4
5
PORTVERSION?=	1.19.2
6
PORTREVISION?=	0
6
PORTREVISION?=	0
7
PORTEPOCH?=	1
7
PORTEPOCH?=	1
8
CATEGORIES=	x11-servers
8
CATEGORIES=	x11-servers
Lines 23-39 Link Here
23
OPTIONS_SUB=	yes
23
OPTIONS_SUB=	yes
24
OPTIONS_DEFINE=	SUID
24
OPTIONS_DEFINE=	SUID
25
OPTIONS_RADIO=	CONF
25
OPTIONS_RADIO=	CONF
26
OPTIONS_RADIO_CONF=	DEVD HAL
26
OPTIONS_RADIO_CONF=	DEVD HAL UDEV
27
DEVD_DESC=	Use devd for autoconfiguration of input devices
27
OPTIONS_DEFAULT=	DEVD SUID
28
HAL_DESC=	Use hald for autoconfiguration of input devices
29
SUID_DESC=	Install the Xorg server with setuid bit set
30
OPTIONS_DEFAULT=DEVD SUID
31
28
29
SUID_DESC=	Install setuid wrapper to allow startx as non-root
30
CONF_DESC=	Backend to use for input device configuration
31
DEVD_DESC=	Use devd (native)
32
HAL_DESC=	Use HAL (deprecated)
33
UDEV_DESC=	Use udev via libudev-devd (experimental)
34
32
OPTIONS_EXCLUDE_sparc64=	HAL
35
OPTIONS_EXCLUDE_sparc64=	HAL
33
36
34
.include <bsd.port.options.mk>
37
DEVD_CONFIGURE_ENABLE=	config-devd
38
HAL_CONFIGURE_ENABLE=	config-hal
39
HAL_LIB_DEPENDS=	libhal.so:sysutils/hal \
40
			libdbus-1.so:devel/dbus
41
SUID_CONFIGURE_ENABLE=	suid-wrapper
42
SUID_CONFIGURE_ON=	--libexecdir=${PREFIX}/bin	# set SUID_WRAPPER_DIR
43
UDEV_CONFIGURE_ENABLE=	config-udev
44
UDEV_CONFIGURE_ON=	--disable-config-udev-kms
45
UDEV_LIB_DEPENDS=	libudev.so:devel/libudev-devd
35
46
36
USES=		gmake libtool perl5 ssl tar:bzip2
47
USES=		autoreconf gmake perl5 ssl
37
USE_PERL5=	build
48
USE_PERL5=	build
38
USE_GL+=	gl
49
USE_GL+=	gl
39
USE_XORG+=	bigreqsproto compositeproto damageproto dri2proto dri3proto \
50
USE_XORG+=	bigreqsproto compositeproto damageproto dri2proto dri3proto \
Lines 40-51 Link Here
40
		fixesproto fontsproto glproto inputproto kbproto pixman \
51
		fixesproto fontsproto glproto inputproto kbproto pixman \
41
		presentproto randrproto recordproto renderproto \
52
		presentproto randrproto recordproto renderproto \
42
		resourceproto scrnsaverproto videoproto xau \
53
		resourceproto scrnsaverproto videoproto xau \
43
		xcmiscproto xdmcp xextproto xf86driproto xfont \
54
		xcmiscproto xdmcp xextproto xf86driproto xfont2 \
44
		xineramaproto xkbfile xproto xshmfence xtrans
55
		xineramaproto xkbfile xproto xshmfence xtrans
45
CONFIGURE_ARGS+=--without-doxygen --without-xmlto --without-fop \
56
CONFIGURE_ARGS+=--without-doxygen --without-xmlto --without-fop \
46
		--localstatedir=/var --with-shared-memory-dir=/tmp \
57
		--without-dtrace --with-shared-memory-dir=/tmp \
47
		--disable-config-udev --disable-config-udev-kms \
58
		--disable-install-setuid
48
		--without-dtrace --enable-glamor
49
INSTALL_TARGET=	install-strip
59
INSTALL_TARGET=	install-strip
50
60
51
.if ${SLAVE_PORT} == "no" || ${PORTNAME} == "xephyr" || ${PORTNAME} == "xwayland"
61
.if ${SLAVE_PORT} == "no" || ${PORTNAME} == "xephyr" || ${PORTNAME} == "xwayland"
Lines 62-70 Link Here
62
		--disable-xwayland
72
		--disable-xwayland
63
SUB_FILES=	pkg-install pkg-deinstall
73
SUB_FILES=	pkg-install pkg-deinstall
64
.else
74
.else
65
CONFIGURE_ARGS+=--disable-xorg
75
CONFIGURE_ARGS+=	--disable-xorg
66
# for slave ports we need to overwrite PLIST, so it doesn't overwrite
76
OPTIONS_EXCLUDE=	DEVD HAL UDEV SUID
67
# PLIST_FILES, with the masterport plist.
77
# Set PLIST for slave ports so they only need to set PLIST_FILES
68
PLIST=		${.CURDIR}/pkg-plist
78
PLIST=		${.CURDIR}/pkg-plist
69
.endif
79
.endif
70
80
Lines 77-92 Link Here
77
CONFIGURE_ENV=	SHA1_LIB="-L/usr/lib -lcrypto" SHA1_CFLAGS="-I/usr/include"
87
CONFIGURE_ENV=	SHA1_LIB="-L/usr/lib -lcrypto" SHA1_CFLAGS="-I/usr/include"
78
.endif
88
.endif
79
89
80
.if ${PORT_OPTIONS:MHAL}
81
LIB_DEPENDS+=	libhal.so:sysutils/hal
82
CONFIGURE_ARGS+=	--enable-config-hal
83
.else
84
CONFIGURE_ARGS+=	--disable-config-hal
85
.endif
86
87
# We handle Xorg setuid in the plist. This allows to build xorg-server as a user.
88
CONFIGURE_ARGS+=--disable-install-setuid
89
90
.if ${ARCH} == "i386" || ${ARCH} == "amd64"
90
.if ${ARCH} == "i386" || ${ARCH} == "amd64"
91
LIB_DEPENDS+=	libunwind.so:devel/libunwind
91
LIB_DEPENDS+=	libunwind.so:devel/libunwind
92
.endif
92
.endif
Lines 97-135 Link Here
97
PLIST_SUB+=	SPARC64="@comment "
97
PLIST_SUB+=	SPARC64="@comment "
98
.endif
98
.endif
99
99
100
.if ${PORT_OPTIONS:MSUID}
101
pre-everything::
102
	@${ECHO_MSG} "By default, the X Server installs as a set-user-id root binary. When run by"
103
	@${ECHO_MSG} "a normal user, it checks arguments and environment as done in the x11/wrapper"
104
	@${ECHO_MSG} "port before handling them normally.  If you are concerned about the security"
105
	@${ECHO_MSG} "of this, but still want to run an X Server (for example using xdm/kdm/gdm,"
106
	@${ECHO_MSG} "which will still run the server as root), you can cancel the build and set"
107
	@${ECHO_MSG} "xorg-server_UNSET=SUID in /etc/make.conf."
108
.endif
109
110
post-patch:
100
post-patch:
111
	@${REINPLACE_CMD} 's/test.*-traditional.*;/true;/' \
101
	@${REINPLACE_CMD} 's/test.*-traditional.*;/true;/' \
112
		${WRKSRC}/configure
102
		${WRKSRC}/configure
113
# build libglx.so but don't install it yet. which is done in pre-install.
114
	@${REINPLACE_CMD} -e 's|@GLX_TRUE@GLXMODS =|@GLX_BOGUS@GLXMODS =|g' \
115
		-e 's|^LTLIBRARIES = |LTLIBRARIES = libglx.la |g' \
116
		${WRKSRC}/hw/xfree86/dixmods/Makefile.in
117
103
118
post-configure:
119
.if ${PORT_OPTIONS:MDEVD}
120
	@${REINPLACE_CMD} -e 's|config\.c|config.c devd.c|g' \
121
		-e 's|config\.lo|config.lo devd.lo|g' \
122
		${WRKSRC}/config/Makefile
123
	@${REINPLACE_CMD} -e 's|^/\* #undef CONFIG_UDEV \*/|#define CONFIG_DEVD 1|' \
124
		${WRKSRC}/include/dix-config.h
125
.endif
126
127
.if ${SLAVE_PORT} == "no"
104
.if ${SLAVE_PORT} == "no"
128
post-install:
105
post-install:
129
# The .xorg dir because else the xorg-server might not load the correct
106
# Avoid conflict with nvidia-driver, move libglx.so into .xorg directory
130
# libglx module.
131
	@${MKDIR} ${STAGEDIR}${PREFIX}/lib/xorg/modules/extensions/.xorg
107
	@${MKDIR} ${STAGEDIR}${PREFIX}/lib/xorg/modules/extensions/.xorg
132
	${INSTALL_LIB} ${WRKSRC}/hw/xfree86/dixmods/.libs/libglx.so \
108
	${MV} ${STAGEDIR}${PREFIX}/lib/xorg/modules/extensions/libglx.so \
133
		${STAGEDIR}${PREFIX}/lib/xorg/modules/extensions/.xorg/
109
		${STAGEDIR}${PREFIX}/lib/xorg/modules/extensions/.xorg/
134
	@${MKDIR} ${STAGEDIR}${PREFIX}/etc/X11/xorg.conf.d
110
	@${MKDIR} ${STAGEDIR}${PREFIX}/etc/X11/xorg.conf.d
135
.endif # ! SLAVE_PORT
111
.endif # ! SLAVE_PORT
(-)x11-servers/xorg-server/distinfo (-3 / +3 lines)
Lines 1-3 Link Here
1
TIMESTAMP = 1484803304
1
TIMESTAMP = 1488552223
2
SHA256 (xorg/xserver/xorg-server-1.18.4.tar.bz2) = 278459b2c31d61a15655d95a72fb79930c480a6bb8cf9226e48a07df8b1d31c8
2
SHA256 (xorg/xserver/xorg-server-1.19.2.tar.bz2) = 4f8ab9f4a1a885fe7550080555381b34b82858582559e8e3c4da96e3a85884bb
3
SIZE (xorg/xserver/xorg-server-1.18.4.tar.bz2) = 6009508
3
SIZE (xorg/xserver/xorg-server-1.19.2.tar.bz2) = 5969543
(-)x11-servers/xorg-server/files/patch-config_Makefile.am (+16 lines)
Line 0 Link Here
1
* Build the devd config backend if activated
2
*
3
--- config/Makefile.am.orig	2017-03-10 14:14:25 UTC
4
+++ config/Makefile.am
5
@@ -4,6 +4,11 @@ noinst_LTLIBRARIES = libconfig.la
6
 libconfig_la_SOURCES = config.c config-backends.h
7
 libconfig_la_LIBADD =
8
 
9
+if CONFIG_DEVD
10
+libconfig_la_SOURCES += devd.c
11
+libconfig_la_LIBADD += -lusbhid
12
+endif
13
+
14
 if NEED_DBUS
15
 AM_CFLAGS += $(DBUS_CFLAGS)
16
 libconfig_la_SOURCES += dbus-core.c
(-)x11-servers/xorg-server/files/patch-config_Makefile.in (+91 lines)
Line 0 Link Here
1
* generated from patched Makefile.am; revise and regen instead of editing
2
*
3
* Build the devd config backend if activated
4
*
5
--- config/Makefile.in.orig	2017-03-10 14:14:25 UTC
6
+++ config/Makefile.in
7
@@ -89,16 +89,18 @@ PRE_UNINSTALL = :
8
 POST_UNINSTALL = :
9
 build_triplet = @build@
10
 host_triplet = @host@
11
-@NEED_DBUS_TRUE@am__append_1 = $(DBUS_CFLAGS)
12
-@NEED_DBUS_TRUE@am__append_2 = dbus-core.c
13
-@NEED_DBUS_TRUE@am__append_3 = $(DBUS_LIBS)
14
-@CONFIG_UDEV_TRUE@am__append_4 = $(UDEV_CFLAGS)
15
-@CONFIG_UDEV_TRUE@am__append_5 = udev.c
16
-@CONFIG_UDEV_TRUE@am__append_6 = $(UDEV_LIBS)
17
-@CONFIG_HAL_TRUE@@CONFIG_UDEV_FALSE@am__append_7 = $(HAL_CFLAGS)
18
-@CONFIG_HAL_TRUE@@CONFIG_UDEV_FALSE@am__append_8 = hal.c
19
-@CONFIG_HAL_TRUE@@CONFIG_UDEV_FALSE@am__append_9 = $(HAL_LIBS)
20
-@CONFIG_HAL_FALSE@@CONFIG_UDEV_FALSE@@CONFIG_WSCONS_TRUE@am__append_10 = wscons.c
21
+@CONFIG_DEVD_TRUE@am__append_1 = devd.c
22
+@CONFIG_DEVD_TRUE@am__append_2 = -lusbhid
23
+@NEED_DBUS_TRUE@am__append_3 = $(DBUS_CFLAGS)
24
+@NEED_DBUS_TRUE@am__append_4 = dbus-core.c
25
+@NEED_DBUS_TRUE@am__append_5 = $(DBUS_LIBS)
26
+@CONFIG_UDEV_TRUE@am__append_6 = $(UDEV_CFLAGS)
27
+@CONFIG_UDEV_TRUE@am__append_7 = udev.c
28
+@CONFIG_UDEV_TRUE@am__append_8 = $(UDEV_LIBS)
29
+@CONFIG_HAL_TRUE@@CONFIG_UDEV_FALSE@am__append_9 = $(HAL_CFLAGS)
30
+@CONFIG_HAL_TRUE@@CONFIG_UDEV_FALSE@am__append_10 = hal.c
31
+@CONFIG_HAL_TRUE@@CONFIG_UDEV_FALSE@am__append_11 = $(HAL_LIBS)
32
+@CONFIG_HAL_FALSE@@CONFIG_UDEV_FALSE@@CONFIG_WSCONS_TRUE@am__append_12 = wscons.c
33
 subdir = config
34
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
35
 am__aclocal_m4_deps = $(top_srcdir)/m4/ac_define_dir.m4 \
36
@@ -126,16 +128,18 @@ am__DEPENDENCIES_1 =
37
 @CONFIG_UDEV_TRUE@am__DEPENDENCIES_3 = $(am__DEPENDENCIES_1)
38
 @CONFIG_HAL_TRUE@@CONFIG_UDEV_FALSE@am__DEPENDENCIES_4 =  \
39
 @CONFIG_HAL_TRUE@@CONFIG_UDEV_FALSE@	$(am__DEPENDENCIES_1)
40
-libconfig_la_DEPENDENCIES = $(am__DEPENDENCIES_2) \
41
-	$(am__DEPENDENCIES_3) $(am__DEPENDENCIES_4)
42
-am__libconfig_la_SOURCES_DIST = config.c config-backends.h dbus-core.c \
43
-	udev.c hal.c wscons.c
44
-@NEED_DBUS_TRUE@am__objects_1 = dbus-core.lo
45
-@CONFIG_UDEV_TRUE@am__objects_2 = udev.lo
46
-@CONFIG_HAL_TRUE@@CONFIG_UDEV_FALSE@am__objects_3 = hal.lo
47
-@CONFIG_HAL_FALSE@@CONFIG_UDEV_FALSE@@CONFIG_WSCONS_TRUE@am__objects_4 = wscons.lo
48
+libconfig_la_DEPENDENCIES = $(am__DEPENDENCIES_1) \
49
+	$(am__DEPENDENCIES_2) $(am__DEPENDENCIES_3) \
50
+	$(am__DEPENDENCIES_4)
51
+am__libconfig_la_SOURCES_DIST = config.c config-backends.h devd.c \
52
+	dbus-core.c udev.c hal.c wscons.c
53
+@CONFIG_DEVD_TRUE@am__objects_1 = devd.lo
54
+@NEED_DBUS_TRUE@am__objects_2 = dbus-core.lo
55
+@CONFIG_UDEV_TRUE@am__objects_3 = udev.lo
56
+@CONFIG_HAL_TRUE@@CONFIG_UDEV_FALSE@am__objects_4 = hal.lo
57
+@CONFIG_HAL_FALSE@@CONFIG_UDEV_FALSE@@CONFIG_WSCONS_TRUE@am__objects_5 = wscons.lo
58
 am_libconfig_la_OBJECTS = config.lo $(am__objects_1) $(am__objects_2) \
59
-	$(am__objects_3) $(am__objects_4)
60
+	$(am__objects_3) $(am__objects_4) $(am__objects_5)
61
 libconfig_la_OBJECTS = $(am_libconfig_la_OBJECTS)
62
 AM_V_lt = $(am__v_lt_@AM_V@)
63
 am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
64
@@ -586,12 +590,14 @@ target_alias = @target_alias@
65
 top_build_prefix = @top_build_prefix@
66
 top_builddir = @top_builddir@
67
 top_srcdir = @top_srcdir@
68
-AM_CFLAGS = $(DIX_CFLAGS) $(am__append_1) $(am__append_4) \
69
-	$(am__append_7)
70
+AM_CFLAGS = $(DIX_CFLAGS) $(am__append_3) $(am__append_6) \
71
+	$(am__append_9)
72
 noinst_LTLIBRARIES = libconfig.la
73
-libconfig_la_SOURCES = config.c config-backends.h $(am__append_2) \
74
-	$(am__append_5) $(am__append_8) $(am__append_10)
75
-libconfig_la_LIBADD = $(am__append_3) $(am__append_6) $(am__append_9)
76
+libconfig_la_SOURCES = config.c config-backends.h $(am__append_1) \
77
+	$(am__append_4) $(am__append_7) $(am__append_10) \
78
+	$(am__append_12)
79
+libconfig_la_LIBADD = $(am__append_2) $(am__append_5) $(am__append_8) \
80
+	$(am__append_11)
81
 @CONFIG_UDEV_TRUE@@XORG_TRUE@xorgconfddir = $(datadir)/X11/$(XF86CONFIGDIR)
82
 @CONFIG_UDEV_TRUE@@XORG_TRUE@xorgconfd_DATA = 10-quirks.conf
83
 EXTRA_DIST = x11-input.fdi fdi2iclass.py 10-quirks.conf
84
@@ -651,6 +657,7 @@ distclean-compile:
85
 
86
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/config.Plo@am__quote@
87
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dbus-core.Plo@am__quote@
88
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/devd.Plo@am__quote@
89
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hal.Plo@am__quote@
90
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/udev.Plo@am__quote@
91
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wscons.Plo@am__quote@
(-)x11-servers/xorg-server/files/patch-config_config-backends.h (-6 / +7 lines)
Lines 1-11 Link Here
1
--- config/config-backends.h.orig	2016-07-15 16:17:45 UTC
1
* Define required functions for devd config backend
2
*
3
--- config/config-backends.h.orig	2017-03-02 23:03:58 UTC
2
+++ config/config-backends.h
4
+++ config/config-backends.h
3
@@ -44,3 +44,8 @@ void config_hal_fini(void);
5
@@ -43,4 +43,7 @@ void config_hal_fini(void);
6
 #elif defined(CONFIG_WSCONS)
4
 int config_wscons_init(void);
7
 int config_wscons_init(void);
5
 void config_wscons_fini(void);
8
 void config_wscons_fini(void);
6
 #endif
9
+#elif defined(CONFIG_DEVD)
7
+
8
+#ifdef CONFIG_DEVD
9
+int config_devd_init(void);
10
+int config_devd_init(void);
10
+void config_devd_fini(void);
11
+void config_devd_fini(void);
11
+#endif
12
 #endif
(-)x11-servers/xorg-server/files/patch-config_config.c (-1 / +3 lines)
Lines 1-4 Link Here
1
--- config/config.c.orig	2016-07-19 17:07:29 UTC
1
* Call the devd config backend functions if activated
2
*
3
--- config/config.c.orig	2017-03-02 23:03:58 UTC
2
+++ config/config.c
4
+++ config/config.c
3
@@ -55,6 +55,9 @@ config_init(void)
5
@@ -55,6 +55,9 @@ config_init(void)
4
 #elif defined(CONFIG_WSCONS)
6
 #elif defined(CONFIG_WSCONS)
(-)x11-servers/xorg-server/files/patch-config_devd.c (-346 / +701 lines)
Lines 1-11 Link Here
1
--- config/devd.c.orig	2017-01-19 15:20:42 UTC
1
--- config/devd.c.orig	2017-03-10 14:14:25 UTC
2
+++ config/devd.c
2
+++ config/devd.c
3
@@ -0,0 +1,532 @@
3
@@ -0,0 +1,887 @@
4
+/*
4
+/*
5
+ * Copyright (c) 2012 Baptiste Daroussin
5
+ * Copyright (c) 2012 Baptiste Daroussin
6
+ * Copyright (c) 2013, 2014 Alex Kozlov
6
+ * Copyright (c) 2013, 2014 Alex Kozlov
7
+ * Copyright (c) 2014 Robert Millan
7
+ * Copyright (c) 2014 Robert Millan
8
+ * Copyright (c) 2014 Jean-Sebastien Pedron
8
+ * Copyright (c) 2014 Jean-Sebastien Pedron
9
+ * Copyright (c) 2015 - 2017 Rozhuk Ivan
10
+ * Copyright (c) 2017 Matthew Rezny
9
+ *
11
+ *
10
+ * Permission is hereby granted, free of charge, to any person obtaining a
12
+ * Permission is hereby granted, free of charge, to any person obtaining a
11
+ * copy of this software and associated documentation files (the "Software"),
13
+ * copy of this software and associated documentation files (the "Software"),
Lines 39-46 Link Here
39
+#include <sys/stat.h>
41
+#include <sys/stat.h>
40
+#include <sys/sysctl.h>
42
+#include <sys/sysctl.h>
41
+#include <sys/un.h>
43
+#include <sys/un.h>
44
+#include <sys/mouse.h>
45
+#include <sys/consio.h>
46
+#include <sys/ioctl.h>
47
+#include <dev/usb/usb_ioctl.h>
48
+#include <dev/usb/usbhid.h>
42
+
49
+
43
+#include <ctype.h>
50
+#include <ctype.h>
51
+#include <dirent.h>
44
+#include <errno.h>
52
+#include <errno.h>
45
+#include <fcntl.h>
53
+#include <fcntl.h>
46
+#include <stdlib.h>
54
+#include <stdlib.h>
Lines 47-52 Link Here
47
+#include <stdio.h>
55
+#include <stdio.h>
48
+#include <stdbool.h>
56
+#include <stdbool.h>
49
+#include <unistd.h>
57
+#include <unistd.h>
58
+#include <string.h>
59
+#include <paths.h>
60
+#include <usbhid.h>
50
+
61
+
51
+#include "input.h"
62
+#include "input.h"
52
+#include "inputstr.h"
63
+#include "inputstr.h"
Lines 54-493 Link Here
54
+#include "config-backends.h"
65
+#include "config-backends.h"
55
+#include "os.h"
66
+#include "os.h"
56
+
67
+
57
+#define DEVD_SOCK_PATH "/var/run/devd.pipe"
68
+/* from: <linux/input.h> */
69
+#define	_IOC_READ   IOC_OUT
70
+struct input_id {
71
+	uint16_t bustype;
72
+	uint16_t vendor;
73
+	uint16_t product;
74
+	uint16_t version;
75
+};
58
+
76
+
77
+#define	EVIOCGBIT(ev, len)	_IOC(_IOC_READ, 'E', 0x20 + (ev), (len))
78
+#define	EVIOCGID		_IOR('E', 0x02, struct input_id)
79
+#define	EVIOCGNAME(len)		_IOC(_IOC_READ, 'E', 0x06, (len))
80
+#define	EVIOCGPHYS(len)		_IOC(_IOC_READ, 'E', 0x07, (len))
81
+
82
+#define	EV_KEY			0x01
83
+#define	EV_REL			0x02
84
+#define	EV_ABS			0x03
85
+#define	BTN_MISC		0x100
86
+#define	BTN_LEFT		0x110
87
+#define	BTN_RIGHT		0x111
88
+#define	BTN_MIDDLE		0x112
89
+#define	BTN_JOYSTICK		0x120
90
+#define	BTN_TOOL_PEN		0x140
91
+#define	BTN_TOOL_FINGER		0x145
92
+#define	BTN_TOUCH		0x14a
93
+#define	BTN_STYLUS		0x14b
94
+#define	BTN_STYLUS2		0x14c
95
+#define	KEY_MAX			0x2ff
96
+#define	KEY_CNT			(KEY_MAX + 1)
97
+#define	REL_X			0x00
98
+#define	REL_Y			0x01
99
+#define	REL_MAX			0x0f
100
+#define	REL_CNT			(REL_MAX + 1)
101
+#define	ABS_X			0x00
102
+#define	ABS_Y			0x01
103
+#define	ABS_PRESSURE		0x18
104
+#define	ABS_MT_SLOT		0x2f
105
+#define	ABS_MAX			0x3f
106
+#define	ABS_CNT			(ABS_MAX + 1)
107
+
108
+#define	U32_BITS		(sizeof(uint32_t) * 8)
109
+#define	U32_CNT(__x)		(((__x) + U32_BITS - 1) / U32_BITS)
110
+#define U32_IS_BIT_SET(__x, __bit) (((((const uint32_t*)(__x))[((__bit) >> 5)] >> ((__bit) & 0x1f))) & 0x01)
111
+
112
+/* from: <linux/joystick.h> */
113
+#define JSIOCGNAME(len)		_IOC(_IOC_READ, 'j', 0x13, len)		/* get identifier string */
114
+
115
+/* WebCamD specific. */
116
+#define WEBCAMD_IOCTL_GET_USB_VENDOR_ID _IOR('q', 250, unsigned short)
117
+#define WEBCAMD_IOCTL_GET_USB_PRODUCT_ID _IOR('q', 251, unsigned short)
118
+#define WEBCAMD_IOCTL_GET_USB_SPEED	_IOR('q', 252, unsigned int)
119
+
120
+#ifdef COMPAT_32BIT
121
+	#define hid_pass_ptr(ptr)	((uint64_t)(uintptr_t)(ptr))
122
+#else
123
+	#define hid_pass_ptr(ptr)	(ptr)
124
+#endif
125
+
126
+#define _PATH_DEV_LEN		(sizeof(_PATH_DEV) - 1)
127
+#define DEVD_PATH_DEV		"devd:" _PATH_DEV
128
+#define DEVD_PATH_DEV_LEN	(sizeof(DEVD_PATH_DEV) - 1)
129
+
130
+#define DEVD_SOCK_PATH		_PATH_VARRUN "devd.pipe"
131
+
59
+#define DEVD_EVENT_ADD		'+'
132
+#define DEVD_EVENT_ADD		'+'
60
+#define DEVD_EVENT_REMOVE	'-'
133
+#define DEVD_EVENT_REMOVE	'-'
134
+#define DEVD_EVENT_NOTIFY	'!'
61
+
135
+
62
+#define RECONNECT_DELAY		5 * 1000
136
+#define RECONNECT_DELAY	(5 * 1000)
63
+
137
+
64
+static int sock_devd;
138
+#define is_meuqual(__v1, __v1sz, __v2, __v2sz)				\
65
+static bool is_console_kbd = false;
139
+	((__v1sz) == (__v2sz) && NULL != (__v1) && NULL != (__v2) &&	\
66
+static bool is_kbdmux = false;
140
+	 0 == memcmp((__v1), (__v2), (__v1sz)))
141
+
142
+#define is_meuqual_cstr(__cstr, __v, __vsz)				\
143
+	is_meuqual(__cstr, (sizeof(__cstr) - 1), __v, __vsz)
144
+
145
+#define is_de_euqual_cstr(__de, __cstr)					\
146
+	(NULL != (__de) &&						\
147
+	 is_meuqual((__de)->d_name, (__de)->d_namlen, __cstr, (sizeof(__cstr) - 1)))
148
+
149
+#define devd_get_val_cstr(__cstr, __buf, __bufsz, __valsz)		\
150
+	devd_get_val((__buf), (__bufsz), __cstr, (sizeof(__cstr) - 1),	\
151
+	(__valsz))
152
+
153
+static int devd_skt = 0;
154
+static char devd_buf[4096];
155
+static size_t devd_buf_used = 0;
156
+static int is_kbdmux = 0;
67
+static OsTimerPtr rtimer = NULL;
157
+static OsTimerPtr rtimer = NULL;
68
+
158
+
69
+struct hw_type {
159
+/* Input devices. */
70
+	const char *driver;
160
+typedef struct hw_type_s {
71
+	int flag;
161
+	const char	*dev_name;
72
+	const char *xdriver;
162
+	size_t		dev_name_size;
163
+	size_t		path_offset;
164
+	int		flags;
165
+	const char	*xdriver; 
166
+} hw_type_t, *hw_type_p;
167
+
168
+/* xdriver can be set via config "InputClass" section.
169
+ * Do not set xdriver name if device have more than one
170
+ * xf86-input-* drivers.
171
+ * "input/event" can be hadled by: xf86-input-evdev and
172
+ * xf86-input-wacom, let user choose.
173
+ */
174
+static hw_type_t hw_types[] = {
175
+	{ "uhid",	4, 0, 0, NULL },
176
+	{ "ukbd",	4, 0, ATTR_KEY | ATTR_KEYBOARD, "kbd" },
177
+	{ "atkbd",	5, 0, ATTR_KEY | ATTR_KEYBOARD, "kbd" },
178
+	{ "kbdmux",	6, 0, ATTR_KEY | ATTR_KEYBOARD, "kbd" },
179
+	{ "sysmouse",	8, 0, ATTR_POINTER, "mouse" },
180
+	{ "ums",	3, 0, ATTR_POINTER, "mouse" },
181
+	{ "psm",	3, 0, ATTR_POINTER, "mouse" },
182
+	{ "vboxguest",	9, 0, ATTR_POINTER, "vboxmouse" },
183
+	{ "joy",	3, 0, ATTR_JOYSTICK, NULL },
184
+	{ "atp",	3, 0, ATTR_TOUCHPAD, NULL },
185
+	{ "uep",	3, 0, ATTR_TOUCHSCREEN, NULL },
186
+	{ "input/event",5, 6, 0, NULL },
187
+	{ "input/js",	2, 6, ATTR_JOYSTICK, NULL },
188
+	{ NULL,		0, 0, 0, NULL },
73
+};
189
+};
74
+
190
+
75
+static struct hw_type hw_types[] = {
191
+/* Input devices paths. */
76
+	{ "ukbd", ATTR_KEYBOARD, "kbd" },
192
+static hw_type_t hw_type_path[] = {
77
+	{ "atkbd", ATTR_KEYBOARD, "kbd" },
193
+	{ "input/",	0, 6, 0, NULL },
78
+	{ "kbdmux", ATTR_KEYBOARD, "kbd" },
194
+	{ NULL,		0, 0, 0, NULL },
79
+	{ "sysmouse", ATTR_POINTER, "mouse" },
80
+	{ "ums", ATTR_POINTER, "mouse" },
81
+	{ "psm", ATTR_POINTER, "mouse" },
82
+	{ "vboxguest", ATTR_POINTER, "vboxmouse" },
83
+	{ "joy", ATTR_JOYSTICK, NULL },
84
+	{ "atp", ATTR_TOUCHPAD, NULL },
85
+	{ "uep", ATTR_TOUCHSCREEN, NULL },
86
+	{ NULL, -1, NULL },
87
+};
195
+};
88
+
196
+
89
+static bool
197
+static size_t
90
+sysctl_exists(const struct hw_type *device, int unit,
198
+bits_calc(const uint32_t *bits, size_t off_start, size_t off_stop)
91
+	char *devname, size_t devname_len)
92
+{
199
+{
93
+	char sysctlname[PATH_MAX];
200
+	size_t count = 0;
94
+	size_t len;
95
+	int ret;
96
+
201
+
97
+	if (device == NULL || device->driver == NULL)
202
+	for (size_t i = off_start; i < off_stop; ++i) {
98
+		return false;
203
+		if (U32_IS_BIT_SET(bits, i)) {
204
+			++count;
205
+		}
206
+	}
207
+	return count;
208
+}
99
+
209
+
100
+	/* Check if a sysctl exists. */
210
+static hw_type_p
101
+	snprintf(sysctlname, sizeof(sysctlname), "dev.%s.%i.%%desc",
211
+get_dev_type_by_name(const char *dev_name, size_t dev_name_size)
102
+	    device->driver, unit);
212
+{
103
+	ret = sysctlbyname(sysctlname, NULL, &len, NULL, 0);
213
+	if (!dev_name || !dev_name_size)
214
+		return NULL;
104
+
215
+
105
+	if (ret == 0 && len > 0) {
216
+	for (size_t i = 0; hw_types[i].dev_name; ++i) {
106
+		snprintf(devname, devname_len, "%s%i", device->driver, unit);
217
+		if (dev_name_size >= (hw_types[i].dev_name_size + hw_types[i].path_offset) &&
107
+		return true;
218
+		    !memcmp(dev_name, hw_types[i].dev_name, (hw_types[i].path_offset + hw_types[i].dev_name_size))) {
219
+			return &hw_types[i];
220
+		}
108
+	}
221
+	}
222
+	return NULL;
223
+}
109
+
224
+
110
+	return false;
225
+/* From: sys/dev/usb/usb_hid.c */
226
+static int
227
+hid_is_collection(report_desc_t s, uint32_t usage)
228
+{
229
+	struct hid_data* hd = hid_start_parse(s, ~0, -1);
230
+	if (!hd)
231
+		return 0;
232
+
233
+	struct hid_item hi;
234
+	int rc;
235
+	while ((rc = hid_get_item(hd, &hi))) {
236
+		 if (hi.kind == hid_collection && hi.usage == usage)
237
+			break;
238
+	}
239
+	hid_end_parse(hd);
240
+	return rc;
111
+}
241
+}
112
+
242
+
113
+static bool
243
+static int
114
+devpath_exists(const struct hw_type *device,
244
+hid_is_mouse(report_desc_t s)
115
+	char *devname, size_t devname_len)
116
+{
245
+{
117
+	char *devpath;
246
+	struct hid_data* hd = hid_start_parse(s, (1 << hid_input), -1);
118
+	struct stat st;
247
+	if (!hd)
119
+	int ret;
248
+		return 0;
120
+
249
+
121
+	if (device == NULL || device->driver == NULL)
250
+	struct hid_item hi;
122
+		return false;
251
+	int found = 0, mdepth = 0;
252
+	while (hid_get_item(hd, &hi)) {
253
+		switch (hi.kind) {
254
+		case hid_collection:
255
+			if (mdepth != 0)
256
+				++mdepth;
257
+			else if (hi.collection == 1 &&
258
+			         hi.usage == HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_MOUSE))
259
+				++mdepth;
260
+			break;
261
+		case hid_endcollection:
262
+			if (mdepth)
263
+				--mdepth;
264
+			break;
265
+		case hid_input:
266
+			if (!mdepth)
267
+				break;
268
+			if (hi.usage == HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_X) &&
269
+			    (hi.flags & (HIO_CONST|HIO_RELATIVE)) == HIO_RELATIVE)
270
+				++found;
271
+			if (hi.usage == HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_Y) &&
272
+			    (hi.flags & (HIO_CONST|HIO_RELATIVE)) == HIO_RELATIVE)
273
+				++found;
274
+			break;
275
+		default:
276
+			break;
277
+		}
278
+	}
279
+	hid_end_parse(hd);
280
+	return found;
281
+}
123
+
282
+
124
+	/* Check if /dev/$driver exists. */
283
+static hw_type_p
125
+	asprintf(&devpath, "/dev/%s", device->driver);
284
+get_dev_type_by_path(const char *dev_name, size_t dev_name_size, hw_type_p hw_type_cust)
126
+	if (devpath == NULL)
285
+{
127
+		return false;
286
+	if (!dev_name || !dev_name_size || !hw_type_cust)
287
+		return NULL;
128
+
288
+
129
+	ret = stat(devpath, &st);
289
+	for (size_t i = 0; hw_type_path[i].dev_name; ++i) {
130
+	free(devpath);
290
+		if (dev_name_size <= hw_type_path[i].path_offset ||
131
+
291
+		    memcmp(dev_name, hw_type_path[i].dev_name, hw_type_path[i].path_offset))
132
+	if (ret == 0) {
292
+			continue;
133
+		strncpy(devname, device->driver, devname_len);
293
+		/* Path in white list. */
134
+		return true;
294
+		hw_type_cust->dev_name = dev_name;
295
+		hw_type_cust->flags = hw_type_path[i].flags;
296
+		hw_type_cust->xdriver = hw_type_path[i].xdriver;
297
+		hw_type_cust->path_offset = hw_type_path[i].path_offset;
298
+		size_t name_end = hw_type_cust->path_offset;
299
+		while (name_end < dev_name_size && !isdigit(dev_name[name_end]))
300
+			++name_end;
301
+		hw_type_cust->dev_name_size = (name_end - hw_type_cust->path_offset);
302
+		return hw_type_cust;
135
+	}
303
+	}
304
+	return NULL;
305
+}
136
+
306
+
137
+	return false;
307
+static int
308
+is_kbdmux_enabled(void)
309
+{
310
+	/* Xorg uses /dev/ttyv0 as a console device */
311
+	/* const char device[]="/dev/console"; */
312
+	static const char *device = _PATH_TTY "v0";
313
+
314
+	int fd = open(device, O_RDONLY);
315
+	if (fd < 0)
316
+		return 0;
317
+
318
+	keyboard_info_t info;
319
+	int ret = (ioctl(fd, KDGKBINFO, &info) == -1 ||
320
+	           memcmp(info.kb_name, "kbdmux", 6)) ? 0 : 1;
321
+	close(fd);
322
+	return ret;
138
+}
323
+}
139
+
324
+
140
+static char *
325
+static char *
141
+sysctl_get_str(const char *sysctlname)
326
+sysctl_get_str(const char *sysctlname, size_t *size_ret)
142
+{
327
+{
143
+	char *dest = NULL;
328
+	if (!sysctlname)
144
+	size_t len;
329
+		return NULL;
145
+
330
+
146
+	if (sysctlname == NULL)
331
+	size_t len = 0;
332
+	if (sysctlbyname(sysctlname, NULL, &len, NULL, 0) || !len)
147
+		return NULL;
333
+		return NULL;
148
+
334
+
149
+	if (sysctlbyname(sysctlname, NULL, &len, NULL, 0) == 0) {
335
+	char* dest = malloc(len + 1);
150
+		dest = malloc(len + 1);
336
+	if (!dest)
151
+		if (dest) {
337
+		return NULL;
152
+			if (sysctlbyname(sysctlname, dest, &len, NULL, 0) == 0)
338
+
153
+				dest[len] = '\0';
339
+	if (sysctlbyname(sysctlname, dest, &len, NULL, 0)) {
154
+			else {
340
+		free(dest);
155
+				free(dest);
341
+		return NULL;
156
+				dest = NULL;
157
+			}
158
+		}
159
+	}
342
+	}
160
+
343
+	dest[len] = 0;
344
+	if (size_ret)
345
+		*size_ret = len;
161
+	return dest;
346
+	return dest;
162
+}
347
+}
163
+
348
+
164
+static void
349
+static char *
165
+device_added(const char *devname)
350
+devd_get_val(char *buf, size_t buf_size, const char *val_name, size_t val_name_size, size_t *val_size)
166
+{
351
+{
167
+	char path[PATH_MAX];
352
+	if (!buf || !buf_size || !val_name || !val_name_size)
168
+	char sysctlname[PATH_MAX];
353
+		return NULL;
169
+	char *vendor;
170
+	char *product = NULL;
171
+	char *config_info = NULL;
172
+	char *walk;
173
+	InputOption *options = NULL;
174
+	InputAttributes attrs = { };
175
+	DeviceIntPtr dev = NULL;
176
+	int i;
177
+	int fd;
178
+
354
+
179
+	for (i = 0; hw_types[i].driver != NULL; i++) {
355
+	char *ret = buf, *buf_end = (buf + buf_size);
180
+		size_t len;
356
+	while (ret && ret < buf_end) {
181
+
357
+		ret = memmem(ret, (buf_end - ret), val_name, val_name_size);
182
+		len = strlen(hw_types[i].driver);
358
+		if (!ret)
183
+		if (strcmp(devname, hw_types[i].driver) == 0 ||
359
+			return NULL;
184
+			(strncmp(devname, hw_types[i].driver, len) == 0 &&
360
+		/* Found. */
185
+				isnumber(*(devname + len)))) {
361
+		/* Check: space before or buf+1. */
186
+			attrs.flags |= hw_types[i].flag;
362
+		if ((buf + 1) < ret && ret[-1] != ' ') {
187
+			break;
363
+			ret += val_name_size;
364
+			continue;
188
+		}
365
+		}
366
+		/* Check: = after name and size for value. */
367
+		ret += val_name_size;
368
+		if ((ret + 1) >= buf_end)
369
+			return NULL;
370
+		if (ret[0] != '=')
371
+			continue;
372
+		++ret;
373
+		break;
189
+	}
374
+	}
375
+	if (!ret || !val_size)
376
+		return ret;
377
+	/* Calc value data size. */
378
+	char* ptr = memchr(ret, ' ', (buf_end - ret));
379
+	if (!ptr) /* End of string/last value. */
380
+		ptr = buf_end;
381
+	*val_size = (ptr - ret);
382
+	return ret;
383
+}
190
+
384
+
191
+	if (hw_types[i].driver == NULL || hw_types[i].xdriver == NULL) {
385
+static void
192
+		LogMessage(X_INFO, "config/devd: ignoring device %s\n",
386
+device_added(const char *dev_name, size_t dev_name_size, int allow_no_device)
193
+				devname);
387
+{
388
+	if (!dev_name || !dev_name_size || dev_name_size > PATH_MAX)
194
+		return;
389
+		return;
390
+
391
+	char config_info[(PATH_MAX + 32)];
392
+	/* Make dev_name null ended string. */
393
+	snprintf(config_info, sizeof(config_info), DEVD_PATH_DEV"%.*s", (int)dev_name_size, dev_name);
394
+	/* Set / update pointers to dev_name and dev_path. */
395
+	char* dev_path = (config_info + 5); /* Skip: "devd:" */
396
+	dev_name = (dev_path + _PATH_DEV_LEN); /* Skip: "/dev/" */
397
+
398
+	/* Is known input device or path? */
399
+	hw_type_t *hwtype = get_dev_type_by_name(dev_name, dev_name_size);
400
+	if (!hwtype) {
401
+		hw_type_t hwtype_cust;
402
+		hwtype = get_dev_type_by_path(dev_name, dev_name_size, &hwtype_cust);
195
+	}
403
+	}
404
+	if (!hwtype) /* Not found in white list. */
405
+		return;
196
+
406
+
197
+	/* Skip keyboard devices if kbdmux is enabled */
407
+	/* Skip keyboard devices if kbdmux is enabled */
198
+	if (is_kbdmux && is_console_kbd && hw_types[i].flag & ATTR_KEYBOARD) {
408
+	if (is_kbdmux && !allow_no_device && (hwtype->flags & ATTR_KEYBOARD)) {
199
+		LogMessage(X_INFO, "config/devd: kbdmux is enabled, ignoring device %s\n",
409
+		LogMessage(X_INFO, "config/devd: kbdmux is enabled, ignoring device %s\n", dev_name);
200
+				devname);
201
+		return;
410
+		return;
202
+	}
411
+	}
203
+
412
+	/* Skip duplicate devices. */
204
+	snprintf(path, sizeof(path), "/dev/%s", devname);
413
+	if (device_is_duplicate(config_info)) {
205
+
414
+		LogMessage(X_WARNING, "config/devd: device %s already added. ignoring\n", dev_path);
206
+	options = input_option_new(NULL, "_source", "server/devd");
207
+	if (!options)
208
+		return;
415
+		return;
209
+
210
+	snprintf(sysctlname, sizeof(sysctlname), "dev.%s.%s.%%desc",
211
+	    hw_types[i].driver, devname + strlen(hw_types[i].driver));
212
+	vendor = sysctl_get_str(sysctlname);
213
+	if (vendor == NULL) {
214
+		options = input_option_new(options, "name", devname);
215
+	}
416
+	}
216
+	else {
217
+		if ((walk = strchr(vendor, ' ')) != NULL) {
218
+			walk[0] = '\0';
219
+			walk++;
220
+			product = walk;
221
+			if ((walk = strchr(product, ',')) != NULL)
222
+				walk[0] = '\0';
223
+		}
224
+
417
+
225
+		attrs.vendor = strdup(vendor);
418
+	/* Init and set attributes. */
226
+		if (product) {
419
+	char pnp_usb_id[PATH_MAX], product[PATH_MAX], vendor[PATH_MAX];
227
+			attrs.product = strdup(product);
420
+	InputAttributes attrs;
228
+			options = input_option_new(options, "name", product);
421
+	memset(&attrs, 0, sizeof(attrs));
229
+		}
422
+	attrs.device = dev_path;
230
+		else
423
+	attrs.flags = hwtype->flags;
231
+			options = input_option_new(options, "name", "(unnamed)");
232
+
424
+
233
+		free(vendor);
425
+	/* Try to open device. */
234
+	}
426
+	int fd = open(dev_path, O_RDONLY);
235
+
427
+	if (fd < 0) {
236
+	/* XXX implement usb_id */
428
+		if (!(hwtype->flags & (ATTR_KEY | ATTR_KEYBOARD))) {
237
+	attrs.usb_id = NULL;
238
+	attrs.device = strdup(path);
239
+	options = input_option_new(options, "driver", hw_types[i].xdriver);
240
+
241
+	fd = open(path, O_RDONLY);
242
+	if (fd > 0) {
243
+		close(fd);
244
+		options = input_option_new(options, "device", path);
245
+	}
246
+	else {
247
+		if (attrs.flags & ~ATTR_KEYBOARD) {
248
+			LogMessage(X_INFO, "config/devd: device %s already opened\n",
249
+					 path);
250
+
251
+			/*
429
+			/*
252
+			 * Fail if cannot open device, it breaks AllowMouseOpenFail,
430
+			 * Fail if cannot open device, it breaks AllowMouseOpenFail,
253
+			 * but it should not matter when config/devd enabled
431
+			 * but it should not matter when config/devd is enabled
254
+			 */
432
+			 */
255
+			goto unwind;
433
+			LogMessage(X_WARNING, "config/devd: device %s already opened\n", dev_path);
434
+			return;
256
+		}
435
+		}
257
+
436
+		if (!allow_no_device) {
258
+		if (is_console_kbd) {
259
+			/*
437
+			/*
260
+			 * There can be only one keyboard attached to console and
438
+			 * There can be only one keyboard attached to console and
261
+			 * it is already added.
439
+			 * it is already added.
262
+			 */
440
+			 */
263
+			LogMessage(X_WARNING, "config/devd: console keyboard is "
441
+			LogMessage(X_WARNING, "config/devd: console keyboard is already added, ignoring %s\n", dev_path);
264
+					"already added, ignoring %s (%s)\n",
442
+			return;
265
+					attrs.product, path);
266
+			goto unwind;
267
+		}
443
+		}
268
+		else
444
+	} else {
269
+			/*
445
+		/* Try to get device info via ioctl(). */
270
+			 * Don't pass "device" option if the keyboard is already
446
+		keyboard_info_t kbdi;
271
+			 * attached to the console (ie. open() fails).
447
+		mousehw_t mshw;
272
+			 * This would activate a special logic in xf86-input-keyboard.
448
+		struct input_id iid;
273
+			 * Prevent any other attached to console keyboards being
449
+		report_desc_t rep_desc;
274
+			 * processed. There can be only one such device.
275
+			 */
276
+			is_console_kbd = true;
277
+	}
278
+
450
+
279
+	if (asprintf(&config_info, "devd:%s", devname) == -1) {
451
+		if (ioctl(fd, KDGKBINFO, &kbdi) != -1) { /* Is this keyboard? */
280
+		config_info = NULL;
452
+			memcpy(product, kbdi.kb_name, sizeof(kbdi.kb_name));
281
+		goto unwind;
453
+			attrs.product = product;
454
+			attrs.flags = ATTR_KEY | ATTR_KEYBOARD;
455
+			LogMessage(X_INFO, "config/devd: detected keyboard: %s, kb_index=%i, kb_unit=%i, kb_type=%i, kb_config=%i\n",
456
+			           kbdi.kb_name, kbdi.kb_index, kbdi.kb_unit, kbdi.kb_type, kbdi.kb_config);
457
+		} else if (ioctl(fd, MOUSE_GETHWINFO, &mshw) != -1) { /* Is this mouse? */
458
+			/* FreeBSD mouse drivers does not return real vid+pid. */
459
+			/* construct USB ID in lowercase hex - "0000:ffff" */
460
+			if (mshw.hwid || mshw.model) {
461
+				snprintf(pnp_usb_id, sizeof(pnp_usb_id), "%04x:%04x", mshw.hwid, mshw.model);
462
+				attrs.usb_id = pnp_usb_id;
463
+			}
464
+
465
+			switch (mshw.type) {
466
+			case MOUSE_MOUSE:
467
+			case MOUSE_TRACKBALL:
468
+			case MOUSE_STICK:
469
+				attrs.flags = ATTR_POINTER;
470
+				break;
471
+			case MOUSE_PAD:
472
+				attrs.flags = ATTR_TOUCHPAD;
473
+				break;
474
+			}
475
+			LogMessage(X_INFO, "config/devd: detected mouse: hwid=%04x, model=%04x, type=%04x, iftype=%04x, buttons=%04x\n",
476
+			           mshw.hwid, mshw.model, mshw.type, mshw.iftype, mshw.buttons);
477
+		} else if (ioctl(fd, JSIOCGNAME((sizeof(product) - 1)), product) != -1) { /* Is this joystick? */
478
+			attrs.product = product;
479
+			attrs.flags = ATTR_JOYSTICK;
480
+			LogMessage(X_INFO, "config/devd: detected joystick: %s\n", product);
481
+		} else if (ioctl(fd, EVIOCGID, &iid) != -1 &&
482
+		           ioctl(fd, EVIOCGNAME((sizeof(product) - 1)), product) != -1) { /* Is this event? */
483
+			/* construct USB ID in lowercase hex - "0000:ffff" */
484
+			snprintf(pnp_usb_id, sizeof(pnp_usb_id), "%04x:%04x", iid.vendor, iid.product);
485
+			attrs.usb_id = pnp_usb_id;
486
+			attrs.product = product;
487
+
488
+			/* Detect device type. */
489
+			uint32_t key_bits[U32_CNT(KEY_CNT)];
490
+			size_t has_keys = 0, has_buttons = 0, has_lmr = 0;
491
+			if (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(key_bits)), key_bits) != -1) {
492
+				has_keys = bits_calc(key_bits, 0, BTN_MISC);
493
+				has_buttons = bits_calc(key_bits, BTN_MISC, BTN_JOYSTICK);
494
+				has_lmr = bits_calc(key_bits, BTN_LEFT, BTN_MIDDLE);
495
+			}
496
+			uint32_t rel_bits[U32_CNT(REL_CNT)];
497
+			size_t has_rel_axes = 0;
498
+			if (ioctl(fd, EVIOCGBIT(EV_REL, sizeof(rel_bits)), rel_bits) != -1) {
499
+				has_rel_axes = bits_calc(rel_bits, 0, REL_MAX);
500
+			}
501
+			uint32_t abs_bits[U32_CNT(ABS_CNT)];
502
+			size_t has_abs_axes = 0, has_mt = 0;
503
+			if (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(abs_bits)), abs_bits) != -1) {
504
+				has_abs_axes = bits_calc(abs_bits, 0, ABS_MAX);
505
+				has_mt = bits_calc(abs_bits, ABS_MT_SLOT, ABS_MAX);
506
+			}
507
+
508
+			bool done = false;
509
+			if (has_abs_axes) {
510
+				if (has_mt) {
511
+					if (!has_buttons) {
512
+						/*
513
+						 * XXX: I'm not sure that joystick detection is
514
+						 * done right. xf86-evdev does not support them.
515
+						 */
516
+						if (U32_IS_BIT_SET(key_bits, BTN_JOYSTICK)) {
517
+							attrs.flags = ATTR_JOYSTICK;
518
+							done = true;
519
+						} else {
520
+							++has_buttons;
521
+						}
522
+					}
523
+				}
524
+				if (!done && U32_IS_BIT_SET(abs_bits, ABS_X) && U32_IS_BIT_SET(abs_bits, ABS_Y)) {
525
+					if (U32_IS_BIT_SET(key_bits, BTN_TOOL_PEN) ||
526
+					    U32_IS_BIT_SET(key_bits, BTN_STYLUS) ||
527
+					    U32_IS_BIT_SET(key_bits, BTN_STYLUS2)) {
528
+						attrs.flags = ATTR_TABLET;
529
+						done = true;
530
+					} else if (U32_IS_BIT_SET(abs_bits, ABS_PRESSURE) ||
531
+						       U32_IS_BIT_SET(key_bits, BTN_TOUCH)) {
532
+						if (has_lmr || U32_IS_BIT_SET(key_bits, BTN_TOOL_FINGER)) {
533
+							attrs.flags = ATTR_TOUCHPAD;
534
+						} else {
535
+							attrs.flags = ATTR_TOUCHSCREEN;
536
+						}
537
+						done = true;
538
+					} else if (!(U32_IS_BIT_SET(rel_bits, REL_X) &&
539
+						         U32_IS_BIT_SET(rel_bits, REL_Y)) &&  has_lmr) {
540
+						/* some touchscreens use BTN_LEFT rather than BTN_TOUCH */
541
+						attrs.flags = ATTR_TOUCHSCREEN;
542
+						done = true;
543
+					}
544
+				}
545
+			}
546
+			if (!done) {
547
+				if (has_keys) {
548
+					if (is_kbdmux) {
549
+						close(fd);
550
+						LogMessage(X_INFO, "config/devd: kbdmux is enabled, ignoring device %s\n", dev_name);
551
+						return;
552
+					}
553
+					attrs.flags = ATTR_KEY | ATTR_KEYBOARD;
554
+				} else if (has_rel_axes || has_abs_axes || has_buttons) {
555
+					attrs.flags = ATTR_POINTER;
556
+				}
557
+			}
558
+			LogMessage(X_INFO, "config/devd: detected event input: %s, bustype=%04x, vendor=%04x, product=%04x, version=%04x\n",
559
+			           product, iid.bustype, iid.vendor, iid.product, iid.version);
560
+		} else if ((rep_desc = hid_get_report_desc(fd))) { /* Is USB HID? */
561
+			if (hid_is_mouse(rep_desc)) {
562
+				attrs.flags = ATTR_POINTER;
563
+			} else if (hid_is_collection(rep_desc, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_KEYBOARD))) {
564
+				/* Skip keyboard devices if kbdmux is enabled */
565
+				if (is_kbdmux) {
566
+					hid_dispose_report_desc(rep_desc);
567
+					close(fd);
568
+					LogMessage(X_INFO, "config/devd: kbdmux is enabled, ignoring device %s\n", dev_name);
569
+					return;
570
+				}
571
+				attrs.flags = ATTR_KEY | ATTR_KEYBOARD;
572
+			} else if (hid_is_collection(rep_desc, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_JOYSTICK)) ||
573
+			           hid_is_collection(rep_desc, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_GAME_PAD))) {
574
+				attrs.flags = ATTR_JOYSTICK;
575
+			}
576
+			hid_dispose_report_desc(rep_desc);
577
+			LogMessage(X_INFO, "config/devd: detected USB HID...\n");
578
+		}
579
+
580
+		if (!attrs.usb_id) { /* Is this webcamd device? */
581
+			unsigned short vid, pid;
582
+			if (ioctl(fd, WEBCAMD_IOCTL_GET_USB_VENDOR_ID, &vid) != -1 &&
583
+			    ioctl(fd, WEBCAMD_IOCTL_GET_USB_PRODUCT_ID, &pid) != -1) {
584
+				snprintf(pnp_usb_id, sizeof(pnp_usb_id), "%04x:%04x", vid, pid);
585
+				attrs.usb_id = pnp_usb_id;
586
+				LogMessage(X_INFO, "config/devd: webcamd device: %s\n", pnp_usb_id);
587
+			}
588
+		}
282
+	}
589
+	}
590
+	close(fd);
283
+
591
+
284
+	if (device_is_duplicate(config_info)) {
592
+	/* Try to get device info via sysctl(). */
285
+		LogMessage(X_WARNING, "config/devd: device %s (%s) already added. "
593
+	if (!attrs.usb_id && !attrs.pnp_id) {
286
+				"ignoring\n", attrs.product, path);
594
+		char sysctlname[PATH_MAX];
287
+		goto unwind;
595
+		snprintf(sysctlname, sizeof(sysctlname), "dev.%.*s.%s.%%pnpinfo",
596
+		         (int)hwtype->dev_name_size,
597
+		         (hwtype->dev_name + hwtype->path_offset),
598
+		         (dev_name + hwtype->path_offset + hwtype->dev_name_size));
599
+		size_t sdata_size;
600
+		char* sdata = sysctl_get_str(sysctlname, &sdata_size);
601
+		if (sdata) {
602
+			size_t pid_size, vid_size;
603
+			char* ptr_vid = devd_get_val_cstr("vendor", sdata, sdata_size, &vid_size);
604
+			char* ptr_pid = devd_get_val_cstr("product", sdata, sdata_size, &pid_size);
605
+			if (ptr_vid && ptr_pid) { /* usb_id */
606
+				ptr_vid[vid_size] = 0;
607
+				ptr_pid[pid_size] = 0;
608
+				snprintf(pnp_usb_id, sizeof(pnp_usb_id), "%s:%s", ptr_vid, ptr_pid);
609
+				attrs.usb_id = pnp_usb_id;
610
+				LogMessage(X_INFO, "config/devd: [sysctl] usb_id: %s\n", pnp_usb_id);
611
+			} else { /* pnp_id */
612
+				strlcpy(pnp_usb_id, sdata, sizeof(pnp_usb_id));
613
+				attrs.pnp_id = pnp_usb_id;
614
+			}
615
+			free(sdata);
616
+		}
288
+	}
617
+	}
618
+	if (!attrs.vendor || !attrs.product) {
619
+		char sysctlname[PATH_MAX];
620
+		snprintf(sysctlname, sizeof(sysctlname), "dev.%.*s.%s.%%desc",
621
+		         (int)hwtype->dev_name_size,
622
+		         (hwtype->dev_name + hwtype->path_offset),
623
+		         (dev_name + hwtype->path_offset + hwtype->dev_name_size));
624
+		size_t sdata_size;
625
+		char* sdata = sysctl_get_str(sysctlname, &sdata_size);
626
+		if (sdata) {
627
+			/* Vendor. */
628
+			char* ptr_pid = memchr(sdata, ' ', sdata_size);
629
+			if (ptr_pid)
630
+				ptr_pid[0] = 0;
631
+			strlcpy(vendor, sdata, sizeof(vendor));
632
+			attrs.vendor = vendor;
633
+			/* Product. */
634
+			if (!attrs.product && ptr_pid) {
635
+				++ptr_pid;
636
+				char* ptr_vid = memchr(ptr_pid, ',', (sdata_size - (ptr_pid - sdata)));
637
+				if (ptr_vid)
638
+					ptr_vid[0] = 0;
639
+				strlcpy(product, ptr_pid, sizeof(product));
640
+				attrs.product = product;
641
+			} else
642
+				product[0] = 0;
643
+			free(sdata);
644
+			LogMessage(X_INFO, "config/devd: [sysctl] vendor: %s, product: %s\n", vendor, product);
645
+		}
646
+	}
289
+
647
+
290
+	options = input_option_new(options, "config_info", config_info);
648
+	/* Init options. */
291
+	LogMessage(X_INFO, "config/devd: adding input device %s (%s)\n",
649
+	InputOption *option = NULL, *options = NULL;
292
+			attrs.product, path);
650
+	if ((option = input_option_new(options, "_source", "server/devd")))
293
+
651
+		options = option;
294
+	NewInputDeviceRequest(options, &attrs, &dev);
652
+	if (option && (option = input_option_new(options, "config_info", config_info)))
295
+
653
+		options = option;
296
+unwind:
654
+	if (option && (option = input_option_new(options, "name", (attrs.product ? attrs.product : dev_name))))
297
+	free(config_info);
655
+		options = option;
298
+	input_option_free_list(&options);
656
+	if (option && hwtype->xdriver && (option = input_option_new(options, "driver", hwtype->xdriver)))
299
+	free(attrs.usb_id);
657
+		options = option;
300
+	free(attrs.product);
658
+	/*
301
+	free(attrs.device);
659
+	 * Don't pass "device" option if the keyboard is already attached to the console (ie. open() failed)
302
+	free(attrs.vendor);
660
+	 * This would activate a special logic in xf86-input-keyboard. Prevent any other attached to console
661
+	 * keyboards being processed. There can be only one such device.
662
+	 */
663
+	if (option && fd >= 0 && (option = input_option_new(options, "device", dev_path)))
664
+		options = option;
665
+	/* Most drivers just use "device" but evdev also uses "path" so populate both */
666
+	if (option && (option = input_option_new(options, "path", dev_path)))
667
+		options = option;
668
+	if (option) {
669
+		LogMessage(X_INFO, "config/devd: adding input device %s\n", dev_path);
670
+		DeviceIntPtr dev_iptr = NULL;
671
+		int rc;
672
+		if ((rc = NewInputDeviceRequest(options, &attrs, &dev_iptr)) != Success)
673
+			LogMessage(X_ERROR, "config/devd: error %d adding device %s\n", rc, dev_path);
674
+	} else
675
+		LogMessage(X_ERROR, "config/devd: error adding device %s\n", dev_path);
676
+	if (options)
677
+		input_option_free_list(&options);
678
+	return;
303
+}
679
+}
304
+
680
+
305
+static void
681
+static void
306
+device_removed(char *devname)
682
+device_removed(const char *dev_name, size_t dev_name_size)
307
+{
683
+{
308
+	char *config_info;
309
+
684
+
310
+	if (asprintf(&config_info, "devd:%s", devname) == -1)
685
+	if (!dev_name || !dev_name_size || dev_name_size > PATH_MAX)
311
+		return;
686
+		return;
312
+
687
+
313
+	remove_devices("devd", config_info);
688
+	char config_info[(PATH_MAX + 32)];
689
+	snprintf(config_info, sizeof(config_info), DEVD_PATH_DEV"%.*s", (int)dev_name_size, dev_name);
314
+
690
+
315
+	free(config_info);
691
+	hw_type_t hwtype_cust;
316
+}
692
+	if (!get_dev_type_by_name(dev_name, dev_name_size) &&
317
+
693
+	    !get_dev_type_by_path(dev_name, dev_name_size, &hwtype_cust)) {
318
+static bool is_kbdmux_enabled(void)
694
+		LogMessage(X_INFO, "config/devd: skip remove unrecognized device %s\n", (config_info + DEVD_PATH_DEV_LEN));
319
+{
695
+		return;	/* Device not in list - unknown. */
320
+	/* Xorg uses /dev/ttyv0 as a console device */
321
+	/* const char device[]="/dev/console"; */
322
+	const char device[]="/dev/ttyv0";
323
+	keyboard_info_t info;
324
+	int fd;
325
+
326
+	fd = open(device, O_RDONLY);
327
+
328
+	if (fd < 0)
329
+		return false;
330
+
331
+	if (ioctl(fd, KDGKBINFO, &info) == -1) {
332
+		close(fd);
333
+		return false;
334
+	}
696
+	}
335
+
697
+
336
+	close(fd);
698
+	if (device_is_duplicate(config_info))
337
+
699
+		LogMessage(X_INFO, "config/devd: removing input device %s\n", (config_info + DEVD_PATH_DEV_LEN));
338
+	if (!strncmp(info.kb_name, "kbdmux", 6))
700
+	else
339
+		return true;
701
+		LogMessage(X_INFO, "config/devd: removing missing device %s\n", (config_info + DEVD_PATH_DEV_LEN));
340
+
702
+	remove_devices("devd", config_info);
341
+	return false;
703
+	return;
342
+}
704
+}
343
+
705
+
344
+static void
706
+static void socket_handler(int fd, int ready, void *data);
345
+disconnect_devd(int sock)
346
+{
347
+	if (sock >= 0) {
348
+		RemoveGeneralSocket(sock);
349
+		close(sock);
350
+	}
351
+}
352
+
707
+
353
+static int
708
+static int
354
+connect_devd(void)
709
+connect_devd(void)
355
+{
710
+{
356
+	struct sockaddr_un devd;
711
+	int sock = socket(AF_UNIX, SOCK_STREAM, 0);
357
+	int sock;
358
+
359
+	sock = socket(AF_UNIX, SOCK_STREAM, 0);
360
+	if (sock < 0) {
712
+	if (sock < 0) {
361
+		LogMessage(X_ERROR, "config/devd: fail opening stream socket\n");
713
+		LogMessage(X_ERROR, "config/devd: failed opening stream socket: %s\n", strerror(errno));
362
+		return -1;
714
+		return -1;
363
+	}
715
+	}
364
+
716
+
717
+	struct sockaddr_un devd;
365
+	devd.sun_family = AF_UNIX;
718
+	devd.sun_family = AF_UNIX;
366
+	strlcpy(devd.sun_path, DEVD_SOCK_PATH, sizeof(devd.sun_path));
719
+	memcpy(devd.sun_path, DEVD_SOCK_PATH, sizeof(DEVD_SOCK_PATH));
367
+
720
+	if (connect(sock, (struct sockaddr*)&devd, sizeof(devd)) < 0) {
368
+	if (connect(sock, (struct sockaddr *) &devd, sizeof(devd)) < 0) {
721
+		int error = errno;
369
+		close(sock);
722
+		close(sock);
370
+		LogMessage(X_ERROR, "config/devd: fail to connect to devd\n");
723
+		LogMessage(X_ERROR, "config/devd: failed to connect to devd: %s)\n", strerror(error));
371
+		return -1;
724
+		return -1;
372
+	}
725
+	}
373
+
726
+
374
+	AddGeneralSocket(sock);
727
+	SetNotifyFd(sock, socket_handler, X_NOTIFY_READ, NULL);
728
+	return sock;
729
+}
375
+
730
+
376
+	return	sock;
731
+static void
732
+disconnect_devd(int sock)
733
+{
734
+	if (sock < 0)
735
+		return;
736
+	RemoveNotifyFd(sock);
737
+	close(sock);
738
+	return;
377
+}
739
+}
378
+
740
+
379
+static CARD32
741
+static CARD32
380
+reconnect_handler(OsTimerPtr timer, CARD32 time, void *arg)
742
+reconnect_handler(OsTimerPtr timer, CARD32 time, void *arg)
381
+{
743
+{
382
+	int newsock;
744
+	devd_buf_used = 0;
383
+
745
+	devd_skt = connect_devd();
384
+	if ((newsock = connect_devd()) > 0) {
746
+	if (devd_skt < 0) /* Try again after RECONNECT_DELAY */
385
+		sock_devd = newsock;
747
+		return RECONNECT_DELAY;
386
+		TimerFree(rtimer);
748
+	TimerFree(rtimer);
387
+		rtimer = NULL;
749
+	rtimer = NULL;
388
+		LogMessage(X_INFO, "config/devd: reopening devd socket\n");
750
+	LogMessage(X_INFO, "config/devd: reopened devd socket\n");
389
+		return 0;
751
+	return 0;
390
+	}
391
+
392
+	/* Try again after RECONNECT_DELAY */
393
+	return RECONNECT_DELAY;
394
+}
752
+}
395
+
753
+
396
+static ssize_t
754
+static void
397
+socket_getline(int fd, char **out)
755
+socket_handler(int fd, int ready, void *data)
398
+{
756
+{
399
+	char *buf, *newbuf;
757
+	/* Read new data. */
400
+	ssize_t ret, cap, sz = 0;
758
+	while (1) {
401
+	char c;
759
+		ssize_t ios = recv(devd_skt, (devd_buf + devd_buf_used), (sizeof(devd_buf) - devd_buf_used), MSG_DONTWAIT);
402
+
760
+		if (ios > 0) { /* Read OK. */
403
+	cap = 1024;
761
+			devd_buf_used += ios;
404
+	buf = malloc(cap * sizeof(char));
762
+			continue; /* Try to read more. */
405
+	if (!buf)
406
+		return -1;
407
+
408
+	for (;;) {
409
+		ret = read(sock_devd, &c, 1);
410
+		if (ret < 0) {
411
+			if (errno == EINTR)
412
+				continue;
413
+			free(buf);
414
+			return -1;
415
+		/* EOF - devd socket is lost */
416
+		} else if (ret == 0) {
417
+			disconnect_devd(sock_devd);
418
+			rtimer = TimerSet(NULL, 0, 1, reconnect_handler, NULL);
419
+			LogMessage(X_WARNING, "config/devd: devd socket is lost\n");
420
+			free(buf);
421
+			return -1;
422
+		}
763
+		}
423
+		if (c == '\n')
764
+		/* Something wrong. */
424
+			break;
765
+		int error = errno;
425
+
766
+		if (error == EAGAIN)
426
+		if (sz + 1 >= cap) {
767
+			break; /* All available data read. */
427
+			cap *= 2;
768
+		if (error == EINTR)
428
+			newbuf = realloc(buf, cap * sizeof(char));
769
+			continue;
429
+			if (!newbuf) {
770
+		if (devd_buf_used >= sizeof(devd_buf)) {
430
+				free(buf);
771
+			devd_buf_used = 0; /* Message too long, reset buf. */
431
+				return -1;
772
+			continue;
432
+			}
433
+			buf = newbuf;
434
+		}
773
+		}
435
+		buf[sz] = c;
774
+		/* devd socket is lost */
436
+		sz++;
775
+		disconnect_devd(devd_skt);
776
+		rtimer = TimerSet(NULL, 0, 1, reconnect_handler, NULL);
777
+		LogMessage(X_WARNING, "config/devd: devd socket read error: %s\n", strerror(error));
778
+		return;
437
+	}
779
+	}
438
+
780
+
439
+	buf[sz] = '\0';
781
+	/* Process data. */
440
+	if (sz >= 0)
782
+	char *ptr, *line = (devd_buf + 1);
441
+		*out = buf;
783
+	size_t line_size = 0;
442
+	else
784
+	while((ptr = memchr(line, '\n', (devd_buf_used - line_size)))) {
443
+		free(buf);
785
+		line_size = (ptr - line);
786
+		do {
787
+			if (*(line - 1) != DEVD_EVENT_NOTIFY)
788
+				break; /* Handle only notify. */
789
+			/* Check: is system=DEVFS. */
790
+			size_t val_size;
791
+			char* val = devd_get_val_cstr("system", line, line_size, &val_size);
792
+			if (!is_meuqual_cstr("DEVFS", val, val_size))
793
+				break;
794
+			/* Check: is subsystem=CDEV. */
795
+			val = devd_get_val_cstr("subsystem", line, line_size, &val_size);
796
+			if (!is_meuqual_cstr("CDEV", val, val_size))
797
+				break;
798
+			/* Get device name. */
799
+			size_t cdev_size;
800
+			char* cdev = devd_get_val_cstr("cdev", line, line_size, &cdev_size);
801
+			if (!cdev)
802
+				break;
803
+			/* Get event type. */
804
+			val = devd_get_val_cstr("type", line, line_size, &val_size);
805
+			if (is_meuqual_cstr("CREATE", val, val_size)) {
806
+				device_added(cdev, cdev_size, 0);
807
+			} else if (is_meuqual_cstr("DESTROY", val, val_size)) {
808
+				device_removed(cdev, cdev_size);
809
+			}
810
+		} while(0);
444
+
811
+
445
+	/* Number of bytes in the line, not counting the line break */
812
+		line += (line_size + 2); /* Skip '\n' and event type byte. */
446
+	return sz;
813
+		line_size = (line - devd_buf);
447
+}
814
+		if (devd_buf_used <= line_size) {
448
+
815
+			devd_buf_used = 0;
449
+static void
450
+wakeup_handler(void *data, int err, void *read_mask)
451
+{
452
+	char *line = NULL;
453
+	char *walk;
454
+
455
+	if (err < 0)
456
+		return;
457
+
458
+	if (FD_ISSET(sock_devd, (fd_set *) read_mask)) {
459
+		if (socket_getline(sock_devd, &line) < 0)
460
+			return;
816
+			return;
461
+
462
+		walk = strchr(line + 1, ' ');
463
+		if (walk != NULL)
464
+			walk[0] = '\0';
465
+
466
+		switch (*line) {
467
+		case DEVD_EVENT_ADD:
468
+			device_added(line + 1);
469
+			break;
470
+		case DEVD_EVENT_REMOVE:
471
+			device_removed(line + 1);
472
+			break;
473
+		default:
474
+			break;
475
+		}
817
+		}
476
+		free(line);
477
+	}
818
+	}
819
+	/* Save line without end marker. */
820
+	if (line_size) {
821
+		devd_buf_used -= (line_size - 1);
822
+		memmove(devd_buf, (line - 1), devd_buf_used);
823
+	}
824
+	return;
478
+}
825
+}
479
+
826
+
480
+static void
481
+block_handler(void *data, struct timeval **tv, void *read_mask)
482
+{
483
+}
484
+
485
+int
827
+int
486
+config_devd_init(void)
828
+config_devd_init(void)
487
+{
829
+{
488
+	char devicename[1024];
489
+	int i, j;
490
+
491
+	LogMessage(X_INFO, "config/devd: probing input devices...\n");
830
+	LogMessage(X_INFO, "config/devd: probing input devices...\n");
492
+
831
+
493
+	/*
832
+	/*
Lines 494-520 Link Here
494
+	 * Add fake keyboard and give up on keyboards management
833
+	 * Add fake keyboard and give up on keyboards management
495
+	 * if kbdmux is enabled
834
+	 * if kbdmux is enabled
496
+	 */
835
+	 */
497
+	if ((is_kbdmux = is_kbdmux_enabled()) == true)
836
+	is_kbdmux = is_kbdmux_enabled();
498
+		device_added("kbdmux");
837
+	if (is_kbdmux)
838
+		device_added("kbdmux0", 7, 1);
499
+
839
+
500
+	for (i = 0; hw_types[i].driver != NULL; i++) {
840
+	/* Scan /dev/ for devices. */
501
+		/* First scan the sysctl to determine the hardware */
841
+	struct dirent** namelist;
502
+		for (j = 0; j < 16; j++) {
842
+	size_t dir_cnt = scandir(_PATH_DEV, &namelist, 0, alphasort);
503
+			if (sysctl_exists(&hw_types[i], j,
843
+	for (size_t i = 0; i < dir_cnt; ++i) {
504
+					devicename, sizeof(devicename)) != 0)
844
+		struct dirent* de = namelist[i];
505
+				device_added(devicename);
845
+		if (is_de_euqual_cstr(de, ".") ||
846
+		    is_de_euqual_cstr(de, "..")) {
847
+			free(de);
848
+			continue;
506
+		}
849
+		}
507
+
850
+		if (de->d_type != DT_DIR) {
508
+		if (devpath_exists(&hw_types[i], devicename, sizeof(devicename)) != 0)
851
+			device_added(de->d_name, de->d_namlen, 0);
509
+			device_added(devicename);
852
+		} else { /* Sub folder. */
853
+			char devicename[PATH_MAX];
854
+			snprintf(devicename, sizeof(devicename), _PATH_DEV "%s", de->d_name);
855
+			struct dirent** snamelist;
856
+			size_t sdir_cnt = scandir(devicename, &snamelist, 0, alphasort);
857
+			for (size_t j = 0; j < sdir_cnt; ++j) {
858
+				struct dirent* sde = snamelist[j];
859
+				if (!is_de_euqual_cstr(sde, ".") &&
860
+				    !is_de_euqual_cstr(sde, "..") &&
861
+				    sde->d_type != DT_DIR) {
862
+					size_t tm = snprintf(devicename, sizeof(devicename), "%s/%s", de->d_name, sde->d_name);
863
+					device_added(devicename, tm, 0);
864
+				}
865
+				free(sde);
866
+			}
867
+			free(snamelist);
868
+		}
869
+		free(de);
510
+	}
870
+	}
871
+	free(namelist);
511
+
872
+
512
+	if ((sock_devd = connect_devd()) < 0)
873
+	devd_buf_used = 0;
513
+		return 0;
874
+	devd_skt = connect_devd();
514
+
875
+	return (devd_skt < 0) ? 0 : 1;
515
+	RegisterBlockAndWakeupHandlers(block_handler, wakeup_handler, NULL);
516
+
517
+	return 1;
518
+}
876
+}
519
+
877
+
520
+void
878
+void
Lines 527-535 Link Here
527
+		rtimer = NULL;
885
+		rtimer = NULL;
528
+	}
886
+	}
529
+
887
+
530
+	disconnect_devd(sock_devd);
888
+	disconnect_devd(devd_skt);
531
+
889
+	return;
532
+	RemoveBlockAndWakeupHandlers(block_handler, wakeup_handler, NULL);
533
+
534
+	is_console_kbd = false;
535
+}
890
+}
(-)x11-servers/xorg-server/files/patch-config_udev.c (+53 lines)
Line 0 Link Here
1
* Don't pass the device parameter when using kbdmux to prevent conflict
2
*
3
* Specify a driver to use for basic devices (keyboard and mouse), otherwise none attaches
4
*
5
--- config/udev.c.orig	2017-03-02 23:03:58 UTC
6
+++ config/udev.c
7
@@ -29,6 +29,7 @@
8
 
9
 #include <libudev.h>
10
 #include <ctype.h>
11
+#include <fcntl.h>
12
 #include <unistd.h>
13
 
14
 #include "input.h"
15
@@ -188,7 +189,21 @@ device_added(struct udev_device *udev_de
16
         attrs.product = strdup(name);
17
     input_options = input_option_new(input_options, "name", name);
18
     input_options = input_option_new(input_options, "path", path);
19
-    input_options = input_option_new(input_options, "device", path);
20
+    if(strstr(path, "kbdmux") != NULL) {
21
+        /*
22
+         * Don't pass "device" option if the keyboard is already attached
23
+         * to the console (ie. open() fails). This would activate a special
24
+         * logic in xf86-input-keyboard. Prevent any other attached to console
25
+         * keyboards being processed. There can be only one such device.
26
+         */
27
+        int fd = open(path, O_RDONLY);
28
+        if (fd > -1) {
29
+            close(fd);
30
+            input_options = input_option_new(input_options, "device", path);
31
+        }
32
+    }
33
+    else
34
+        input_options = input_option_new(input_options, "device", path);
35
     input_options = input_option_new(input_options, "major", itoa(major(devnum)));
36
     input_options = input_option_new(input_options, "minor", itoa(minor(devnum)));
37
     if (path)
38
@@ -272,6 +287,15 @@ device_added(struct udev_device *udev_de
39
         }
40
     }
41
 
42
+    if (attrs.flags & (ATTR_KEY | ATTR_KEYBOARD))
43
+        input_options = input_option_new(input_options, "driver", "kbd");
44
+    else if (attrs.flags & ATTR_POINTER) {
45
+        if (strstr(path, "vbox"))
46
+            input_options = input_option_new(input_options, "driver", "vboxmouse");
47
+        else
48
+            input_options = input_option_new(input_options, "driver", "mouse");
49
+    }
50
+
51
     input_options = input_option_new(input_options, "config_info", config_info);
52
 
53
     /* Default setting needed for non-seat0 seats */
(-)x11-servers/xorg-server/files/patch-configure (-14 / +152 lines)
Lines 1-6 Link Here
1
--- configure.orig	2016-07-19 17:27:31 UTC
1
* generated from patched configure.ac; revise and regen instead of editing
2
*
3
* Plumb the devd config backend into configure
4
*
5
* define USE_DEV_IO for ARM platforms
6
*
7
* Only run pkg-config for udev if it is not disabled to prevent over-linking
8
*
9
* Automatically use systemd/logind only on Linux
10
*
11
--- configure.orig	2017-03-02 23:04:12 UTC
2
+++ configure
12
+++ configure
3
@@ -23168,9 +23168,14 @@ $as_echo "#define USE_ALPHA_PIO 1" >>con
13
@@ -1032,6 +1032,8 @@ CONFIG_UDEV_FALSE
14
 CONFIG_UDEV_TRUE
15
 UDEV_LIBS
16
 UDEV_CFLAGS
17
+CONFIG_DEVD_FALSE
18
+CONFIG_DEVD_TRUE
19
 HAVE_SYSTEMD_DAEMON_FALSE
20
 HAVE_SYSTEMD_DAEMON_TRUE
21
 SYSTEMD_DAEMON_LIBS
22
@@ -1367,6 +1369,7 @@ enable_tslib
23
 enable_dbe
24
 enable_xf86bigfont
25
 enable_dpms
26
+enable_config_devd
27
 enable_config_udev
28
 enable_config_udev_kms
29
 enable_config_hal
30
@@ -2191,6 +2194,7 @@ Optional Features:
31
   --disable-dbe           Build DBE extension (default: enabled)
32
   --enable-xf86bigfont    Build XF86 Big Font extension (default: disabled)
33
   --disable-dpms          Build DPMS extension (default: enabled)
34
+  --enable-config-devd    Build devd support (default: auto)
35
   --enable-config-udev    Build udev support (default: auto)
36
   --enable-config-udev-kms
37
                           Build udev kms support (default: auto)
38
@@ -23263,9 +23267,13 @@ $as_echo "#define USE_ALPHA_PIO 1" >>con
4
 	esac
39
 	esac
5
 	GLX_ARCH_DEFINES="-D__GLX_ALIGN64 -mieee"
40
 	GLX_ARCH_DEFINES="-D__GLX_ALIGN64 -mieee"
6
 	;;
41
 	;;
Lines 9-27 Link Here
9
 	ARM_VIDEO=yes
44
 	ARM_VIDEO=yes
10
 	DEFAULT_INT10="stub"
45
 	DEFAULT_INT10="stub"
11
+	case $host_os in
46
+	case $host_os in
12
+		*freebsd*)
47
+		*freebsd*)	$as_echo "#define USE_DEV_IO 1" >>confdefs.h
13
+			$as_echo "#define USE_DEV_IO 1" >>confdefs.h
48
+ ;;
14
+		 ;;
15
+	esac
49
+	esac
16
 	;;
50
 	;;
17
   i*86)
51
   i*86)
18
 	I386_VIDEO=yes
52
 	I386_VIDEO=yes
19
@@ -26057,7 +26062,7 @@ fi
53
@@ -24036,6 +24044,13 @@ else
20
 case "x$XTRANS_SEND_FDS" in
54
   DPMSExtension=yes
21
 xauto)
55
 fi
22
 	case "$host_os" in
56
 
23
-	linux*|solaris*)
57
+# Check whether --enable-config-devd was given.
24
+	linux*|solaris*|freebsd*|dragonfly*|openbsd*)
58
+if test "${enable_config_devd+set}" = set; then :
25
 		XTRANS_SEND_FDS=yes
59
+  enableval=$enable_config_devd; CONFIG_DEVD=$enableval
26
 		;;
60
+else
27
 	*)
61
+  CONFIG_DEVD=auto
62
+fi
63
+
64
 # Check whether --enable-config-udev was given.
65
 if test "${enable_config_udev+set}" = set; then :
66
   enableval=$enable_config_udev; CONFIG_UDEV=$enableval
67
@@ -25796,6 +25811,31 @@ if test "x$CONFIG_UDEV" = xyes && test "
68
 	as_fn_error $? "Hotplugging through both libudev and hal not allowed" "$LINENO" 5
69
 fi
70
 
71
+if test "x$CONFIG_DEVD" = xauto; then
72
+	case $host_os in
73
+		*freebsd*)
74
+			CONFIG_DEVD=yes
75
+			;;
76
+		*)
77
+			CONFIG_DEVD=no
78
+			;;
79
+	esac
80
+fi
81
+ if test "x$CONFIG_DEVD" = xyes; then
82
+  CONFIG_DEVD_TRUE=
83
+  CONFIG_DEVD_FALSE='#'
84
+else
85
+  CONFIG_DEVD_TRUE='#'
86
+  CONFIG_DEVD_FALSE=
87
+fi
88
+
89
+if test "x$CONFIG_DEVD" = xyes; then
90
+
91
+$as_echo "#define CONFIG_DEVD 1" >>confdefs.h
92
+
93
+fi
94
+
95
+if test "x$CONFIG_UDEV" != xno; then
96
 
97
 pkg_failed=no
98
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for UDEV" >&5
99
@@ -25867,11 +25907,12 @@ else
100
 $as_echo "yes" >&6; }
101
 	HAVE_LIBUDEV=yes
102
 fi
103
-if test "x$CONFIG_UDEV" = xauto; then
104
-	CONFIG_UDEV="$HAVE_LIBUDEV"
105
+	if test "x$CONFIG_UDEV" = xauto; then
106
+		CONFIG_UDEV="$HAVE_LIBUDEV"
107
 
108
 $as_echo "#define HAVE_LIBUDEV 1" >>confdefs.h
109
 
110
+	fi
111
 fi
112
  if test "x$CONFIG_UDEV" = xyes; then
113
   CONFIG_UDEV_TRUE=
114
@@ -26115,7 +26156,14 @@ fi
115
 
116
 if test "x$SYSTEMD_LOGIND" = xauto; then
117
         if test "x$HAVE_DBUS" = xyes -a "x$CONFIG_UDEV" = xyes ; then
118
-                SYSTEMD_LOGIND=yes
119
+            case $host_os in
120
+                *linux*)
121
+                        SYSTEMD_LOGIND=yes
122
+                        ;;
123
+                *)
124
+                        SYSTEMD_LOGIND=no
125
+                        ;;
126
+            esac
127
         else
128
                 SYSTEMD_LOGIND=no
129
         fi
130
@@ -32832,17 +32880,17 @@ DIX_CFLAGS="-DHAVE_DIX_CONFIG_H $XSERVER
131
 ac_config_commands="$ac_config_commands sdksyms"
132
 
133
 
134
-if test "x$CONFIG_HAL" = xno && test "x$CONFIG_UDEV" = xno; then
135
+if test "x$CONFIG_HAL" = xno && test "x$CONFIG_UDEV" = xno && test "x$CONFIG_DEVD" = xno; then
136
     { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING:
137
-             ***********************************************
138
-             Neither HAL nor udev backend will be enabled.
139
+             *****************************************************
140
+             Neither HAL, devd, nor udev backend will be enabled.
141
              Input device hotplugging will not be available!
142
-             ***********************************************" >&5
143
+             *****************************************************" >&5
144
 $as_echo "$as_me: WARNING:
145
-             ***********************************************
146
-             Neither HAL nor udev backend will be enabled.
147
+             *****************************************************
148
+             Neither HAL, devd, nor udev backend will be enabled.
149
              Input device hotplugging will not be available!
150
-             ***********************************************" >&2;}
151
+             *****************************************************" >&2;}
152
 fi
153
 
154
 ac_config_files="$ac_config_files Makefile glx/Makefile include/Makefile composite/Makefile damageext/Makefile dbe/Makefile dix/Makefile doc/Makefile doc/dtrace/Makefile man/Makefile fb/Makefile glamor/Makefile record/Makefile config/Makefile mi/Makefile miext/Makefile miext/sync/Makefile miext/damage/Makefile miext/shadow/Makefile miext/rootless/Makefile os/Makefile pseudoramiX/Makefile randr/Makefile render/Makefile xkb/Makefile Xext/Makefile Xi/Makefile xfixes/Makefile exa/Makefile dri3/Makefile present/Makefile hw/Makefile hw/xfree86/Makefile hw/xfree86/Xorg.sh hw/xfree86/common/Makefile hw/xfree86/common/xf86Build.h hw/xfree86/ddc/Makefile hw/xfree86/dixmods/Makefile hw/xfree86/doc/Makefile hw/xfree86/dri/Makefile hw/xfree86/dri2/Makefile hw/xfree86/dri2/pci_ids/Makefile hw/xfree86/drivers/Makefile hw/xfree86/drivers/modesetting/Makefile hw/xfree86/exa/Makefile hw/xfree86/exa/man/Makefile hw/xfree86/fbdevhw/Makefile hw/xfree86/fbdevhw/man/Makefile hw/xfree86/glamor_egl/Makefile hw/xfree86/i2c/Makefile hw/xfree86/int10/Makefile hw/xfree86/loader/Makefile hw/xfree86/man/Makefile hw/xfree86/modes/Makefile hw/xfree86/os-support/Makefile hw/xfree86/os-support/bsd/Makefile hw/xfree86/os-support/bus/Makefile hw/xfree86/os-support/hurd/Makefile hw/xfree86/os-support/misc/Makefile hw/xfree86/os-support/linux/Makefile hw/xfree86/os-support/solaris/Makefile hw/xfree86/os-support/stub/Makefile hw/xfree86/parser/Makefile hw/xfree86/ramdac/Makefile hw/xfree86/shadowfb/Makefile hw/xfree86/vbe/Makefile hw/xfree86/vgahw/Makefile hw/xfree86/x86emu/Makefile hw/xfree86/utils/Makefile hw/xfree86/utils/man/Makefile hw/xfree86/utils/cvt/Makefile hw/xfree86/utils/gtf/Makefile hw/dmx/config/Makefile hw/dmx/config/man/Makefile hw/dmx/doc/Makefile hw/dmx/doxygen/doxygen.conf hw/dmx/doxygen/Makefile hw/dmx/examples/Makefile hw/dmx/input/Makefile hw/dmx/glxProxy/Makefile hw/dmx/Makefile hw/dmx/man/Makefile hw/vfb/Makefile hw/vfb/man/Makefile hw/xnest/Makefile hw/xnest/man/Makefile hw/xwin/Makefile hw/xwin/dri/Makefile hw/xwin/glx/Makefile hw/xwin/man/Makefile hw/xwin/winclipboard/Makefile hw/xquartz/Makefile hw/xquartz/GL/Makefile hw/xquartz/bundle/Makefile hw/xquartz/man/Makefile hw/xquartz/mach-startup/Makefile hw/xquartz/pbproxy/Makefile hw/xquartz/xpr/Makefile hw/kdrive/Makefile hw/kdrive/ephyr/Makefile hw/kdrive/ephyr/man/Makefile hw/kdrive/fake/Makefile hw/kdrive/fbdev/Makefile hw/kdrive/linux/Makefile hw/kdrive/src/Makefile hw/xwayland/Makefile test/Makefile test/xi1/Makefile test/xi2/Makefile xserver.ent xorg-server.pc"
155
@@ -33105,6 +33153,10 @@ if test -z "${HAVE_SYSTEMD_DAEMON_TRUE}"
156
   as_fn_error $? "conditional \"HAVE_SYSTEMD_DAEMON\" was never defined.
157
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
158
 fi
159
+if test -z "${CONFIG_DEVD_TRUE}" && test -z "${CONFIG_DEVD_FALSE}"; then
160
+  as_fn_error $? "conditional \"CONFIG_DEVD\" was never defined.
161
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
162
+fi
163
 if test -z "${CONFIG_UDEV_TRUE}" && test -z "${CONFIG_UDEV_FALSE}"; then
164
   as_fn_error $? "conditional \"CONFIG_UDEV\" was never defined.
165
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
(-)x11-servers/xorg-server/files/patch-configure.ac (+97 lines)
Line 0 Link Here
1
* Plumb the devd config backend into configure
2
*
3
* define USE_DEV_IO for ARM platforms
4
*
5
* Only run pkg-config for udev if it is not disabled to prevent over-linking
6
*
7
* Automatically use systemd/logind only on Linux
8
*
9
--- configure.ac.orig	2017-03-02 23:03:58 UTC
10
+++ configure.ac
11
@@ -328,9 +328,12 @@ case $host_cpu in
12
 	esac
13
 	GLX_ARCH_DEFINES="-D__GLX_ALIGN64 -mieee"
14
 	;;
15
-  arm*)
16
+  arm*|aarch64*)
17
 	ARM_VIDEO=yes
18
 	DEFAULT_INT10="stub"
19
+	case $host_os in
20
+		*freebsd*)	AC_DEFINE(USE_DEV_IO) ;;
21
+	esac
22
 	;;
23
   i*86)
24
 	I386_VIDEO=yes
25
@@ -628,6 +631,7 @@ AC_ARG_ENABLE(tslib,          AS_HELP_ST
26
 AC_ARG_ENABLE(dbe,            AS_HELP_STRING([--disable-dbe], [Build DBE extension (default: enabled)]), [DBE=$enableval], [DBE=yes])
27
 AC_ARG_ENABLE(xf86bigfont,    AS_HELP_STRING([--enable-xf86bigfont], [Build XF86 Big Font extension (default: disabled)]), [XF86BIGFONT=$enableval], [XF86BIGFONT=no])
28
 AC_ARG_ENABLE(dpms,           AS_HELP_STRING([--disable-dpms], [Build DPMS extension (default: enabled)]), [DPMSExtension=$enableval], [DPMSExtension=yes])
29
+AC_ARG_ENABLE(config-devd,    AS_HELP_STRING([--enable-config-devd], [Build devd support (default: auto)]), [CONFIG_DEVD=$enableval], [CONFIG_DEVD=auto])
30
 AC_ARG_ENABLE(config-udev,    AS_HELP_STRING([--enable-config-udev], [Build udev support (default: auto)]), [CONFIG_UDEV=$enableval], [CONFIG_UDEV=auto])
31
 AC_ARG_ENABLE(config-udev-kms,    AS_HELP_STRING([--enable-config-udev-kms], [Build udev kms support (default: auto)]), [CONFIG_UDEV_KMS=$enableval], [CONFIG_UDEV_KMS=auto])
32
 AC_ARG_ENABLE(config-hal,     AS_HELP_STRING([--disable-config-hal], [Build HAL support (default: auto)]), [CONFIG_HAL=$enableval], [CONFIG_HAL=auto])
33
@@ -924,10 +928,27 @@ if test "x$CONFIG_UDEV" = xyes && test "
34
 	AC_MSG_ERROR([Hotplugging through both libudev and hal not allowed])
35
 fi
36
 
37
-PKG_CHECK_MODULES(UDEV, $LIBUDEV, [HAVE_LIBUDEV=yes], [HAVE_LIBUDEV=no])
38
-if test "x$CONFIG_UDEV" = xauto; then
39
-	CONFIG_UDEV="$HAVE_LIBUDEV"
40
-	AC_DEFINE(HAVE_LIBUDEV, 1, [Define to 1 if libudev is available.])
41
+if test "x$CONFIG_DEVD" = xauto; then
42
+	case $host_os in
43
+		*freebsd*)
44
+			CONFIG_DEVD=yes
45
+			;;
46
+		*)
47
+			CONFIG_DEVD=no
48
+			;;
49
+	esac
50
+fi
51
+AM_CONDITIONAL(CONFIG_DEVD, [test "x$CONFIG_DEVD" = xyes])
52
+if test "x$CONFIG_DEVD" = xyes; then
53
+	AC_DEFINE(CONFIG_DEVD, 1, [Use devd for input auto configuration])
54
+fi
55
+
56
+if test "x$CONFIG_UDEV" != xno; then
57
+	PKG_CHECK_MODULES(UDEV, $LIBUDEV, [HAVE_LIBUDEV=yes], [HAVE_LIBUDEV=no])
58
+	if test "x$CONFIG_UDEV" = xauto; then
59
+		CONFIG_UDEV="$HAVE_LIBUDEV"
60
+		AC_DEFINE(HAVE_LIBUDEV, 1, [Define to 1 if libudev is available.])
61
+	fi
62
 fi
63
 AM_CONDITIONAL(CONFIG_UDEV, [test "x$CONFIG_UDEV" = xyes])
64
 if test "x$CONFIG_UDEV" = xyes; then
65
@@ -975,7 +996,14 @@ AM_CONDITIONAL(CONFIG_HAL, [test "x$CONF
66
 
67
 if test "x$SYSTEMD_LOGIND" = xauto; then
68
         if test "x$HAVE_DBUS" = xyes -a "x$CONFIG_UDEV" = xyes ; then
69
-                SYSTEMD_LOGIND=yes
70
+            case $host_os in
71
+                *linux*)
72
+                        SYSTEMD_LOGIND=yes
73
+                        ;;
74
+                *)
75
+                        SYSTEMD_LOGIND=no
76
+                        ;;
77
+            esac
78
         else
79
                 SYSTEMD_LOGIND=no
80
         fi
81
@@ -2570,12 +2598,12 @@ AC_SUBST([prefix])
82
 
83
 AC_CONFIG_COMMANDS([sdksyms], [touch hw/xfree86/sdksyms.dep])
84
 
85
-if test "x$CONFIG_HAL" = xno && test "x$CONFIG_UDEV" = xno; then
86
+if test "x$CONFIG_HAL" = xno && test "x$CONFIG_UDEV" = xno && test "x$CONFIG_DEVD" = xno; then
87
     AC_MSG_WARN([
88
-             ***********************************************
89
-             Neither HAL nor udev backend will be enabled.
90
+             *****************************************************
91
+             Neither HAL, devd, nor udev backend will be enabled.
92
              Input device hotplugging will not be available!
93
-             ***********************************************])
94
+             *****************************************************])
95
 fi
96
 
97
 AC_CONFIG_FILES([
(-)x11-servers/xorg-server/files/patch-hw_xfree86_Makefile.am (+14 lines)
Line 0 Link Here
1
* Don't overwrite Xorg binary with Xorg.sh when SUID_WRAPPER_DIR == bindir
2
* Instead, relink bin/X to Xorg.wrap rather than to Xorg (which isn't Xorg.sh)
3
*
4
--- hw/xfree86/Makefile.am.orig	2017-03-10 14:14:25 UTC
5
+++ hw/xfree86/Makefile.am
6
@@ -109,7 +109,7 @@ endif
7
 if SUID_WRAPPER
8
 	$(MKDIR_P) $(DESTDIR)$(SUID_WRAPPER_DIR)
9
 	mv $(DESTDIR)$(bindir)/Xorg $(DESTDIR)$(SUID_WRAPPER_DIR)/Xorg
10
-	${INSTALL} -m 755 Xorg.sh $(DESTDIR)$(bindir)/Xorg
11
+	(test ! -f $(DESTDIR)$(bindir)/Xorg && ${INSTALL} -m 755 Xorg.sh $(DESTDIR)$(bindir)/Xorg || cd $(DESTDIR)$(bindir) && rm -f X && $(LN_S) Xorg.wrap$(EXEEXT) X)
12
 	-chown root $(DESTDIR)$(SUID_WRAPPER_DIR)/Xorg.wrap && chmod u+s $(DESTDIR)$(SUID_WRAPPER_DIR)/Xorg.wrap
13
 endif
14
 
(-)x11-servers/xorg-server/files/patch-hw_xfree86_Makefile.in (+14 lines)
Line 0 Link Here
1
* Don't overwrite Xorg binary with Xorg.sh when SUID_WRAPPER_DIR == bindir
2
* Instead, relink bin/X to Xorg.wrap rather than to Xorg (which isn't Xorg.sh)
3
*
4
--- hw/xfree86/Makefile.in.orig	2017-03-10 14:14:25 UTC
5
+++ hw/xfree86/Makefile.in
6
@@ -1149,7 +1149,7 @@ install-exec-hook:
7
 @INSTALL_SETUID_TRUE@	chmod u+s $(DESTDIR)$(bindir)/Xorg
8
 @SUID_WRAPPER_TRUE@	$(MKDIR_P) $(DESTDIR)$(SUID_WRAPPER_DIR)
9
 @SUID_WRAPPER_TRUE@	mv $(DESTDIR)$(bindir)/Xorg $(DESTDIR)$(SUID_WRAPPER_DIR)/Xorg
10
-@SUID_WRAPPER_TRUE@	${INSTALL} -m 755 Xorg.sh $(DESTDIR)$(bindir)/Xorg
11
+@SUID_WRAPPER_TRUE@	(test ! -f $(DESTDIR)$(bindir)/Xorg && ${INSTALL} -m 755 Xorg.sh $(DESTDIR)$(bindir)/Xorg || cd $(DESTDIR)$(bindir) && rm -f X && $(LN_S) Xorg.wrap$(EXEEXT) X)
12
 @SUID_WRAPPER_TRUE@	-chown root $(DESTDIR)$(SUID_WRAPPER_DIR)/Xorg.wrap && chmod u+s $(DESTDIR)$(SUID_WRAPPER_DIR)/Xorg.wrap
13
 
14
 uninstall-local:
(-)x11-servers/xorg-server/files/patch-hw_xfree86_common_xf86AutoConfig.c (-1 / +5 lines)
Lines 1-4 Link Here
1
--- hw/xfree86/common/xf86AutoConfig.c.orig	2017-01-11 20:00:58 UTC
1
* Try using modesetting driver before falling back to scfb or vesa
2
*
3
* Use our scfb driver as fallback instead of Linux's fbdev
4
*
5
--- hw/xfree86/common/xf86AutoConfig.c.orig	2017-03-02 23:03:58 UTC
2
+++ hw/xfree86/common/xf86AutoConfig.c
6
+++ hw/xfree86/common/xf86AutoConfig.c
3
@@ -276,7 +276,7 @@ listPossibleVideoDrivers(char *matches[]
7
@@ -276,7 +276,7 @@ listPossibleVideoDrivers(char *matches[]
4
         i += xf86PciMatchDriver(&matches[i], nmatches - i);
8
         i += xf86PciMatchDriver(&matches[i], nmatches - i);
(-)x11-servers/xorg-server/files/patch-hw_xfree86_common_xf86Config.c (-3 / +5 lines)
Lines 1-12 Link Here
1
--- hw/xfree86/common/xf86Config.c.orig	2016-07-19 17:14:30 UTC
1
* Select the devd config backend if it is activated
2
*
3
--- hw/xfree86/common/xf86Config.c.orig	2017-03-02 23:03:58 UTC
2
+++ hw/xfree86/common/xf86Config.c
4
+++ hw/xfree86/common/xf86Config.c
3
@@ -1410,13 +1410,16 @@ checkCoreInputDevices(serverLayoutPtr se
5
@@ -1375,13 +1375,16 @@ checkCoreInputDevices(serverLayoutPtr se
4
     }
6
     }
5
 
7
 
6
     if (!xf86Info.forceInputDevices && !(foundPointer && foundKeyboard)) {
8
     if (!xf86Info.forceInputDevices && !(foundPointer && foundKeyboard)) {
7
-#if defined(CONFIG_HAL) || defined(CONFIG_UDEV) || defined(CONFIG_WSCONS)
9
-#if defined(CONFIG_HAL) || defined(CONFIG_UDEV) || defined(CONFIG_WSCONS)
8
+#if defined(CONFIG_HAL) || defined(CONFIG_UDEV) || defined(CONFIG_WSCONS) || \
10
+#if defined(CONFIG_HAL) || defined(CONFIG_UDEV) || defined(CONFIG_WSCONS) || \
9
+		defined(CONFIG_DEVD)
11
+	defined(CONFIG_DEVD)
10
         const char *config_backend;
12
         const char *config_backend;
11
 
13
 
12
 #if defined(CONFIG_HAL)
14
 #if defined(CONFIG_HAL)
(-)x11-servers/xorg-server/files/patch-hw_xfree86_common_xf86Globals.c (-1 / +3 lines)
Lines 1-4 Link Here
1
--- hw/xfree86/common/xf86Globals.c.orig	2016-07-19 17:07:29 UTC
1
* Include devd in the set of config backends
2
*
3
--- hw/xfree86/common/xf86Globals.c.orig	2017-03-02 23:03:58 UTC
2
+++ hw/xfree86/common/xf86Globals.c
4
+++ hw/xfree86/common/xf86Globals.c
3
@@ -122,7 +122,8 @@ xf86InfoRec xf86Info = {
5
@@ -122,7 +122,8 @@ xf86InfoRec xf86Info = {
4
     .pmFlag = TRUE,
6
     .pmFlag = TRUE,
(-)x11-servers/xorg-server/files/patch-hw_xfree86_common_xf86Xinput.c (-3 / +5 lines)
Lines 1-6 Link Here
1
--- hw/xfree86/common/xf86Xinput.c.orig	2016-07-19 17:07:29 UTC
1
* Recognize devd backend as a source of auto-configured devices
2
*
3
--- hw/xfree86/common/xf86Xinput.c.orig	2017-03-02 23:03:58 UTC
2
+++ hw/xfree86/common/xf86Xinput.c
4
+++ hw/xfree86/common/xf86Xinput.c
3
@@ -841,7 +841,7 @@ xf86NewInputDevice(InputInfoPtr pInfo, D
5
@@ -871,7 +871,7 @@ xf86NewInputDevice(InputInfoPtr pInfo, D
4
 {
6
 {
5
     InputDriverPtr drv = NULL;
7
     InputDriverPtr drv = NULL;
6
     DeviceIntPtr dev = NULL;
8
     DeviceIntPtr dev = NULL;
Lines 9-15 Link Here
9
     int rval;
11
     int rval;
10
     char *path = NULL;
12
     char *path = NULL;
11
 
13
 
12
@@ -996,6 +996,7 @@ NewInputDeviceRequest(InputOption *optio
14
@@ -1034,6 +1034,7 @@ NewInputDeviceRequest(InputOption *optio
13
         if (strcmp(key, "_source") == 0 &&
15
         if (strcmp(key, "_source") == 0 &&
14
             (strcmp(value, "server/hal") == 0 ||
16
             (strcmp(value, "server/hal") == 0 ||
15
              strcmp(value, "server/udev") == 0 ||
17
              strcmp(value, "server/udev") == 0 ||
(-)x11-servers/xorg-server/files/patch-hw_xfree86_os-support_bsd_bsd__init.c (-1 / +1 lines)
Lines 1-4 Link Here
1
--- hw/xfree86/os-support/bsd/bsd_init.c.orig	2016-07-19 17:07:29 UTC
1
--- hw/xfree86/os-support/bsd/bsd_init.c.orig	2017-03-02 23:03:58 UTC
2
+++ hw/xfree86/os-support/bsd/bsd_init.c
2
+++ hw/xfree86/os-support/bsd/bsd_init.c
3
@@ -230,6 +230,9 @@ xf86OpenConsole()
3
@@ -230,6 +230,9 @@ xf86OpenConsole()
4
              * Add cases for other *BSD that behave the same.
4
              * Add cases for other *BSD that behave the same.
(-)x11-servers/xorg-server/files/patch-hw_xfree86_os-support_bsd_i386__video.c (-1 / +1 lines)
Lines 1-5 Link Here
1
Index: programs/Xserver/hw/xfree86/os-support/bsd/i386_video.c
1
Index: programs/Xserver/hw/xfree86/os-support/bsd/i386_video.c
2
--- hw/xfree86/os-support/bsd/i386_video.c.orig	2016-07-15 16:18:11 UTC
2
--- hw/xfree86/os-support/bsd/i386_video.c.orig	2017-03-02 23:03:58 UTC
3
+++ hw/xfree86/os-support/bsd/i386_video.c
3
+++ hw/xfree86/os-support/bsd/i386_video.c
4
@@ -32,6 +32,7 @@
4
@@ -32,6 +32,7 @@
5
 #include "xf86Priv.h"
5
 #include "xf86Priv.h"
(-)x11-servers/xorg-server/files/patch-hw_xfree86_os-support_bsd_ppc__video.c (-1 / +1 lines)
Lines 1-4 Link Here
1
--- hw/xfree86/os-support/bsd/ppc_video.c.orig	2016-07-15 16:18:11 UTC
1
--- hw/xfree86/os-support/bsd/ppc_video.c.orig	2017-03-02 23:03:58 UTC
2
+++ hw/xfree86/os-support/bsd/ppc_video.c
2
+++ hw/xfree86/os-support/bsd/ppc_video.c
3
@@ -79,7 +79,11 @@ xf86DisableIO()
3
@@ -79,7 +79,11 @@ xf86DisableIO()
4
 {
4
 {
(-)x11-servers/xorg-server/files/patch-hw_xfree86_xorg-wrapper.c (+27 lines)
Line 0 Link Here
1
* Skip the detection of root rights requirement, the assumption that presence
2
* of KMS drivers removes the root requirement is only valid for Linux
3
*
4
--- hw/xfree86/xorg-wrapper.c.orig	2017-03-02 23:03:58 UTC
5
+++ hw/xfree86/xorg-wrapper.c
6
@@ -188,9 +188,6 @@ static int on_console(int fd)
7
 
8
 int main(int argc, char *argv[])
9
 {
10
-#ifdef WITH_LIBDRM
11
-    struct drm_mode_card_res res;
12
-#endif
13
     char buf[PATH_MAX];
14
     int i, r, fd;
15
     int kms_cards = 0;
16
@@ -227,9 +224,10 @@ int main(int argc, char *argv[])
17
         }
18
     }
19
 
20
-#ifdef WITH_LIBDRM
21
+#if defined(WITH_LIBDRM) && defined(__linux__)
22
     /* Detect if we need root rights, except when overriden by the config */
23
     if (needs_root_rights == -1) {
24
+        struct drm_mode_card_res res;
25
         for (i = 0; i < 16; i++) {
26
             snprintf(buf, sizeof(buf), DRM_DEV_NAME, DRM_DIR_NAME, i);
27
             fd = open(buf, O_RDWR);
(-)x11-servers/xorg-server/files/patch-include_dix-config.h.in (+14 lines)
Line 0 Link Here
1
* Add a define which will be toggled by configure when devd backend is activated
2
*
3
--- include/dix-config.h.in.orig	2017-03-02 23:03:58 UTC
4
+++ include/dix-config.h.in
5
@@ -433,6 +433,9 @@
6
 /* Support D-Bus */
7
 #undef HAVE_DBUS
8
 
9
+/* Use devd for input hotplug */
10
+#undef CONFIG_DEVD
11
+
12
 /* Use libudev for input hotplug */
13
 #undef CONFIG_UDEV
14
 
(-)x11-servers/xorg-server/files/patch-xkb_Makefile.am (+13 lines)
Line 0 Link Here
1
* Skip installing a README into a directory which is actually a symlink created
2
* by another port. If this file is installed, then upon uninstall pkg will
3
* delete the directory under the symlink, which would cause a reinstall to fail
4
* as the target directory is not remade until reinstalling the other port
5
*
6
--- xkb/Makefile.am.orig	2017-03-10 14:14:25 UTC
7
+++ xkb/Makefile.am
8
@@ -39,4 +39,4 @@ libxkbstubs_la_SOURCES = ddxVT.c ddxPriv
9
 EXTRA_DIST = xkbDflts.h xkbgeom.h xkb.h
10
 
11
 xkbcompileddir = $(XKB_COMPILED_DIR)
12
-dist_xkbcompiled_DATA = README.compiled
13
+#dist_xkbcompiled_DATA = README.compiled
(-)x11-servers/xorg-server/files/patch-xkb_Makefile.in (-2 / +7 lines)
Lines 1-6 Link Here
1
--- xkb/Makefile.in.orig	2017-01-19 15:20:42 UTC
1
* Skip installing a README into a directory which is actually a symlink created
2
* by another port. If this file is installed, then upon uninstall pkg will
3
* delete the directory under the symlink, which would cause a reinstall to fail
4
* as the target directory is not remade until reinstalling the other port
5
*
6
--- xkb/Makefile.in.orig	2017-03-10 14:14:25 UTC
2
+++ xkb/Makefile.in
7
+++ xkb/Makefile.in
3
@@ -878,7 +878,7 @@ info: info-am
8
@@ -886,7 +886,7 @@ info: info-am
4
 
9
 
5
 info-am:
10
 info-am:
6
 
11
 
(-)x11-servers/xorg-server/pkg-plist (-3 / +6 lines)
Lines 1-6 Link Here
1
bin/X
1
bin/X
2
%%SUID%%@(,,4555) bin/Xorg
2
bin/Xorg
3
%%NO_SUID%%bin/Xorg
3
%%SUID%%@(,,4555) bin/Xorg.wrap
4
bin/cvt
4
bin/cvt
5
bin/gtf
5
bin/gtf
6
include/xorg/BT.h
6
include/xorg/BT.h
Lines 159-165 Link Here
159
include/xorg/xorg-server.h
159
include/xorg/xorg-server.h
160
include/xorg/xorgVersion.h
160
include/xorg/xorgVersion.h
161
include/xorg/xserver-properties.h
161
include/xorg/xserver-properties.h
162
@comment include/xorg/xserver_poll.h
162
include/xorg/xserver_poll.h
163
include/xorg/xvdix.h
163
include/xorg/xvdix.h
164
include/xorg/xvmcext.h
164
include/xorg/xvmcext.h
165
lib/xorg/modules/drivers/modesetting_drv.so
165
lib/xorg/modules/drivers/modesetting_drv.so
Lines 177-182 Link Here
177
lib/xorg/protocol.txt
177
lib/xorg/protocol.txt
178
libdata/pkgconfig/xorg-server.pc
178
libdata/pkgconfig/xorg-server.pc
179
man/man1/Xorg.1.gz
179
man/man1/Xorg.1.gz
180
%%SUID%%man/man1/Xorg.wrap.1.gz
180
man/man1/Xserver.1.gz
181
man/man1/Xserver.1.gz
181
man/man1/cvt.1.gz
182
man/man1/cvt.1.gz
182
man/man1/gtf.1.gz
183
man/man1/gtf.1.gz
Lines 183-189 Link Here
183
man/man4/exa.4.gz
184
man/man4/exa.4.gz
184
man/man4/fbdevhw.4.gz
185
man/man4/fbdevhw.4.gz
185
man/man4/modesetting.4.gz
186
man/man4/modesetting.4.gz
187
%%SUID%%man/man5/Xwrapper.config.5.gz
186
man/man5/xorg.conf.5.gz
188
man/man5/xorg.conf.5.gz
187
man/man5/xorg.conf.d.5.gz
189
man/man5/xorg.conf.d.5.gz
190
%%UDEV%%share/X11/xorg.conf.d/10-quirks.conf
188
share/aclocal/xorg-server.m4
191
share/aclocal/xorg-server.m4
189
@dir etc/X11/xorg.conf.d
192
@dir etc/X11/xorg.conf.d
(-)x11-servers/xorg-vfbserver/Makefile (-6 lines)
Lines 2-8 Link Here
2
# $FreeBSD$
2
# $FreeBSD$
3
3
4
PORTNAME=	xorg-vfbserver
4
PORTNAME=	xorg-vfbserver
5
PORTVERSION=	1.19.1
6
PORTEPOCH=	1
5
PORTEPOCH=	1
7
6
8
COMMENT=	X virtual framebuffer server from X.Org
7
COMMENT=	X virtual framebuffer server from X.Org
Lines 11-24 Link Here
11
10
12
MASTERDIR=	${.CURDIR}/../xorg-server
11
MASTERDIR=	${.CURDIR}/../xorg-server
13
DESCR=		${.CURDIR}/pkg-descr
12
DESCR=		${.CURDIR}/pkg-descr
14
DISTINFO_FILE=	${.CURDIR}/distinfo
15
PATCHDIR=	${.CURDIR}/files
16
13
17
SLAVE_PORT=	yes
14
SLAVE_PORT=	yes
18
OPTIONS_EXCLUDE=DEVD HAL SUID
19
15
20
USE_XORG=	xfont2
21
22
CONFIGURE_ARGS+=--enable-xvfb --disable-dmx --disable-xephyr --disable-xnest \
16
CONFIGURE_ARGS+=--enable-xvfb --disable-dmx --disable-xephyr --disable-xnest \
23
		--disable-xwayland
17
		--disable-xwayland
24
18
(-)x11-servers/xorg-vfbserver/distinfo (-3 lines)
Lines 1-3 Link Here
1
TIMESTAMP = 1484389062
2
SHA256 (xorg/xserver/xorg-server-1.19.1.tar.bz2) = 79ae2cf39d3f6c4a91201d8dad549d1d774b3420073c5a70d390040aa965a7fb
3
SIZE (xorg/xserver/xorg-server-1.19.1.tar.bz2) = 6041792
(-)x11-servers/xwayland/Makefile (-9 / +3 lines)
Lines 1-7 Link Here
1
# $FreeBSD$
1
# $FreeBSD$
2
2
3
PORTNAME=	xwayland
3
PORTNAME=	xwayland
4
PORTVERSION=	1.19.1
5
4
6
COMMENT=	X Clients under Wayland
5
COMMENT=	X Clients under Wayland
7
6
Lines 13-30 Link Here
13
12
14
MASTERDIR=	${.CURDIR}/../xorg-server
13
MASTERDIR=	${.CURDIR}/../xorg-server
15
DESCR=		${.CURDIR}/pkg-descr
14
DESCR=		${.CURDIR}/pkg-descr
16
DISTINFO_FILE=	${.CURDIR}/distinfo
17
PATCHDIR=	${.CURDIR}/files
18
15
19
SLAVE_PORT=	yes
16
SLAVE_PORT=	yes
20
OPTIONS_EXCLUDE=DEVD HAL SUID
17
USE_XORG=	x11 xext
21
22
USE_XORG=	x11 xext xfont2
23
USE_GL+=	egl gbm
18
USE_GL+=	egl gbm
24
19
25
CONFIGURE_ARGS+=	--disable-docs --disable-devel-docs \
20
CONFIGURE_ARGS+=--disable-dmx --disable-xephyr --disable-xnest --disable-xvfb \
26
			--enable-xwayland --disable-xorg --disable-xvfb --disable-xnest \
21
		--enable-xwayland 
27
			--disable-xquartz --disable-xwin
28
22
29
PLIST_FILES=	bin/Xwayland
23
PLIST_FILES=	bin/Xwayland
30
24
(-)x11-servers/xwayland/distinfo (-3 lines)
Lines 1-3 Link Here
1
TIMESTAMP = 1484388904
2
SHA256 (xorg/xserver/xorg-server-1.19.1.tar.bz2) = 79ae2cf39d3f6c4a91201d8dad549d1d774b3420073c5a70d390040aa965a7fb
3
SIZE (xorg/xserver/xorg-server-1.19.1.tar.bz2) = 6041792

Return to bug 196678