2008-09-30 21:04:35 +02:00
|
|
|
/* app-main.m
|
2008-11-17 02:57:46 +01:00
|
|
|
Copyright (c) 2002, 2008 Apple Computer, Inc. All rights reserved.
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person
|
|
|
|
obtaining a copy of this software and associated documentation files
|
|
|
|
(the "Software"), to deal in the Software without restriction,
|
|
|
|
including without limitation the rights to use, copy, modify, merge,
|
|
|
|
publish, distribute, sublicense, and/or sell copies of the Software,
|
|
|
|
and to permit persons to whom the Software is furnished to do so,
|
|
|
|
subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be
|
|
|
|
included in all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
|
|
|
|
HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
|
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
Except as contained in this notice, the name(s) of the above
|
|
|
|
copyright holders shall not be used in advertising or otherwise to
|
|
|
|
promote the sale, use or other dealings in this Software without
|
|
|
|
prior written authorization.
|
|
|
|
*/
|
2008-09-28 00:30:10 +02:00
|
|
|
|
|
|
|
#include "pbproxy.h"
|
|
|
|
#import "x-selection.h"
|
|
|
|
|
|
|
|
#include <pthread.h>
|
2012-03-21 20:55:09 +01:00
|
|
|
#include <unistd.h> /*for getpid */
|
2008-10-01 07:53:12 +02:00
|
|
|
#include <Cocoa/Cocoa.h>
|
2008-09-28 00:30:10 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
static const char *app_prefs_domain = BUNDLE_ID_PREFIX ".xpbproxy";
|
2008-11-25 09:15:53 +01:00
|
|
|
CFStringRef app_prefs_domain_cfstr;
|
|
|
|
|
2009-10-28 01:16:57 +01:00
|
|
|
/* Stubs */
|
2008-11-25 09:51:01 +01:00
|
|
|
char *display = NULL;
|
2011-05-15 01:11:32 +02:00
|
|
|
BOOL serverRunning = YES;
|
|
|
|
pthread_mutex_t serverRunningMutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
pthread_cond_t serverRunningCond = PTHREAD_COND_INITIALIZER;
|
2008-11-25 09:51:01 +01:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
static void
|
|
|
|
signal_handler(int sig)
|
|
|
|
{
|
|
|
|
switch (sig) {
|
|
|
|
case SIGHUP:
|
|
|
|
xpbproxy_prefs_reload = YES;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
_exit(EXIT_SUCCESS);
|
2008-10-21 20:19:06 +02:00
|
|
|
}
|
2008-09-28 00:30:10 +02:00
|
|
|
}
|
|
|
|
|
2011-04-26 07:00:41 +02:00
|
|
|
void
|
2012-03-21 20:55:09 +01:00
|
|
|
ErrorF(const char *f, ...)
|
2011-04-26 07:00:41 +02:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, f);
|
|
|
|
vfprintf(stderr, f, args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
2011-06-02 06:18:03 +02:00
|
|
|
/* TODO: Have this actually log to ASL */
|
2012-03-21 20:55:09 +01:00
|
|
|
void
|
|
|
|
xq_asl_log(int level, const char *subsystem, const char *file,
|
|
|
|
const char *function, int line, const char *fmt, ...)
|
|
|
|
{
|
2011-06-02 06:18:03 +02:00
|
|
|
#ifdef DEBUG
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
vfprintf(stderr, fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
int
|
|
|
|
main(int argc, const char *argv[])
|
|
|
|
{
|
2009-05-06 05:27:53 +02:00
|
|
|
const char *s;
|
|
|
|
int i;
|
|
|
|
|
2008-11-16 04:52:34 +01:00
|
|
|
#ifdef DEBUG
|
2011-04-26 07:00:41 +02:00
|
|
|
ErrorF("pid: %u\n", getpid());
|
2008-10-05 03:54:15 +02:00
|
|
|
#endif
|
|
|
|
|
2008-11-16 04:52:34 +01:00
|
|
|
xpbproxy_is_standalone = YES;
|
2008-11-25 09:15:53 +01:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
if ((s = getenv("X11_PREFS_DOMAIN")))
|
2008-11-25 09:15:53 +01:00
|
|
|
app_prefs_domain = s;
|
|
|
|
|
|
|
|
for (i = 1; i < argc; i++) {
|
2012-03-21 20:55:09 +01:00
|
|
|
if (strcmp(argv[i], "--prefs-domain") == 0 && i + 1 < argc) {
|
2008-11-25 09:15:53 +01:00
|
|
|
app_prefs_domain = argv[++i];
|
2012-03-21 20:55:09 +01:00
|
|
|
}
|
|
|
|
else if (strcmp(argv[i], "--help") == 0) {
|
2011-04-26 07:00:41 +02:00
|
|
|
ErrorF("usage: xpbproxy OPTIONS\n"
|
2008-11-25 09:15:53 +01:00
|
|
|
"Pasteboard proxying for X11.\n\n"
|
|
|
|
"--prefs-domain <domain> Change the domain used for reading preferences\n"
|
2012-03-21 20:55:09 +01:00
|
|
|
" (default: %s)\n",
|
|
|
|
app_prefs_domain);
|
2008-11-25 09:15:53 +01:00
|
|
|
return 0;
|
2012-03-21 20:55:09 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-04-26 07:00:41 +02:00
|
|
|
ErrorF("usage: xpbproxy OPTIONS...\n"
|
2012-03-21 20:55:09 +01:00
|
|
|
"Try 'xpbproxy --help' for more information.\n");
|
2008-11-25 09:15:53 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2012-03-21 20:55:09 +01:00
|
|
|
|
|
|
|
app_prefs_domain_cfstr =
|
|
|
|
CFStringCreateWithCString(NULL, app_prefs_domain,
|
|
|
|
kCFStringEncodingUTF8);
|
|
|
|
|
|
|
|
signal(SIGINT, signal_handler);
|
|
|
|
signal(SIGTERM, signal_handler);
|
|
|
|
signal(SIGHUP, signal_handler);
|
|
|
|
signal(SIGPIPE, SIG_IGN);
|
2008-10-01 07:53:12 +02:00
|
|
|
|
2010-03-20 11:28:57 +01:00
|
|
|
return xpbproxy_run();
|
2008-09-28 00:30:10 +02:00
|
|
|
}
|