quartzStartup.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /**************************************************************
  2. *
  3. * Startup code for the Quartz Darwin X Server
  4. * Copyright (c) 2008-2012 Apple Inc. All rights reserved.
  5. * Copyright (c) 2001-2004 Torrey T. Lyons. All Rights Reserved.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation
  10. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. * and/or sell copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  20. * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  21. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  22. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. *
  25. * Except as contained in this notice, the name(s) of the above copyright
  26. * holders shall not be used in advertising or otherwise to promote the sale,
  27. * use or other dealings in this Software without prior written authorization.
  28. */
  29. #include "sanitizedCarbon.h"
  30. #ifdef HAVE_DIX_CONFIG_H
  31. #include <dix-config.h>
  32. #endif
  33. #include <fcntl.h>
  34. #include <unistd.h>
  35. #include <CoreFoundation/CoreFoundation.h>
  36. #include "quartzCommon.h"
  37. #include "X11Controller.h"
  38. #include "darwin.h"
  39. #include "darwinEvents.h"
  40. #include "quartz.h"
  41. #include "opaque.h"
  42. #include "micmap.h"
  43. #include <assert.h>
  44. #include <pthread.h>
  45. int
  46. dix_main(int argc, char **argv, char **envp);
  47. struct arg {
  48. int argc;
  49. char **argv;
  50. char **envp;
  51. };
  52. _X_NORETURN
  53. static void
  54. server_thread(void *arg)
  55. {
  56. struct arg args = *((struct arg *)arg);
  57. free(arg);
  58. exit(dix_main(args.argc, args.argv, args.envp));
  59. }
  60. static pthread_t
  61. create_thread(void *func, void *arg)
  62. {
  63. pthread_attr_t attr;
  64. pthread_t tid;
  65. pthread_attr_init(&attr);
  66. pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
  67. pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
  68. pthread_create(&tid, &attr, func, arg);
  69. pthread_attr_destroy(&attr);
  70. return tid;
  71. }
  72. void
  73. QuartzInitServer(int argc, char **argv, char **envp)
  74. {
  75. struct arg *args = (struct arg *)malloc(sizeof(struct arg));
  76. if (!args)
  77. FatalError("Could not allocate memory.\n");
  78. args->argc = argc;
  79. args->argv = argv;
  80. args->envp = envp;
  81. if (!create_thread(server_thread, args)) {
  82. FatalError("can't create secondary thread\n");
  83. }
  84. }
  85. int
  86. server_main(int argc, char **argv, char **envp)
  87. {
  88. int i;
  89. int fd[2];
  90. /* Unset CFProcessPath, so our children don't inherit this kludge we need
  91. * to load our nib. If an xterm gets this set, then it fails to
  92. * 'open hi.txt' properly.
  93. */
  94. unsetenv("CFProcessPath");
  95. // Make a pipe to pass events
  96. assert(pipe(fd) == 0);
  97. darwinEventReadFD = fd[0];
  98. darwinEventWriteFD = fd[1];
  99. fcntl(darwinEventReadFD, F_SETFL, O_NONBLOCK);
  100. for (i = 1; i < argc; i++) {
  101. // Display version info without starting Mac OS X UI if requested
  102. if (!strcmp(argv[i],
  103. "-showconfig") || !strcmp(argv[i], "-version")) {
  104. DarwinPrintBanner();
  105. exit(0);
  106. }
  107. }
  108. X11ControllerMain(argc, argv, envp);
  109. exit(0);
  110. }