Ravenports generated: 10 Feb 2024 22:55
[ravenports.git] / bucket_E7 / xorg-server
1 # Buildsheet autogenerated by ravenadm tool -- Do not edit.
2
3 NAMEBASE=               xorg-server
4 VERSION=                21.1.11
5 REVISION=               1
6 KEYWORDS=               x11_servers
7 VARIANTS=               standard virtual xephyr nest
8 SDESC[xephyr]=          X server from X.Org based on kdrive
9 SDESC[virtual]=         X virtual framebuffer server from X.Org
10 SDESC[standard]=        X.Org X server and related programs
11 SDESC[nest]=            Nesting X server from X.Org
12 HOMEPAGE=               https://www.x.org/
13 CONTACT=                nobody
14
15 DOWNLOAD_GROUPS=        main
16 SITES[main]=            XORG/individual/xserver
17 DISTFILE[1]=            xorg-server-21.1.11.tar.xz:main
18 DF_INDEX=               1
19 SPKGS[xephyr]=          complete
20                         primary
21                         man
22 SPKGS[virtual]=         complete
23                         primary
24                         man
25 SPKGS[standard]=        complete
26                         primary
27                         man
28                         dev
29 SPKGS[nest]=            complete
30                         primary
31                         man
32
33 OPTIONS_AVAILABLE=      XORG VIRTUAL XEPHYR NEST UDEV
34 OPTIONS_STANDARD=       XORG UDEV
35 VOPTS[xephyr]=          XORG=OFF VIRTUAL=OFF XEPHYR=ON NEST=OFF UDEV=OFF
36 VOPTS[virtual]=         XORG=OFF VIRTUAL=ON XEPHYR=OFF NEST=OFF UDEV=OFF
37 VOPTS[nest]=            XORG=OFF VIRTUAL=OFF XEPHYR=OFF NEST=ON UDEV=OFF
38 OPT_ON[freebsd]=        UDEV
39 OPT_ON[linux]=          UDEV
40 OPT_ON[all]=            XORG
41 OPT_ON[midnightbsd]=    UDEV
42
43 BUILD_DEPENDS=          libdrm:dev:standard
44                         libgpg-error:dev:standard
45 BUILDRUN_DEPENDS=       xorg-xkbcomp:single:standard
46 RUN_DEPENDS=            xorg-xkeyboard-config:primary:standard
47 EXRUN[dev]=             xorg-pixman:dev:standard
48                         xorg-pciaccess:dev:standard
49
50 USES=                   cpe perl:build ssl solaris-funcs meson zlib:build
51 XORG_COMPONENTS=        xorgproto xtransproto pixman xshmfence xau xdmcp
52                         xfont2 xkbfile
53
54 LICENSE=                MIT:primary
55 LICENSE_FILE=           MIT:{{WRKSRC}}/COPYING
56 LICENSE_SCHEME=         solo
57
58 CPE_VENDOR=             x.org
59 FPC_EQUIVALENT=         x11-servers/xorg-server
60 MESON_ARGS=             -Dxkb_dir="{{LOCALBASE}}/share/X11/xkb"
61                         -Ddefault_font_path="{{fontlist:ts,}}"
62                         -Dglamor=false
63                         -Dxcsecurity=true
64                         -Ddtrace=false
65                         -Dhal=false
66                         -Dudev_kms=false
67                         -Dxwin=false
68                         -Dxquartz=false
69                         -Dsystemd_logind=false
70                         -Dxselinux=false
71                         -Dfallback_input_driver=libinput
72                         -Dxkb_dir={{LOCALBASE}}/share/X11/xkb
73                         -Dxkb_output_dir=/var/lib/xkb
74 SOL_FUNCTIONS=          strnlen:xkb/XKBGAlloc.c
75
76 VAR_OPSYS[sunos]=       CFLAGS=-DO_CLOEXEC=0
77 VAR_OPSYS[netbsd]=      CPPFLAGS=-D_OPENBSD_SOURCE
78                         CONFIGURE_ARGS=-Dsecure-rpc=false
79
80 [NEST].DESCRIPTION=                     Build as nesting X server
81 [NEST].BUILDRUN_DEPENDS_ON=             libglvnd:primary:standard
82 [NEST].BUILD_DEPENDS_ON=                libepoxy:primary:standard
83                                         libepoxy:dev:standard
84                                         mesa:drivers:standard
85                                         mesa:dev:standard
86                                         libglvnd:dev:standard
87 [NEST].CONFIGURE_ARGS_OFF=              -Dxnest=false
88 [NEST].CONFIGURE_ARGS_ON=               -Dxnest=true
89 [NEST].XORG_COMPONENTS_ON=              x11
90                                         xext
91
92 [UDEV].DESCRIPTION=                     Use udev for autoconfiguration of input devices
93 [UDEV].BUILDRUN_DEPENDS_ON=             libudev-devd:primary:standard
94 [UDEV].BUILD_DEPENDS_ON=                libudev-devd:dev:standard
95 [UDEV].CONFIGURE_ARGS_OFF=              -Dudev=false
96 [UDEV].CONFIGURE_ARGS_ON=               -Dudev=true
97
98 [XEPHYR].DESCRIPTION=                   Build as kdrive-base X server
99 [XEPHYR].BUILDRUN_DEPENDS_ON=           libdrm:primary:standard
100                                         libepoxy:primary:standard
101                                         libglvnd:primary:standard
102 [XEPHYR].BUILD_DEPENDS_ON=              mesa:drivers:standard
103                                         mesa:dev:standard
104                                         libepoxy:dev:standard
105                                         libglvnd:dev:standard
106 [XEPHYR].CONFIGURE_ARGS_OFF=            -Dxephyr=false
107 [XEPHYR].CONFIGURE_ARGS_ON=             -Dxephyr=true
108 [XEPHYR].XORG_COMPONENTS_ON=            x11
109                                         xcb
110                                         xcb-util
111                                         xcb-util-image
112                                         xcb-util-wm
113                                         xcb-util-keysyms
114                                         xcb-render-util
115
116 [VIRTUAL].DESCRIPTION=                  Build as virtual framebuffer server
117 [VIRTUAL].BUILDRUN_DEPENDS_ON=          libglvnd:primary:standard
118 [VIRTUAL].BUILD_DEPENDS_ON=             libepoxy:primary:standard
119                                         libepoxy:dev:standard
120                                         mesa:drivers:standard
121                                         mesa:dev:standard
122                                         libglvnd:dev:standard
123 [VIRTUAL].CONFIGURE_ARGS_OFF=           -Dxvfb=false
124 [VIRTUAL].CONFIGURE_ARGS_ON=            -Dxvfb=true
125
126 [XORG].DESCRIPTION=                     Build as X server (don't change setting!)
127 [XORG].BUILDRUN_DEPENDS_ON=             libdrm:primary:standard
128                                         libepoxy:primary:standard
129                                         mesa:drivers:standard
130                                         xorg-xcvt:primary:standard
131 [XORG].BUILD_DEPENDS_ON=                xmlto:single:standard
132                                         xorg-sgml-doctools:single:standard
133                                         mesa:dev:standard
134                                         libepoxy:dev:standard
135                                         xorg-xcvt:dev:standard
136 [XORG].CONFIGURE_ARGS_OFF=              -Ddocs=false
137                                         -Ddevel-docs=false
138                                         -Dxorg=false
139 [XORG].CONFIGURE_ARGS_ON=               -Ddocs=true
140                                         -Ddevel-docs=true
141                                         -Dxorg=true
142                                         -Dlog_dir=/var/log
143                                         -Dsuid_wrapper=true
144 [XORG].XORG_COMPONENTS_ON=              pciaccess
145                                         xfont2
146
147 post-install-XORG-OFF:
148         ${RM} -r ${STAGEDIR}${PREFIX}/lib/xorg
149         ${RM} ${STAGEDIR}${PREFIX}/share/man/man1/Xserver.1
150         ${MKDIR} ${STAGEDIR}/var/lib/xkb
151
152 post-install-XORG-ON:
153         ${RM} -r ${STAGEDIR}${STD_DOCDIR}
154         ${MKDIR} ${STAGEDIR}${PREFIX}/share/X11/xorg.conf.d
155         ${MKDIR} ${STAGEDIR}${PREFIX}/etc/X11/xorg.conf.d
156         ${MKDIR} ${STAGEDIR}${fontpathd}
157         ${MKDIR} ${STAGEDIR}/var/lib/xkb
158         ${INSTALL_DATA} ${FILESDIR}/20-evdev-kbd.conf \
159                 ${STAGEDIR}${PREFIX}/share/X11/xorg.conf.d
160
161 [FILE:71:descriptions/desc.primary.standard]
162 This package contains the X.Org X server and some associated programs.
163
164
165 [FILE:60:descriptions/desc.primary.virtual]
166 This package contains Xvfb, a virtual framebuffer X server.
167
168
169 [FILE:173:descriptions/desc.primary.xephyr]
170 Xephyr is a kdrive server that outputs to a window on a pre-existing
171 'host' X display.  Think Xnest but with support for modern extensions
172 like composite, damage and randr.
173
174
175 [FILE:78:descriptions/desc.primary.nest]
176 This package contains Xnest, a nesting X Server that displays on an X
177 Server.
178
179
180 [FILE:105:distinfo]
181 1d3dadbd57fb86b16a018e9f5f957aeeadf744f56c0553f55737628d06d326ef      4985464 xorg-server-21.1.11.tar.xz
182
183
184 [FILE:432:manifests/plist.primary.standard]
185 bin/
186  X
187  Xorg
188  gtf
189 etc/X11/xorg.conf.d/10-quirks.conf
190 lib/xorg/protocol.txt
191 lib/xorg/modules/
192  libexa.so
193  libfbdevhw.so
194  libint10.so
195  libshadow.so
196  libshadowfb.so
197  libvgahw.so
198  libwfb.so
199 lib/xorg/modules/drivers/modesetting_drv.so
200 lib/xorg/modules/extensions/libglx.so
201 lib/xorg/modules/input/inputtest_drv.so
202 libexec/Xorg
203 @(,,4555) libexec/Xorg.wrap
204 share/X11/xorg.conf.d/20-evdev-kbd.conf
205 @dir /var/lib/xkb
206 @dir etc/X11/fontpath.d
207
208
209 [FILE:216:manifests/plist.man.standard]
210 share/man/man1/
211  Xorg.1.gz
212  Xorg.wrap.1.gz
213  Xserver.1.gz
214  gtf.1.gz
215 share/man/man4/
216  exa.4.gz
217  fbdevhw.4.gz
218  inputtestdrv.4.gz
219  modesetting.4.gz
220 share/man/man5/
221  Xwrapper.config.5.gz
222  xorg.conf.5.gz
223  xorg.conf.d.5.gz
224
225
226 [FILE:1983:manifests/plist.dev.standard]
227 %%ONLY-SUNOS%%include/xorg/solaris-amd64.il
228 include/xorg/
229  XIstubs.h
230  Xprintf.h
231  callback.h
232  client.h
233  closestr.h
234  closure.h
235  colormap.h
236  colormapst.h
237  compiler.h
238  compositeext.h
239  cursor.h
240  cursorstr.h
241  damage.h
242  damagestr.h
243  dbestruct.h
244  dgaproc.h
245  displaymode.h
246  dix.h
247  dixaccess.h
248  dixevents.h
249  dixfont.h
250  dixfontstr.h
251  dixgrabs.h
252  dixstruct.h
253  dri.h
254  dri2.h
255  dri3.h
256  dristruct.h
257  edid.h
258  events.h
259  exa.h
260  exevents.h
261  extension.h
262  extinit.h
263  extnsionst.h
264  fb.h
265  fbdevhw.h
266  fboverlay.h
267  fbpict.h
268  fbrop.h
269  fourcc.h
270  gc.h
271  gcstruct.h
272  geext.h
273  geint.h
274  globals.h
275  glx_extinit.h
276  glxvndabi.h
277  glyphstr.h
278  hotplug.h
279  i2c_def.h
280  input.h
281  inputstr.h
282  list.h
283  mi.h
284  micmap.h
285  micoord.h
286  migc.h
287  miline.h
288  mioverlay.h
289  mipict.h
290  mipointer.h
291  mipointrst.h
292  misc.h
293  miscstruct.h
294  mistruct.h
295  misync.h
296  misyncfd.h
297  misyncshm.h
298  misyncstr.h
299  mizerarc.h
300  nonsdk_extinit.h
301  opaque.h
302  optionstr.h
303  os.h
304  panoramiX.h
305  panoramiXsrv.h
306  picture.h
307  picturestr.h
308  pixmap.h
309  pixmapstr.h
310  present.h
311  presentext.h
312  privates.h
313  property.h
314  propertyst.h
315  ptrveloc.h
316  randrstr.h
317  region.h
318  regionstr.h
319  registry.h
320  resource.h
321  rgb.h
322  rrtransform.h
323  sarea.h
324  screenint.h
325  scrnintstr.h
326  selection.h
327  servermd.h
328  shadow.h
329  shadowfb.h
330  shmint.h
331  syncsdk.h
332  validate.h
333  vbe.h
334  vbeModes.h
335  vgaHW.h
336  vndserver.h
337  wfbrename.h
338  window.h
339  windowstr.h
340  xaarop.h
341  xace.h
342  xacestr.h
343  xf86-input-inputtest-protocol.h
344  xf86.h
345  xf86Crtc.h
346  xf86Cursor.h
347  xf86DDC.h
348  xf86MatchDrivers.h
349  xf86Modes.h
350  xf86Module.h
351  xf86Opt.h
352  xf86Optionstr.h
353  xf86Optrec.h
354  xf86Parser.h
355  xf86Pci.h
356  xf86PciInfo.h
357  xf86Priv.h
358  xf86Privstr.h
359  xf86RandR12.h
360  xf86VGAarbiter.h
361  xf86Xinput.h
362  xf86_OSlib.h
363  xf86_OSproc.h
364  xf86cmap.h
365  xf86fbman.h
366  xf86i2c.h
367  xf86int10.h
368  xf86platformBus.h
369  xf86sbusBus.h
370  xf86str.h
371  xf86xv.h
372  xf86xvmc.h
373  xf86xvpriv.h
374  xisb.h
375  xkbfile.h
376  xkbrules.h
377  xkbsrv.h
378  xkbstr.h
379  xorg-server.h
380  xorgVersion.h
381  xserver-properties.h
382  xserver_poll.h
383  xvdix.h
384  xvmcext.h
385 lib/pkgconfig/xorg-server.pc
386 share/aclocal/xorg-server.m4
387
388
389 [FILE:27:manifests/plist.primary.virtual]
390 bin/Xvfb
391 @dir /var/lib/xkb
392
393
394 [FILE:25:manifests/plist.man.virtual]
395 share/man/man1/Xvfb.1.gz
396
397
398 [FILE:29:manifests/plist.primary.xephyr]
399 bin/Xephyr
400 @dir /var/lib/xkb
401
402
403 [FILE:27:manifests/plist.man.xephyr]
404 share/man/man1/Xephyr.1.gz
405
406
407 [FILE:28:manifests/plist.primary.nest]
408 bin/Xnest
409 @dir /var/lib/xkb
410
411
412 [FILE:26:manifests/plist.man.nest]
413 share/man/man1/Xnest.1.gz
414
415
416 [FILE:293:patches/patch-config_config-backends.h]
417 --- config/config-backends.h.orig       2023-12-13 01:31:04 UTC
418 +++ config/config-backends.h
419 @@ -44,3 +44,8 @@ void config_hal_fini(void);
420  int config_wscons_init(void);
421  void config_wscons_fini(void);
422  #endif
423 +
424 +#ifdef CONFIG_DEVD
425 +int config_devd_init(void);
426 +void config_devd_fini(void);
427 +#endif
428
429
430 [FILE:537:patches/patch-config_config.c]
431 --- config/config.c.orig        2023-12-13 01:31:04 UTC
432 +++ config/config.c
433 @@ -55,6 +55,9 @@ config_init(void)
434  #elif defined(CONFIG_WSCONS)
435      if (!config_wscons_init())
436          ErrorF("[config] failed to initialise wscons\n");
437 +#elif defined(CONFIG_DEVD)
438 +    if (!config_devd_init())
439 +        ErrorF("[config] failed to initialise devd\n");
440  #endif
441  }
442  
443 @@ -67,6 +70,8 @@ config_fini(void)
444      config_hal_fini();
445  #elif defined(CONFIG_WSCONS)
446      config_wscons_fini();
447 +#elif defined(CONFIG_DEVD)
448 +    config_devd_fini();
449  #endif
450  }
451  
452
453
454 [FILE:12171:patches/patch-config_devd.c]
455 --- /dev/null   2024-01-16 12:14:31 UTC
456 +++ config/devd.c
457 @@ -0,0 +1,532 @@
458 +/*
459 + * Copyright (c) 2012 Baptiste Daroussin
460 + * Copyright (c) 2013, 2014 Alex Kozlov
461 + * Copyright (c) 2014 Robert Millan
462 + * Copyright (c) 2014 Jean-Sebastien Pedron
463 + *
464 + * Permission is hereby granted, free of charge, to any person obtaining a
465 + * copy of this software and associated documentation files (the "Software"),
466 + * to deal in the Software without restriction, including without limitation
467 + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
468 + * and/or sell copies of the Software, and to permit persons to whom the
469 + * Software is furnished to do so, subject to the following conditions:
470 + *
471 + * The above copyright notice and this permission notice (including the next
472 + * paragraph) shall be included in all copies or substantial portions of the
473 + * Software.
474 + *
475 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
476 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
477 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
478 + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
479 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
480 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
481 + * DEALINGS IN THE SOFTWARE.
482 + *
483 + * Author: Baptiste Daroussin <bapt@FreeBSD.org>
484 + */
485 +
486 +#ifdef HAVE_DIX_CONFIG_H
487 +#include <dix-config.h>
488 +#endif
489 +
490 +#include <sys/types.h>
491 +#include <sys/kbio.h>
492 +#include <sys/socket.h>
493 +#include <sys/stat.h>
494 +#include <sys/sysctl.h>
495 +#include <sys/un.h>
496 +
497 +#include <ctype.h>
498 +#include <errno.h>
499 +#include <fcntl.h>
500 +#include <stdlib.h>
501 +#include <stdio.h>
502 +#include <stdbool.h>
503 +#include <unistd.h>
504 +
505 +#include "input.h"
506 +#include "inputstr.h"
507 +#include "hotplug.h"
508 +#include "config-backends.h"
509 +#include "os.h"
510 +
511 +#define DEVD_SOCK_PATH "/var/run/devd.pipe"
512 +
513 +#define DEVD_EVENT_ADD         '+'
514 +#define DEVD_EVENT_REMOVE      '-'
515 +
516 +#define RECONNECT_DELAY                5 * 1000
517 +
518 +static int sock_devd;
519 +static bool is_console_kbd = false;
520 +static bool is_kbdmux = false;
521 +static OsTimerPtr rtimer = NULL;
522 +
523 +struct hw_type {
524 +       const char *driver;
525 +       int flag;
526 +       const char *xdriver;
527 +};
528 +
529 +static struct hw_type hw_types[] = {
530 +       { "ukbd", ATTR_KEYBOARD, "kbd" },
531 +       { "atkbd", ATTR_KEYBOARD, "kbd" },
532 +       { "kbdmux", ATTR_KEYBOARD, "kbd" },
533 +       { "sysmouse", ATTR_POINTER, "mouse" },
534 +       { "ums", ATTR_POINTER, "mouse" },
535 +       { "psm", ATTR_POINTER, "mouse" },
536 +       { "vboxguest", ATTR_POINTER, "vboxmouse" },
537 +       { "joy", ATTR_JOYSTICK, NULL },
538 +       { "atp", ATTR_TOUCHPAD, NULL },
539 +       { "uep", ATTR_TOUCHSCREEN, NULL },
540 +       { NULL, -1, NULL },
541 +};
542 +
543 +static bool
544 +sysctl_exists(const struct hw_type *device, int unit,
545 +       char *devname, size_t devname_len)
546 +{
547 +       char sysctlname[PATH_MAX];
548 +       size_t len;
549 +       int ret;
550 +
551 +       if (device == NULL || device->driver == NULL)
552 +               return false;
553 +
554 +       /* Check if a sysctl exists. */
555 +       snprintf(sysctlname, sizeof(sysctlname), "dev.%s.%i.%%desc",
556 +           device->driver, unit);
557 +       ret = sysctlbyname(sysctlname, NULL, &len, NULL, 0);
558 +
559 +       if (ret == 0 && len > 0) {
560 +               snprintf(devname, devname_len, "%s%i", device->driver, unit);
561 +               return true;
562 +       }
563 +
564 +       return false;
565 +}
566 +
567 +static bool
568 +devpath_exists(const struct hw_type *device,
569 +       char *devname, size_t devname_len)
570 +{
571 +       char *devpath;
572 +       struct stat st;
573 +       int ret;
574 +
575 +       if (device == NULL || device->driver == NULL)
576 +               return false;
577 +
578 +       /* Check if /dev/$driver exists. */
579 +       asprintf(&devpath, "/dev/%s", device->driver);
580 +       if (devpath == NULL)
581 +               return false;
582 +
583 +       ret = stat(devpath, &st);
584 +       free(devpath);
585 +
586 +       if (ret == 0) {
587 +               strncpy(devname, device->driver, devname_len);
588 +               return true;
589 +       }
590 +
591 +       return false;
592 +}
593 +
594 +static char *
595 +sysctl_get_str(const char *sysctlname)
596 +{
597 +       char *dest = NULL;
598 +       size_t len;
599 +
600 +       if (sysctlname == NULL)
601 +               return NULL;
602 +
603 +       if (sysctlbyname(sysctlname, NULL, &len, NULL, 0) == 0) {
604 +               dest = malloc(len + 1);
605 +               if (dest) {
606 +                       if (sysctlbyname(sysctlname, dest, &len, NULL, 0) == 0)
607 +                               dest[len] = '\0';
608 +                       else {
609 +                               free(dest);
610 +                               dest = NULL;
611 +                       }
612 +               }
613 +       }
614 +
615 +       return dest;
616 +}
617 +
618 +static void
619 +device_added(const char *devname)
620 +{
621 +       char path[PATH_MAX];
622 +       char sysctlname[PATH_MAX];
623 +       char *vendor;
624 +       char *product = NULL;
625 +       char *config_info = NULL;
626 +       char *walk;
627 +       InputOption *options = NULL;
628 +       InputAttributes attrs = { };
629 +       DeviceIntPtr dev = NULL;
630 +       int i;
631 +       int fd;
632 +
633 +       for (i = 0; hw_types[i].driver != NULL; i++) {
634 +               size_t len;
635 +
636 +               len = strlen(hw_types[i].driver);
637 +               if (strcmp(devname, hw_types[i].driver) == 0 ||
638 +                       (strncmp(devname, hw_types[i].driver, len) == 0 &&
639 +                               isnumber(*(devname + len)))) {
640 +                       attrs.flags |= hw_types[i].flag;
641 +                       break;
642 +               }
643 +       }
644 +
645 +       if (hw_types[i].driver == NULL || hw_types[i].xdriver == NULL) {
646 +               LogMessage(X_INFO, "config/devd: ignoring device %s\n",
647 +                               devname);
648 +               return;
649 +       }
650 +
651 +       /* Skip keyboard devices if kbdmux is enabled */
652 +       if (is_kbdmux && is_console_kbd && hw_types[i].flag & ATTR_KEYBOARD) {
653 +               LogMessage(X_INFO, "config/devd: kbdmux is enabled, ignoring device %s\n",
654 +                               devname);
655 +               return;
656 +       }
657 +
658 +       snprintf(path, sizeof(path), "/dev/%s", devname);
659 +
660 +       options = input_option_new(NULL, "_source", "server/devd");
661 +       if (!options)
662 +               return;
663 +
664 +       snprintf(sysctlname, sizeof(sysctlname), "dev.%s.%s.%%desc",
665 +           hw_types[i].driver, devname + strlen(hw_types[i].driver));
666 +       vendor = sysctl_get_str(sysctlname);
667 +       if (vendor == NULL) {
668 +               options = input_option_new(options, "name", devname);
669 +       }
670 +       else {
671 +               if ((walk = strchr(vendor, ' ')) != NULL) {
672 +                       walk[0] = '\0';
673 +                       walk++;
674 +                       product = walk;
675 +                       if ((walk = strchr(product, ',')) != NULL)
676 +                               walk[0] = '\0';
677 +               }
678 +
679 +               attrs.vendor = strdup(vendor);
680 +               if (product) {
681 +                       attrs.product = strdup(product);
682 +                       options = input_option_new(options, "name", product);
683 +               }
684 +               else
685 +                       options = input_option_new(options, "name", "(unnamed)");
686 +
687 +               free(vendor);
688 +       }
689 +
690 +       /* XXX implement usb_id */
691 +       attrs.usb_id = NULL;
692 +       attrs.device = strdup(path);
693 +       options = input_option_new(options, "driver", hw_types[i].xdriver);
694 +
695 +       fd = open(path, O_RDONLY);
696 +       if (fd > 0) {
697 +               close(fd);
698 +               options = input_option_new(options, "device", path);
699 +       }
700 +       else {
701 +               if (attrs.flags & ~ATTR_KEYBOARD) {
702 +                       LogMessage(X_INFO, "config/devd: device %s already opened\n",
703 +                                        path);
704 +
705 +                       /*
706 +                        * Fail if cannot open device, it breaks AllowMouseOpenFail,
707 +                        * but it should not matter when config/devd enabled
708 +                        */
709 +                       goto unwind;
710 +               }
711 +
712 +               if (is_console_kbd) {
713 +                       /*
714 +                        * There can be only one keyboard attached to console and
715 +                        * it is already added.
716 +                        */
717 +                       LogMessage(X_WARNING, "config/devd: console keyboard is "
718 +                                       "already added, ignoring %s (%s)\n",
719 +                                       attrs.product, path);
720 +                       goto unwind;
721 +               }
722 +               else
723 +                       /*
724 +                        * Don't pass "device" option if the keyboard is already
725 +                        * attached to the console (ie. open() fails).
726 +                        * This would activate a special logic in xf86-input-keyboard.
727 +                        * Prevent any other attached to console keyboards being
728 +                        * processed. There can be only one such device.
729 +                        */
730 +                       is_console_kbd = true;
731 +       }
732 +
733 +       if (asprintf(&config_info, "devd:%s", devname) == -1) {
734 +               config_info = NULL;
735 +               goto unwind;
736 +       }
737 +
738 +       if (device_is_duplicate(config_info)) {
739 +               LogMessage(X_WARNING, "config/devd: device %s (%s) already added. "
740 +                               "ignoring\n", attrs.product, path);
741 +               goto unwind;
742 +       }
743 +
744 +       options = input_option_new(options, "config_info", config_info);
745 +       LogMessage(X_INFO, "config/devd: adding input device %s (%s)\n",
746 +                       attrs.product, path);
747 +
748 +       NewInputDeviceRequest(options, &attrs, &dev);
749 +
750 +unwind:
751 +       free(config_info);
752 +       input_option_free_list(&options);
753 +       free(attrs.usb_id);
754 +       free(attrs.product);
755 +       free(attrs.device);
756 +       free(attrs.vendor);
757 +}
758 +
759 +static void
760 +device_removed(char *devname)
761 +{
762 +       char *config_info;
763 +
764 +       if (asprintf(&config_info, "devd:%s", devname) == -1)
765 +               return;
766 +
767 +       remove_devices("devd", config_info);
768 +
769 +       free(config_info);
770 +}
771 +
772 +static bool is_kbdmux_enabled(void)
773 +{
774 +       /* Xorg uses /dev/ttyv0 as a console device */
775 +       /* const char device[]="/dev/console"; */
776 +       const char device[]="/dev/ttyv0";
777 +       keyboard_info_t info;
778 +       int fd;
779 +
780 +       fd = open(device, O_RDONLY);
781 +
782 +       if (fd < 0)
783 +               return false;
784 +
785 +       if (ioctl(fd, KDGKBINFO, &info) == -1) {
786 +               close(fd);
787 +               return false;
788 +       }
789 +
790 +       close(fd);
791 +
792 +       if (!strncmp(info.kb_name, "kbdmux", 6))
793 +               return true;
794 +
795 +       return false;
796 +}
797 +
798 +static void
799 +disconnect_devd(int sock)
800 +{
801 +       if (sock >= 0) {
802 +               RemoveGeneralSocket(sock);
803 +               close(sock);
804 +       }
805 +}
806 +
807 +static int
808 +connect_devd(void)
809 +{
810 +       struct sockaddr_un devd;
811 +       int sock;
812 +
813 +       sock = socket(AF_UNIX, SOCK_STREAM, 0);
814 +       if (sock < 0) {
815 +               LogMessage(X_ERROR, "config/devd: fail opening stream socket\n");
816 +               return -1;
817 +       }
818 +
819 +       devd.sun_family = AF_UNIX;
820 +       strlcpy(devd.sun_path, DEVD_SOCK_PATH, sizeof(devd.sun_path));
821 +
822 +       if (connect(sock, (struct sockaddr *) &devd, sizeof(devd)) < 0) {
823 +               close(sock);
824 +               LogMessage(X_ERROR, "config/devd: fail to connect to devd\n");
825 +               return -1;
826 +       }
827 +
828 +       AddGeneralSocket(sock);
829 +
830 +       return  sock;
831 +}
832 +
833 +static CARD32
834 +reconnect_handler(OsTimerPtr timer, CARD32 time, void *arg)
835 +{
836 +       int newsock;
837 +
838 +       if ((newsock = connect_devd()) > 0) {
839 +               sock_devd = newsock;
840 +               TimerFree(rtimer);
841 +               rtimer = NULL;
842 +               LogMessage(X_INFO, "config/devd: reopening devd socket\n");
843 +               return 0;
844 +       }
845 +
846 +       /* Try again after RECONNECT_DELAY */
847 +       return RECONNECT_DELAY;
848 +}
849 +
850 +static ssize_t
851 +socket_getline(int fd, char **out)
852 +{
853 +       char *buf, *newbuf;
854 +       ssize_t ret, cap, sz = 0;
855 +       char c;
856 +
857 +       cap = 1024;
858 +       buf = malloc(cap * sizeof(char));
859 +       if (!buf)
860 +               return -1;
861 +
862 +       for (;;) {
863 +               ret = read(sock_devd, &c, 1);
864 +               if (ret < 0) {
865 +                       if (errno == EINTR)
866 +                               continue;
867 +                       free(buf);
868 +                       return -1;
869 +               /* EOF - devd socket is lost */
870 +               } else if (ret == 0) {
871 +                       disconnect_devd(sock_devd);
872 +                       rtimer = TimerSet(NULL, 0, 1, reconnect_handler, NULL);
873 +                       LogMessage(X_WARNING, "config/devd: devd socket is lost\n");
874 +                       free(buf);
875 +                       return -1;
876 +               }
877 +               if (c == '\n')
878 +                       break;
879 +
880 +               if (sz + 1 >= cap) {
881 +                       cap *= 2;
882 +                       newbuf = realloc(buf, cap * sizeof(char));
883 +                       if (!newbuf) {
884 +                               free(buf);
885 +                               return -1;
886 +                       }
887 +                       buf = newbuf;
888 +               }
889 +               buf[sz] = c;
890 +               sz++;
891 +       }
892 +
893 +       buf[sz] = '\0';
894 +       if (sz >= 0)
895 +               *out = buf;
896 +       else
897 +               free(buf);
898 +
899 +       /* Number of bytes in the line, not counting the line break */
900 +       return sz;
901 +}
902 +
903 +static void
904 +wakeup_handler(void *data, int err, void *read_mask)
905 +{
906 +       char *line = NULL;
907 +       char *walk;
908 +
909 +       if (err < 0)
910 +               return;
911 +
912 +       if (FD_ISSET(sock_devd, (fd_set *) read_mask)) {
913 +               if (socket_getline(sock_devd, &line) < 0)
914 +                       return;
915 +
916 +               walk = strchr(line + 1, ' ');
917 +               if (walk != NULL)
918 +                       walk[0] = '\0';
919 +
920 +               switch (*line) {
921 +               case DEVD_EVENT_ADD:
922 +                       device_added(line + 1);
923 +                       break;
924 +               case DEVD_EVENT_REMOVE:
925 +                       device_removed(line + 1);
926 +                       break;
927 +               default:
928 +                       break;
929 +               }
930 +               free(line);
931 +       }
932 +}
933 +
934 +static void
935 +block_handler(void *data, struct timeval **tv, void *read_mask)
936 +{
937 +}
938 +
939 +int
940 +config_devd_init(void)
941 +{
942 +       char devicename[1024];
943 +       int i, j;
944 +
945 +       LogMessage(X_INFO, "config/devd: probing input devices...\n");
946 +
947 +       /*
948 +        * Add fake keyboard and give up on keyboards management
949 +        * if kbdmux is enabled
950 +        */
951 +       if ((is_kbdmux = is_kbdmux_enabled()) == true)
952 +               device_added("kbdmux");
953 +
954 +       for (i = 0; hw_types[i].driver != NULL; i++) {
955 +               /* First scan the sysctl to determine the hardware */
956 +               for (j = 0; j < 16; j++) {
957 +                       if (sysctl_exists(&hw_types[i], j,
958 +                                       devicename, sizeof(devicename)) != 0)
959 +                               device_added(devicename);
960 +               }
961 +
962 +               if (devpath_exists(&hw_types[i], devicename, sizeof(devicename)) != 0)
963 +                       device_added(devicename);
964 +       }
965 +
966 +       if ((sock_devd = connect_devd()) < 0)
967 +               return 0;
968 +
969 +       RegisterBlockAndWakeupHandlers(block_handler, wakeup_handler, NULL);
970 +
971 +       return 1;
972 +}
973 +
974 +void
975 +config_devd_fini(void)
976 +{
977 +       LogMessage(X_INFO, "config/devd: terminating backend...\n");
978 +
979 +       if (rtimer) {
980 +               TimerFree(rtimer);
981 +               rtimer = NULL;
982 +       }
983 +
984 +       disconnect_devd(sock_devd);
985 +
986 +       RemoveBlockAndWakeupHandlers(block_handler, wakeup_handler, NULL);
987 +
988 +       is_console_kbd = false;
989 +}
990
991
992 [FILE:391:patches/patch-config_meson.build]
993 --- config/meson.build.orig     2023-12-13 01:31:04 UTC
994 +++ config/meson.build
995 @@ -25,7 +25,7 @@ endif
996  
997  if build_xorg
998      install_data('10-quirks.conf',
999 -                 install_dir: join_paths(get_option('datadir'), 'X11/xorg.conf.d'))
1000 +                 install_dir: join_paths(get_option('prefix'), 'etc/X11/xorg.conf.d'))
1001  endif
1002  
1003  libxserver_config = static_library('libxserver_config',
1004
1005
1006 [FILE:3104:patches/patch-config_udev.c]
1007 --- config/udev.c.orig  2023-12-13 01:31:04 UTC
1008 +++ config/udev.c
1009 @@ -29,6 +29,7 @@
1010  
1011  #include <libudev.h>
1012  #include <ctype.h>
1013 +#include <fcntl.h>
1014  #include <unistd.h>
1015  
1016  #include "input.h"
1017 @@ -67,6 +68,45 @@ config_udev_odev_setup_attribs(struct ud
1018  
1019  static char itoa_buf[16];
1020  
1021 +#if defined(__DragonFly__)
1022 +// Taken from FreeBSD's lib/libc/gen/feature_present.c
1023 +
1024 +#include <sys/cdefs.h>
1025 +#include <sys/types.h>
1026 +#include <sys/sysctl.h>
1027 +#include <stdio.h>
1028 +#include <stdlib.h>
1029 +#include <unistd.h>
1030 +
1031 +int      feature_present(const char *);
1032 +/*
1033 + * Returns true if the named feature is present in the currently
1034 + * running kernel.  A feature's presence is indicated by an integer
1035 + * sysctl node called kern.feature.<feature> that is non-zero.
1036 + */
1037 +int
1038 +feature_present(const char *feature)
1039 +{
1040 +       char *mib;
1041 +       size_t len;
1042 +       int i;
1043 +
1044 +       if (asprintf(&mib, "kern.features.%s", feature) < 0)
1045 +               return (0);
1046 +       len = sizeof(i);
1047 +       if (sysctlbyname(mib, &i, &len, NULL, 0) < 0) {
1048 +               free(mib);
1049 +               return (0);
1050 +       }
1051 +       free(mib);
1052 +       if (len != sizeof(i))
1053 +               return (0);
1054 +       return (i != 0);
1055 +}
1056 +
1057 +// end of FreeBSD's lib/libc/gen/feature_present.c
1058 +#endif
1059 +
1060  static const char *itoa(int i)
1061  {
1062      snprintf(itoa_buf, sizeof(itoa_buf), "%d", i);
1063 @@ -198,7 +238,21 @@ device_added(struct udev_device *udev_de
1064          attrs.product = strdup(name);
1065      input_options = input_option_new(input_options, "name", name);
1066      input_options = input_option_new(input_options, "path", path);
1067 -    input_options = input_option_new(input_options, "device", path);
1068 +    if(strstr(path, "kbdmux") != NULL) {
1069 +        /*
1070 +         * Don't pass "device" option if the keyboard is already attached
1071 +         * to the console (ie. open() fails). This would activate a special
1072 +         * logic in xf86-input-keyboard. Prevent any other attached to console
1073 +         * keyboards being processed. There can be only one such device.
1074 +         */
1075 +        int fd = open(path, O_RDONLY);
1076 +        if (fd > -1) {
1077 +            close(fd);
1078 +            input_options = input_option_new(input_options, "device", path);
1079 +        }
1080 +    }
1081 +    else
1082 +        input_options = input_option_new(input_options, "device", path);
1083      input_options = input_option_new(input_options, "major", itoa(major(devnum)));
1084      input_options = input_option_new(input_options, "minor", itoa(minor(devnum)));
1085      if (path)
1086 @@ -280,6 +334,18 @@ device_added(struct udev_device *udev_de
1087          }
1088      }
1089  
1090 +    if (attrs.flags & (ATTR_KEY | ATTR_KEYBOARD)) {
1091 +        if (!feature_present("evdev_support"))
1092 +            input_options = input_option_new(input_options, "driver", "kbd");
1093 +    } else if (attrs.flags & ATTR_POINTER) {
1094 +        if (strstr(path, "vbox"))
1095 +            input_options = input_option_new(input_options, "driver", "vboxmouse");
1096 +        else {
1097 +            if (!feature_present("evdev_support"))
1098 +                input_options = input_option_new(input_options, "driver", "mouse");
1099 +        }
1100 +    }
1101 +
1102      input_options = input_option_new(input_options, "config_info", config_info);
1103  
1104      /* Default setting needed for non-seat0 seats */
1105
1106
1107 [FILE:1646:patches/patch-configure]
1108 --- configure.orig      2023-12-13 01:31:14 UTC
1109 +++ configure
1110 @@ -24707,14 +24707,14 @@ printf "%s\n" "#define USE_ALPHA_PIO 1"
1111    x86_64*|amd64*)
1112         I386_VIDEO=yes
1113         case $host_os in
1114 -               *freebsd*)
1115 +               *freebsd*|*midnight*)
1116  printf "%s\n" "#define USE_DEV_IO 1" >>confdefs.h
1117   ;;
1118                 *dragonfly*)
1119  printf "%s\n" "#define USE_DEV_IO 1" >>confdefs.h
1120   ;;
1121                 *netbsd*)
1122 -printf "%s\n" "#define USE_I386_IOPL 1" >>confdefs.h
1123 +printf "%s\n" "#define USE_AMD64_IOPL 1" >>confdefs.h
1124  
1125                                 SYS_LIBS=-lx86_64
1126                                 ;;
1127 @@ -24778,7 +24778,7 @@ fi
1128  
1129  DRI=no
1130  case $host_os in
1131 -  *freebsd* | *dragonfly*)
1132 +  *freebsd* | *dragonfly*| *midnight*)
1133         case $host_os in
1134                 kfreebsd*-gnu) ;;
1135                 *)
1136 @@ -26588,7 +26588,8 @@ case ${host_os} in
1137         netbsd*)
1138         # use libc stubs, don't link against libpthread, to allow
1139         # dynamic loading
1140 -       ax_pthread_flags=""
1141 +       ax_pthread_flags="none"
1142 +       ax_pthread_ok="yes"
1143         ;;
1144  esac
1145  
1146 @@ -28097,7 +28098,7 @@ fi
1147  case "x$XTRANS_SEND_FDS" in
1148  xauto)
1149         case "$host_os" in
1150 -       linux*|solaris*|freebsd*|dragonfly*|openbsd*)
1151 +       linux*|solaris*|freebsd*|dragonfly*|openbsd*|midnight*)
1152                 XTRANS_SEND_FDS=yes
1153                 ;;
1154         *)
1155 @@ -30713,7 +30714,7 @@ printf "%s\n" "#define PCI_TXT_IDS_PATH
1156    test "$exec_prefix_NONE" && exec_prefix=NONE
1157  
1158                 case $host_os in
1159 -                 gnu* | freebsd* | kfreebsd*-gnu | netbsd* | openbsd* | solaris* | dragonfly*)
1160 +                 gnu* | freebsd* | kfreebsd*-gnu | netbsd* | openbsd* | solaris* | dragonfly* | midnight*)
1161                         xorg_bus_bsdpci="yes"
1162                         ;;
1163                 esac
1164 @@ -30763,7 +30764,7 @@ fi
1165  
1166  done
1167                 ;;
1168 -         freebsd* | kfreebsd*-gnu | dragonfly*)
1169 +         freebsd* | kfreebsd*-gnu | dragonfly* | midnight*)
1170                 XORG_OS_SUBDIR="bsd"
1171                 ;;
1172           netbsd*)
1173
1174
1175 [FILE:256:patches/patch-hw_kdrive_ephyr_hostx.c]
1176 --- hw/kdrive/ephyr/hostx.c.orig        2023-12-13 01:31:04 UTC
1177 +++ hw/kdrive/ephyr/hostx.c
1178 @@ -36,7 +36,6 @@
1179  #include <string.h>             /* for memset */
1180  #include <errno.h>
1181  #include <time.h>
1182 -#include <err.h>
1183  
1184  #include <sys/ipc.h>
1185  #include <sys/shm.h>
1186
1187
1188 [FILE:791:patches/patch-hw_xfree86_common_xf86AutoConfig.c]
1189 --- hw/xfree86/common/xf86AutoConfig.c.orig     2023-12-13 01:31:04 UTC
1190 +++ hw/xfree86/common/xf86AutoConfig.c
1191 @@ -294,7 +294,7 @@ listPossibleVideoDrivers(XF86MatchedDriv
1192      xf86PciMatchDriver(md);
1193  #endif
1194  
1195 -#if defined(__linux__)
1196 +#if defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__)
1197      xf86AddMatchedDriver(md, "modesetting");
1198  #endif
1199  
1200 @@ -302,8 +302,10 @@ listPossibleVideoDrivers(XF86MatchedDriv
1201      /* Fallback to platform default frame buffer driver */
1202  #if !defined(__linux__) && defined(__sparc__)
1203      xf86AddMatchedDriver(md, "wsfb");
1204 -#else
1205 +#elif defined(__linux__)
1206      xf86AddMatchedDriver(md, "fbdev");
1207 +#elif defined(__FreeBSD__) || defined(__DragonFly__)
1208 +    xf86AddMatchedDriver(md, "scfb");
1209  #endif
1210  #endif                          /* !__sun */
1211  
1212
1213
1214 [FILE:700:patches/patch-hw_xfree86_common_xf86Config.c]
1215 --- hw/xfree86/common/xf86Config.c.orig 2023-12-13 01:31:04 UTC
1216 +++ hw/xfree86/common/xf86Config.c
1217 @@ -1279,13 +1279,16 @@ checkCoreInputDevices(serverLayoutPtr se
1218      }
1219  
1220      if (!xf86Info.forceInputDevices && !(foundPointer && foundKeyboard)) {
1221 -#if defined(CONFIG_HAL) || defined(CONFIG_UDEV) || defined(CONFIG_WSCONS)
1222 +#if defined(CONFIG_HAL) || defined(CONFIG_UDEV) || defined(CONFIG_WSCONS) || \
1223 +               defined(CONFIG_DEVD)
1224          const char *config_backend;
1225  
1226  #if defined(CONFIG_HAL)
1227          config_backend = "HAL";
1228  #elif defined(CONFIG_UDEV)
1229          config_backend = "udev";
1230 +#elif defined(CONFIG_DEVD)
1231 +        config_backend = "devd";
1232  #else
1233          config_backend = "wscons";
1234  #endif
1235
1236
1237 [FILE:510:patches/patch-hw_xfree86_common_xf86Globals.c]
1238 --- hw/xfree86/common/xf86Globals.c.orig        2023-12-13 01:31:04 UTC
1239 +++ hw/xfree86/common/xf86Globals.c
1240 @@ -118,7 +118,7 @@ xf86InfoRec xf86Info = {
1241      .miscModInDevEnabled = TRUE,
1242      .miscModInDevAllowNonLocal = FALSE,
1243      .pmFlag = TRUE,
1244 -#if defined(CONFIG_HAL) || defined(CONFIG_UDEV) || defined(CONFIG_WSCONS)
1245 +#if defined(CONFIG_HAL) || defined(CONFIG_UDEV) || defined(CONFIG_WSCONS) || defined(CONFIG_DEVD)
1246      .forceInputDevices = FALSE,
1247      .autoAddDevices = TRUE,
1248      .autoEnableDevices = TRUE,
1249
1250
1251 [FILE:483:patches/patch-hw_xfree86_common_xf86Xinput.c]
1252 --- hw/xfree86/common/xf86Xinput.c.orig 2023-12-13 01:31:04 UTC
1253 +++ hw/xfree86/common/xf86Xinput.c
1254 @@ -1065,6 +1065,7 @@ NewInputDeviceRequest(InputOption *optio
1255          if (strcmp(key, "_source") == 0 &&
1256              (strcmp(value, "server/hal") == 0 ||
1257               strcmp(value, "server/udev") == 0 ||
1258 +             strcmp(value, "server/devd") == 0 ||
1259               strcmp(value, "server/wscons") == 0)) {
1260              is_auto = 1;
1261              if (!xf86Info.autoAddDevices) {
1262
1263
1264 [FILE:343:patches/patch-hw_xfree86_common_xf86str.h]
1265 --- hw/xfree86/common/xf86str.h.orig    2023-12-13 01:31:04 UTC
1266 +++ hw/xfree86/common/xf86str.h
1267 @@ -249,7 +249,7 @@ typedef struct _DriverRec {
1268   */
1269  
1270  /* Tolerate prior #include <linux/input.h> */
1271 -#if defined(__linux__)
1272 +#if defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__)
1273  #undef BUS_NONE
1274  #undef BUS_PCI
1275  #undef BUS_SBUS
1276
1277
1278 [FILE:596:patches/patch-hw_xfree86_drivers_modesetting_driver.c]
1279 --- hw/xfree86/drivers/modesetting/driver.c.orig        2023-12-13 01:31:04 UTC
1280 +++ hw/xfree86/drivers/modesetting/driver.c
1281 @@ -925,8 +925,12 @@ try_enable_glamor(ScrnInfoPtr pScrn)
1282      modesettingPtr ms = modesettingPTR(pScrn);
1283      const char *accel_method_str = xf86GetOptValString(ms->drmmode.Options,
1284                                                         OPTION_ACCEL_METHOD);
1285 +#if defined(__DragonFly__)
1286 +    Bool do_glamor = FALSE;
1287 +#else
1288      Bool do_glamor = (!accel_method_str ||
1289                        strcmp(accel_method_str, "glamor") == 0);
1290 +#endif
1291  
1292      ms->drmmode.glamor = FALSE;
1293  
1294
1295
1296 [FILE:359:patches/patch-hw_xfree86_meson.build]
1297 --- hw/xfree86/meson.build.orig 2023-12-13 01:31:04 UTC
1298 +++ hw/xfree86/meson.build
1299 @@ -152,7 +152,6 @@ if get_option('suid_wrapper')
1300          c_args: xorg_c_args,
1301          install: true,
1302          install_dir: get_option('libexecdir'),
1303 -        install_mode: ['r-sr-xr-x', 0, 0],
1304      )
1305  
1306      # meson gets confused when there are two targets of the same name
1307
1308
1309 [FILE:2566:patches/patch-hw_xfree86_os-support_bsd_bsd__init.c]
1310 --- hw/xfree86/os-support/bsd/bsd_init.c.orig   2023-12-13 01:31:04 UTC
1311 +++ hw/xfree86/os-support/bsd/bsd_init.c
1312 @@ -48,6 +48,8 @@ static int devConsoleFd = -1;
1313  #if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
1314  static int VTnum = -1;
1315  static int initialVT = -1;
1316 +static struct termios tty_attr;        /* tty state to restore */
1317 +static int tty_mode;           /* kbd mode to restore */
1318  #endif
1319  
1320  #ifdef PCCONS_SUPPORT
1321 @@ -230,6 +232,9 @@ xf86OpenConsole()
1322               * Add cases for other *BSD that behave the same.
1323               */
1324  #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
1325 +#if defined(__sparc64__)
1326 +           pci_system_init_dev_mem(fd);
1327 +#endif
1328              uname(&uts);
1329              i = atof(uts.release) * 100;
1330              if (i >= 310)
1331 @@ -253,6 +258,7 @@ xf86OpenConsole()
1332  #endif
1333   acquire_vt:
1334              if (!xf86Info.ShareVTs) {
1335 +                struct termios nTty;
1336                  /*
1337                   * now get the VT
1338                   */
1339 @@ -287,6 +293,26 @@ xf86OpenConsole()
1340                  if (ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS) < 0) {
1341                      FatalError("xf86OpenConsole: KDSETMODE KD_GRAPHICS failed");
1342                  }
1343 +
1344 +                tcgetattr(xf86Info.consoleFd, &tty_attr);
1345 +                ioctl(xf86Info.consoleFd, KDGKBMODE, &tty_mode);
1346 +
1347 +                /* disable special keys */
1348 +                if (ioctl(xf86Info.consoleFd, KDSKBMODE, K_RAW) < 0) {
1349 +                    FatalError("xf86OpenConsole: KDSKBMODE K_RAW failed (%s)",
1350 +                               strerror(errno));
1351 +                }
1352 +
1353 +                nTty = tty_attr;
1354 +                nTty.c_iflag = IGNPAR | IGNBRK;
1355 +                nTty.c_oflag = 0;
1356 +                nTty.c_cflag = CREAD | CS8;
1357 +                nTty.c_lflag = 0;
1358 +                nTty.c_cc[VTIME] = 0;
1359 +                nTty.c_cc[VMIN] = 1;
1360 +                cfsetispeed(&nTty, 9600);
1361 +                cfsetospeed(&nTty, 9600);
1362 +                tcsetattr(xf86Info.consoleFd, TCSANOW, &nTty);
1363              }
1364              else {              /* xf86Info.ShareVTs */
1365                  close(xf86Info.consoleFd);
1366 @@ -594,6 +620,8 @@ xf86CloseConsole()
1367      case SYSCONS:
1368      case PCVT:
1369          ioctl(xf86Info.consoleFd, KDSETMODE, KD_TEXT);  /* Back to text mode */
1370 +        ioctl(xf86Info.consoleFd, KDSKBMODE, tty_mode);
1371 +        tcsetattr(xf86Info.consoleFd, TCSANOW, &tty_attr);
1372          if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) != -1) {
1373              VT.mode = VT_AUTO;
1374              ioctl(xf86Info.consoleFd, VT_SETMODE, &VT); /* dflt vt handling */
1375
1376
1377 [FILE:519:patches/patch-hw_xfree86_os-support_bsd_i386__video.c]
1378 --- hw/xfree86/os-support/bsd/i386_video.c.orig 2023-12-13 01:31:04 UTC
1379 +++ hw/xfree86/os-support/bsd/i386_video.c
1380 @@ -32,6 +32,7 @@
1381  #include "xf86Priv.h"
1382  
1383  #include <errno.h>
1384 +#include <sys/types.h>
1385  #include <sys/mman.h>
1386  
1387  #include "xf86_OSlib.h"
1388 @@ -42,6 +43,9 @@
1389  #else
1390  #define MAP_FLAGS (MAP_FILE | MAP_SHARED)
1391  #endif
1392 +#if defined(__NetBSD__) && defined(USE_AMD64_IOPL)
1393 +#define amd64_iopl x86_64_iopl
1394 +#endif
1395  
1396  #ifdef __OpenBSD__
1397  #define SYSCTL_MSG "\tCheck that you have set 'machdep.allowaperture=1'\n"\
1398
1399
1400 [FILE:380:patches/patch-hw_xfree86_os-support_bsd_ppc__video.c]
1401 --- hw/xfree86/os-support/bsd/ppc_video.c.orig  2023-12-13 01:31:04 UTC
1402 +++ hw/xfree86/os-support/bsd/ppc_video.c
1403 @@ -79,7 +79,11 @@ xf86DisableIO()
1404  {
1405  
1406      if (ioBase != MAP_FAILED) {
1407 +#if defined(__FreeBSD__)
1408 +        munmap(__DEVOLATILE(unsigned char *, ioBase), 0x10000);
1409 +#else
1410          munmap(__UNVOLATILE(ioBase), 0x10000);
1411 +#endif
1412          ioBase = MAP_FAILED;
1413      }
1414  }
1415
1416
1417 [FILE:1280:patches/patch-hw_xfree86_os-support_meson.build]
1418 --- hw/xfree86/os-support/meson.build.orig      2023-12-13 01:31:04 UTC
1419 +++ hw/xfree86/os-support/meson.build
1420 @@ -91,11 +91,12 @@ elif host_machine.system() == 'sunos'
1421          error('Unknown CPU family for Solaris build')
1422      endif
1423  
1424 -elif host_machine.system().endswith('bsd')
1425 +elif host_machine.system().endswith('bsd') or host_machine.system() == 'dragonfly'
1426      srcs_xorg_os_support += [
1427          'bsd/bsd_VTsw.c',
1428          'bsd/bsd_bell.c',
1429          'bsd/bsd_init.c',
1430 +       'misc/SlowBcopy.c',
1431         'shared/pm_noop.c'
1432      ]
1433  
1434 @@ -120,14 +121,14 @@ elif host_machine.system().endswith('bsd
1435          srcs_xorg_os_support += 'shared/ioperm_noop.c'
1436      elif host_machine.cpu_family() == 'alpha'
1437          srcs_xorg_os_support += 'bsd/alpha_video.c'
1438 -        if host_machine.system() == 'freebsd'
1439 +        if host_machine.system() == 'freebsd' or host_machine.system() == 'midnightbsd'
1440              os_dep += cc.find_library('io')
1441          elif host_machine.system() == 'netbsd'
1442              os_c_args += '-DUSE_ALPHA_PIO'
1443          endif
1444      endif
1445  
1446 -    if host_machine.system() == 'freebsd'
1447 +    if ['freebsd', 'dragonfly', 'midnightbsd'].contains(host_machine.system())
1448          srcs_xorg_os_support += 'bsd/bsd_kmod.c'
1449      else
1450          srcs_xorg_os_support += 'shared/kmod_noop.c'
1451
1452
1453 [FILE:714:patches/patch-hw_xfree86_os-support_solaris_sun__init.c]
1454 --- hw/xfree86/os-support/solaris/sun_init.c.orig       2023-12-13 01:31:04 UTC
1455 +++ hw/xfree86/os-support/solaris/sun_init.c
1456 @@ -54,6 +54,22 @@ static int xf86StartVT = -1;
1457  static int vtEnabled = 0;
1458  #endif
1459  
1460 +#ifdef __sun__
1461 +#define VTIOC          ('V'<<8)
1462 +#define VT_OPENQRY     (VTIOC|1)
1463 +#define VT_SETMODE     (VTIOC|2)
1464 +#define VT_GETMODE     (VTIOC|3)
1465 +#define VT_ACTIVATE    (VTIOC|5)
1466 +#define VT_WAITACTIVE  (VTIOC|6)
1467 +#define VT_GETSTATE    (VTIOC|100)
1468 +#define VT_ENABLED     (VTIOC|101)
1469 +#define VT_SETDISPINFO (VTIOC|103)
1470 +#define VT_GET_CONSUSER        (VTIOC|108)
1471 +#define VT_SET_CONSUSER        (VTIOC|109)
1472 +
1473 +enum { VT_AUTO = 0, VT_PROCESS };
1474 +#endif
1475 +
1476  /* Device to open as xf86Info.consoleFd */
1477  static char consoleDev[PATH_MAX] = "/dev/fb";
1478  
1479
1480
1481 [FILE:520:patches/patch-hw_xfree86_os-support_xf86__OSlib.h]
1482 --- hw/xfree86/os-support/xf86_OSlib.h.orig     2023-12-13 01:31:04 UTC
1483 +++ hw/xfree86/os-support/xf86_OSlib.h
1484 @@ -241,7 +241,7 @@ extern _X_HIDDEN char xf86SolarisFbDev[P
1485  #ifdef SYSCONS_SUPPORT
1486  #define COMPAT_SYSCONS
1487  #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
1488 -#if defined(__DragonFly__)  || (__FreeBSD_kernel_version >= 410000)
1489 +#if defined(__DragonFly__)  || (__FreeBSD_kernel_version >= 410000) || defined(__MidnightBSD__)
1490  #include <sys/consio.h>
1491  #include <sys/kbio.h>
1492  #else
1493
1494
1495 [FILE:1986:patches/patch-hw_xfree86_xorg-wrapper.c]
1496 * Skip the detection of root rights requirement, the assumption that presence
1497 * of KMS drivers removes the root requirement is only valid for Linux
1498
1499 --- hw/xfree86/xorg-wrapper.c.orig      2023-12-13 01:31:04 UTC
1500 +++ hw/xfree86/xorg-wrapper.c
1501 @@ -39,7 +39,7 @@
1502  #include <sys/sysmacros.h>
1503  #endif
1504  #include <sys/types.h>
1505 -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
1506 +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
1507  #include <sys/consio.h>
1508  #endif
1509  #include <unistd.h>
1510 @@ -170,7 +170,7 @@ static int on_console(int fd)
1511      r = fstat(fd, &st);
1512      if (r == 0 && S_ISCHR(st.st_mode) && major(st.st_rdev) == 4)
1513        return 1;
1514 -#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
1515 +#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
1516      int idx;
1517  
1518      if (ioctl(fd, VT_GETINDEX, &idx) != -1)
1519 @@ -191,7 +191,7 @@ static int on_console(int fd)
1520  
1521  int main(int argc, char *argv[])
1522  {
1523 -#ifdef WITH_LIBDRM
1524 +#if defined(WITH_LIBDRM) && defined(__linux__)
1525      struct drm_mode_card_res res;
1526  #endif
1527      char buf[PATH_MAX];
1528 @@ -230,7 +230,7 @@ int main(int argc, char *argv[])
1529          }
1530      }
1531  
1532 -#ifdef WITH_LIBDRM
1533 +#if defined(WITH_LIBDRM) && defined(__linux__)
1534      /* Detect if we need root rights, except when overridden by the config */
1535      if (needs_root_rights == -1) {
1536          for (i = 0; i < 16; i++) {
1537 @@ -256,6 +256,8 @@ int main(int argc, char *argv[])
1538          gid_t realgid = getgid();
1539          uid_t realuid = getuid();
1540  
1541 +#if !defined(__NetBSD__)
1542 +       /* setresgid and setresuid are not implemented on NetBSD */
1543          if (setresgid(-1, realgid, realgid) != 0) {
1544              fprintf(stderr, "%s: Could not drop setgid privileges: %s\n",
1545                  progname, strerror(errno));
1546 @@ -266,6 +268,7 @@ int main(int argc, char *argv[])
1547                  progname, strerror(errno));
1548              exit(1);
1549          }
1550 +#endif
1551      }
1552  
1553      snprintf(buf, sizeof(buf), "%s/Xorg", SUID_WRAPPER_DIR);
1554
1555
1556 [FILE:1214:patches/patch-include_meson.build]
1557 --- include/meson.build.orig    2023-12-13 01:31:04 UTC
1558 +++ include/meson.build
1559 @@ -278,7 +278,7 @@ supports_syscons = false
1560  supports_wscons = false
1561  csrg_based = false
1562  
1563 -if host_machine.system() == 'freebsd' or host_machine.system() == 'dragonfly'
1564 +if ['freebsd', 'dragonfly', 'midnightbsd'].contains(host_machine.system())
1565    supports_pccons = true
1566    supports_pcvt = true
1567    supports_syscons = true
1568 @@ -377,13 +377,13 @@ xorg_data.set('HAVE_STROPTS_H', cc.has_h
1569  xorg_data.set('HAVE_SYS_KD_H', cc.has_header('sys/kd.h') ? '1' : false)
1570  xorg_data.set('HAVE_SYS_VT_H', cc.has_header('sys/vt.h') ? '1' : false)
1571  
1572 -if host_machine.system() == 'freebsd' or host_machine.system() == 'dragonfly'
1573 +if ['freebsd', 'dragonfly', 'midnightbsd'].contains(host_machine.system())
1574      if host_machine.cpu_family() == 'x86' or host_machine.cpu_family() == 'x86_64'
1575          xorg_data.set('USE_DEV_IO', '1')
1576      endif
1577  elif host_machine.system() == 'netbsd'
1578      if host_machine.cpu_family() == 'x86' or host_machine.cpu_family() == 'x86_64'
1579 -        xorg_data.set('USE_I386_IOPL', '1')
1580 +        xorg_data.set('USE_AMD64_IOPL', '1')
1581      endif
1582  elif host_machine.system() == 'openbsd'
1583      if host_machine.cpu_family() == 'x86'
1584
1585
1586 [FILE:193:patches/patch-os_backtrace.c]
1587 --- os/backtrace.c.orig 2023-12-13 01:31:04 UTC
1588 +++ os/backtrace.c
1589 @@ -29,6 +29,7 @@
1590  #include "misc.h"
1591  #include <errno.h>
1592  #include <string.h>
1593 +#include <unistd.h>
1594  
1595  #ifdef HAVE_LIBUNWIND
1596  
1597
1598
1599 [FILE:1021:patches/patch-test_simple-xinit.c]
1600 --- test/simple-xinit.c.orig    2023-12-13 01:31:04 UTC
1601 +++ test/simple-xinit.c
1602 @@ -34,6 +34,47 @@
1603  #include <sys/wait.h>
1604  #include <unistd.h>
1605  
1606 +#ifdef __sun__
1607 +#include <sys/varargs.h>
1608 +static int
1609 +vasprintf(char **strp, const char *fmt, va_list args)
1610 +{
1611 +    va_list args_copy;
1612 +    int status, needed;
1613 +
1614 +    va_copy(args_copy, args);
1615 +    needed = vsnprintf(NULL, 0, fmt, args_copy);
1616 +    va_end(args_copy);
1617 +    if (needed < 0) {
1618 +        *strp = NULL;
1619 +        return needed;
1620 +    }
1621 +    *strp = malloc(needed + 1);
1622 +    if (*strp == NULL)
1623 +        return -1;
1624 +    status = vsnprintf(*strp, needed + 1, fmt, args);
1625 +    if (status >= 0)
1626 +        return status;
1627 +    else {
1628 +        free(*strp);
1629 +        *strp = NULL;
1630 +        return status;
1631 +    }
1632 +}
1633 +
1634 +static int
1635 +asprintf(char **strp, const char *fmt, ...)
1636 +{
1637 +    va_list args;
1638 +    int status;
1639 +
1640 +    va_start(args, fmt);
1641 +    status = vasprintf(strp, fmt, args);
1642 +    va_end(args);
1643 +    return status;
1644 +}
1645 +#endif
1646 +
1647  static void
1648  kill_server(int server_pid)
1649  {
1650
1651
1652 [FILE:152:files/20-evdev-kbd.conf]
1653 Section "InputClass"
1654         Identifier              "Evdev keyboard"
1655         MatchDevicePath         "/dev/input/event*"
1656         MatchIsKeyboard         "on"
1657         Option                  "XkbRules" "evdev"
1658 EndSection
1659
1660
1661 [FILE:251:files/special.mk]
1662 sharefonts=     ${LOCALBASE}/share/fonts
1663 fontpathd=      ${PREFIX}/etc/X11/fontpath.d
1664
1665 fontlist=       ${sharefonts}/misc \
1666                 ${sharefonts}/TTF \
1667                 ${sharefonts}/OTF \
1668                 ${sharefonts}/Type1 \
1669                 ${sharefonts}/100dpi \
1670                 ${sharefonts}/75dpi \
1671                 catalogue:${fontpathd}
1672