3 * Copyright (c) 2002-2012 Apple Inc. All rights reserved.
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation files
7 * (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
20 * HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
25 * Except as contained in this notice, the name(s) of the above
26 * copyright holders shall not be used in advertising or otherwise to
27 * promote the sale, use or other dealings in this Software without
28 * prior written authorization.
32 #import "x-selection.h"
35 #include <unistd.h> /*for getpid*/
36 #include <Cocoa/Cocoa.h>
38 static const char *app_prefs_domain = BUNDLE_ID_PREFIX ".xpbproxy";
39 CFStringRef app_prefs_domain_cfstr;
43 BOOL serverRunning = YES;
44 pthread_mutex_t serverRunningMutex = PTHREAD_MUTEX_INITIALIZER;
45 pthread_cond_t serverRunningCond = PTHREAD_COND_INITIALIZER;
48 signal_handler(int sig)
52 xpbproxy_prefs_reload = YES;
61 ErrorF(const char * f, ...)
66 vfprintf(stderr, f, args);
70 /* TODO: Have this actually log to ASL */
72 xq_asl_log(int level, const char *subsystem, const char *file,
73 const char *function, int line, const char *fmt,
80 vfprintf(stderr, fmt, args);
86 main(int argc, const char *argv[])
92 ErrorF("pid: %u\n", getpid());
95 xpbproxy_is_standalone = YES;
97 if ((s = getenv("X11_PREFS_DOMAIN")))
100 for (i = 1; i < argc; i++) {
101 if (strcmp(argv[i], "--prefs-domain") == 0 && i + 1 < argc) {
102 app_prefs_domain = argv[++i];
104 else if (strcmp(argv[i], "--help") == 0) {
106 "usage: xpbproxy OPTIONS\n"
107 "Pasteboard proxying for X11.\n\n"
108 "--prefs-domain <domain> Change the domain used for reading preferences\n"
114 ErrorF("usage: xpbproxy OPTIONS...\n"
115 "Try 'xpbproxy --help' for more information.\n");
120 app_prefs_domain_cfstr = CFStringCreateWithCString(NULL, app_prefs_domain,
121 kCFStringEncodingUTF8);
123 signal(SIGINT, signal_handler);
124 signal(SIGTERM, signal_handler);
125 signal(SIGHUP, signal_handler);
126 signal(SIGPIPE, SIG_IGN);
128 return xpbproxy_run();