1c81d8f5eSmrg/* Copyright (c) 2008 Apple Inc. 2c81d8f5eSmrg * 3c81d8f5eSmrg * Permission is hereby granted, free of charge, to any person 4c81d8f5eSmrg * obtaining a copy of this software and associated documentation files 5c81d8f5eSmrg * (the "Software"), to deal in the Software without restriction, 6c81d8f5eSmrg * including without limitation the rights to use, copy, modify, merge, 7c81d8f5eSmrg * publish, distribute, sublicense, and/or sell copies of the Software, 8c81d8f5eSmrg * and to permit persons to whom the Software is furnished to do so, 9c81d8f5eSmrg * subject to the following conditions: 10c81d8f5eSmrg * 11c81d8f5eSmrg * The above copyright notice and this permission notice shall be 12c81d8f5eSmrg * included in all copies or substantial portions of the Software. 13c81d8f5eSmrg * 14c81d8f5eSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15c81d8f5eSmrg * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16c81d8f5eSmrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17c81d8f5eSmrg * NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT 18c81d8f5eSmrg * HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19c81d8f5eSmrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20c81d8f5eSmrg * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21c81d8f5eSmrg * DEALINGS IN THE SOFTWARE. 22c81d8f5eSmrg * 23c81d8f5eSmrg * Except as contained in this notice, the name(s) of the above 24c81d8f5eSmrg * copyright holders shall not be used in advertising or otherwise to 25c81d8f5eSmrg * promote the sale, use or other dealings in this Software without 26c81d8f5eSmrg * prior written authorization. 27c81d8f5eSmrg */ 28c81d8f5eSmrg 29c81d8f5eSmrg#ifdef HAVE_CONFIG_H 30c81d8f5eSmrg# include "config.h" 31c81d8f5eSmrg#endif 32c81d8f5eSmrg 33c81d8f5eSmrg#include <string.h> 34c81d8f5eSmrg#include <stdio.h> 35c81d8f5eSmrg 36c81d8f5eSmrg#ifndef SCRIPTDIR 37c81d8f5eSmrg#define SCRIPTDIR="/usr/X11/lib/X11/xinit/privileged_startx.d" 38c81d8f5eSmrg#endif 39c81d8f5eSmrg 40c81d8f5eSmrgstatic void usage(const char *prog) { 41c81d8f5eSmrg fprintf(stderr, "%s: usage\n", prog); 42c81d8f5eSmrg fprintf(stderr, " %s [-d [<script dir>]]\n\n", prog); 43c81d8f5eSmrg fprintf(stderr, " -d: Passed when called from launchd to denote server-mode.\n"); 44c81d8f5eSmrg fprintf(stderr, " <script dir>: Directory to use instead of %s\n", SCRIPTDIR); 45c81d8f5eSmrg} 46c81d8f5eSmrg 47c81d8f5eSmrgint client_main(void); 48c81d8f5eSmrgint server_main(const char *dir); 49c81d8f5eSmrg 50c81d8f5eSmrgint main(int argc, char *argv[]) { 51c81d8f5eSmrg 52c81d8f5eSmrg if(argc == 1) { 53c81d8f5eSmrg return client_main(); 54c81d8f5eSmrg } else if(!strncmp(argv[1], "-d", 2)) { 55c81d8f5eSmrg if(argc == 2) 56c81d8f5eSmrg return server_main(NULL); 57c81d8f5eSmrg else if(argc == 3) 58c81d8f5eSmrg return server_main(argv[2]); 59c81d8f5eSmrg } 60c81d8f5eSmrg 61c81d8f5eSmrg usage(argv[0]); 62c81d8f5eSmrg return 1; 63c81d8f5eSmrg} 64