quartzStartup.c revision 1b5d61b8
14642e01fSmrg/************************************************************** 24642e01fSmrg * 34642e01fSmrg * Startup code for the Quartz Darwin X Server 435c4bbdfSmrg * Copyright (c) 2008-2012 Apple Inc. All rights reserved. 54642e01fSmrg * Copyright (c) 2001-2004 Torrey T. Lyons. All Rights Reserved. 64642e01fSmrg * 74642e01fSmrg * Permission is hereby granted, free of charge, to any person obtaining a 84642e01fSmrg * copy of this software and associated documentation files (the "Software"), 94642e01fSmrg * to deal in the Software without restriction, including without limitation 104642e01fSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 114642e01fSmrg * and/or sell copies of the Software, and to permit persons to whom the 124642e01fSmrg * Software is furnished to do so, subject to the following conditions: 134642e01fSmrg * 144642e01fSmrg * The above copyright notice and this permission notice shall be included in 154642e01fSmrg * all copies or substantial portions of the Software. 164642e01fSmrg * 174642e01fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 184642e01fSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 194642e01fSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 204642e01fSmrg * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 214642e01fSmrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 224642e01fSmrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 234642e01fSmrg * DEALINGS IN THE SOFTWARE. 244642e01fSmrg * 254642e01fSmrg * Except as contained in this notice, the name(s) of the above copyright 264642e01fSmrg * holders shall not be used in advertising or otherwise to promote the sale, 274642e01fSmrg * use or other dealings in this Software without prior written authorization. 284642e01fSmrg */ 294642e01fSmrg 304642e01fSmrg#include "sanitizedCarbon.h" 314642e01fSmrg 324642e01fSmrg#ifdef HAVE_DIX_CONFIG_H 334642e01fSmrg#include <dix-config.h> 344642e01fSmrg#endif 354642e01fSmrg 364642e01fSmrg#include <fcntl.h> 374642e01fSmrg#include <unistd.h> 384642e01fSmrg#include <CoreFoundation/CoreFoundation.h> 394642e01fSmrg#include "quartzCommon.h" 404642e01fSmrg#include "X11Controller.h" 414642e01fSmrg#include "darwin.h" 424642e01fSmrg#include "darwinEvents.h" 434642e01fSmrg#include "quartz.h" 444642e01fSmrg#include "opaque.h" 454642e01fSmrg#include "micmap.h" 464642e01fSmrg 474642e01fSmrg#include <assert.h> 484642e01fSmrg 494642e01fSmrg#include <pthread.h> 504642e01fSmrg 5135c4bbdfSmrgint 5235c4bbdfSmrgdix_main(int argc, char **argv, char **envp); 534642e01fSmrg 544642e01fSmrgstruct arg { 554642e01fSmrg int argc; 564642e01fSmrg char **argv; 574642e01fSmrg char **envp; 584642e01fSmrg}; 594642e01fSmrg 6035c4bbdfSmrg_X_NORETURN 6135c4bbdfSmrgstatic void 6235c4bbdfSmrgserver_thread(void *arg) 6335c4bbdfSmrg{ 644642e01fSmrg struct arg args = *((struct arg *)arg); 654642e01fSmrg free(arg); 6635c4bbdfSmrg exit(dix_main(args.argc, args.argv, args.envp)); 674642e01fSmrg} 684642e01fSmrg 6935c4bbdfSmrgstatic pthread_t 7035c4bbdfSmrgcreate_thread(void *func, void *arg) 7135c4bbdfSmrg{ 724642e01fSmrg pthread_attr_t attr; 734642e01fSmrg pthread_t tid; 7435c4bbdfSmrg 7535c4bbdfSmrg pthread_attr_init(&attr); 7635c4bbdfSmrg pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); 7735c4bbdfSmrg pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); 7835c4bbdfSmrg pthread_create(&tid, &attr, func, arg); 7935c4bbdfSmrg pthread_attr_destroy(&attr); 8035c4bbdfSmrg 814642e01fSmrg return tid; 824642e01fSmrg} 834642e01fSmrg 8435c4bbdfSmrgvoid 8535c4bbdfSmrgQuartzInitServer(int argc, char **argv, char **envp) 8635c4bbdfSmrg{ 8735c4bbdfSmrg struct arg *args = (struct arg *)malloc(sizeof(struct arg)); 8835c4bbdfSmrg if (!args) 894642e01fSmrg FatalError("Could not allocate memory.\n"); 9035c4bbdfSmrg 914642e01fSmrg args->argc = argc; 924642e01fSmrg args->argv = argv; 934642e01fSmrg args->envp = envp; 944642e01fSmrg 9535c4bbdfSmrg if (!create_thread(server_thread, args)) { 964642e01fSmrg FatalError("can't create secondary thread\n"); 974642e01fSmrg } 981b5d61b8Smrg 991b5d61b8Smrg /* Block signals on the AppKit thread that the X11 expects to handle on its thread */ 1001b5d61b8Smrg sigset_t set; 1011b5d61b8Smrg sigemptyset(&set); 1021b5d61b8Smrg sigaddset(&set, SIGALRM); 1031b5d61b8Smrg#ifdef BUSFAULT 1041b5d61b8Smrg sigaddset(&set, SIGBUS); 1051b5d61b8Smrg#endif 1061b5d61b8Smrg pthread_sigmask(SIG_BLOCK, &set, NULL); 1074642e01fSmrg} 1084642e01fSmrg 10935c4bbdfSmrgint 11035c4bbdfSmrgserver_main(int argc, char **argv, char **envp) 11135c4bbdfSmrg{ 11235c4bbdfSmrg int i; 11335c4bbdfSmrg int fd[2]; 1144642e01fSmrg 1154642e01fSmrg /* Unset CFProcessPath, so our children don't inherit this kludge we need 1164642e01fSmrg * to load our nib. If an xterm gets this set, then it fails to 1174642e01fSmrg * 'open hi.txt' properly. 1184642e01fSmrg */ 1194642e01fSmrg unsetenv("CFProcessPath"); 12035c4bbdfSmrg 1214642e01fSmrg // Make a pipe to pass events 12235c4bbdfSmrg assert(pipe(fd) == 0); 1234642e01fSmrg darwinEventReadFD = fd[0]; 1244642e01fSmrg darwinEventWriteFD = fd[1]; 1254642e01fSmrg fcntl(darwinEventReadFD, F_SETFL, O_NONBLOCK); 1264642e01fSmrg 1274642e01fSmrg for (i = 1; i < argc; i++) { 1284642e01fSmrg // Display version info without starting Mac OS X UI if requested 12935c4bbdfSmrg if (!strcmp(argv[i], 13035c4bbdfSmrg "-showconfig") || !strcmp(argv[i], "-version")) { 1314642e01fSmrg DarwinPrintBanner(); 1324642e01fSmrg exit(0); 1334642e01fSmrg } 1344642e01fSmrg } 1354642e01fSmrg 1364642e01fSmrg X11ControllerMain(argc, argv, envp); 1374642e01fSmrg exit(0); 1384642e01fSmrg} 139