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