quartzStartup.c revision 4642e01f
14642e01fSmrg/************************************************************** 24642e01fSmrg * 34642e01fSmrg * Startup code for the Quartz Darwin X Server 44642e01fSmrg * 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 "quartzAudio.h" 444642e01fSmrg#include "quartz.h" 454642e01fSmrg#include "opaque.h" 464642e01fSmrg#include "micmap.h" 474642e01fSmrg 484642e01fSmrg#include <assert.h> 494642e01fSmrg 504642e01fSmrg#include <pthread.h> 514642e01fSmrg 524642e01fSmrgint dix_main(int argc, char **argv, char **envp); 534642e01fSmrg 544642e01fSmrgstruct arg { 554642e01fSmrg int argc; 564642e01fSmrg char **argv; 574642e01fSmrg char **envp; 584642e01fSmrg}; 594642e01fSmrg 604642e01fSmrgstatic void server_thread (void *arg) { 614642e01fSmrg struct arg args = *((struct arg *)arg); 624642e01fSmrg free(arg); 634642e01fSmrg exit (dix_main(args.argc, args.argv, args.envp)); 644642e01fSmrg} 654642e01fSmrg 664642e01fSmrgstatic pthread_t create_thread (void *func, void *arg) { 674642e01fSmrg pthread_attr_t attr; 684642e01fSmrg pthread_t tid; 694642e01fSmrg 704642e01fSmrg pthread_attr_init (&attr); 714642e01fSmrg pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM); 724642e01fSmrg pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); 734642e01fSmrg pthread_create (&tid, &attr, func, arg); 744642e01fSmrg pthread_attr_destroy (&attr); 754642e01fSmrg 764642e01fSmrg return tid; 774642e01fSmrg} 784642e01fSmrg 794642e01fSmrgvoid QuartzInitServer(int argc, char **argv, char **envp) { 804642e01fSmrg struct arg *args = (struct arg*)malloc(sizeof(struct arg)); 814642e01fSmrg if(!args) 824642e01fSmrg FatalError("Could not allocate memory.\n"); 834642e01fSmrg 844642e01fSmrg args->argc = argc; 854642e01fSmrg args->argv = argv; 864642e01fSmrg args->envp = envp; 874642e01fSmrg 884642e01fSmrg APPKIT_THREAD_ID = pthread_self(); 894642e01fSmrg SERVER_THREAD_ID = create_thread(server_thread, args); 904642e01fSmrg 914642e01fSmrg if (!SERVER_THREAD_ID) { 924642e01fSmrg FatalError("can't create secondary thread\n"); 934642e01fSmrg } 944642e01fSmrg} 954642e01fSmrg 964642e01fSmrgint server_main(int argc, char **argv, char **envp) { 974642e01fSmrg int i; 984642e01fSmrg int fd[2]; 994642e01fSmrg 1004642e01fSmrg /* Unset CFProcessPath, so our children don't inherit this kludge we need 1014642e01fSmrg * to load our nib. If an xterm gets this set, then it fails to 1024642e01fSmrg * 'open hi.txt' properly. 1034642e01fSmrg */ 1044642e01fSmrg unsetenv("CFProcessPath"); 1054642e01fSmrg 1064642e01fSmrg // Make a pipe to pass events 1074642e01fSmrg assert( pipe(fd) == 0 ); 1084642e01fSmrg darwinEventReadFD = fd[0]; 1094642e01fSmrg darwinEventWriteFD = fd[1]; 1104642e01fSmrg fcntl(darwinEventReadFD, F_SETFL, O_NONBLOCK); 1114642e01fSmrg 1124642e01fSmrg for (i = 1; i < argc; i++) { 1134642e01fSmrg // Display version info without starting Mac OS X UI if requested 1144642e01fSmrg if (!strcmp( argv[i], "-showconfig" ) || !strcmp( argv[i], "-version" )) { 1154642e01fSmrg DarwinPrintBanner(); 1164642e01fSmrg exit(0); 1174642e01fSmrg } 1184642e01fSmrg } 1194642e01fSmrg 1204642e01fSmrg /* Create the audio mutex */ 1214642e01fSmrg QuartzAudioInit(); 1224642e01fSmrg 1234642e01fSmrg X11ControllerMain(argc, argv, envp); 1244642e01fSmrg exit(0); 1254642e01fSmrg} 126