430
432
static GMainLoop *event_loop = NULL;
434
static gboolean option_debug = FALSE;
435
static gboolean option_stderr = FALSE;
437
static GOptionEntry options[] = {
438
{ "debug", 'd', 0, G_OPTION_ARG_NONE, &option_debug,
439
"Enable debug information output" },
440
{ "stderr", 's', 0, G_OPTION_ARG_NONE, &option_stderr,
441
"Write log information to stderr" },
432
445
static void sig_term(int sig)
434
447
g_main_loop_quit(event_loop);
437
450
int main(int argc, char *argv[])
452
GOptionContext *context;
439
453
struct sigaction sa;
440
454
DBusConnection *conn;
443
dbus_error_init(&err);
445
conn = g_dbus_setup_bus(DBUS_BUS_SESSION, CLIENT_SERVICE, &err);
447
if (dbus_error_is_set(&err) == TRUE) {
448
fprintf(stderr, "%s\n", err.message);
449
dbus_error_free(&err);
451
fprintf(stderr, "Can't register with session bus\n");
459
context = g_option_context_new(NULL);
460
g_option_context_add_main_entries(context, options, NULL);
462
g_option_context_parse(context, &argc, &argv, &gerr);
464
g_printerr("%s\n", gerr->message);
469
g_option_context_free(context);
471
dbus_error_init(&derr);
473
conn = g_dbus_setup_bus(DBUS_BUS_SESSION, CLIENT_SERVICE, &derr);
474
if (dbus_error_is_set(&derr) == TRUE) {
475
g_printerr("%s: %s\n", derr.name, derr.message);
476
dbus_error_free(&derr);
452
477
exit(EXIT_FAILURE);
455
480
if (g_dbus_register_interface(conn, CLIENT_PATH, CLIENT_INTERFACE,
456
481
client_methods, NULL, NULL,
457
482
NULL, NULL) == FALSE) {
458
fprintf(stderr, "Can't register client interface\n");
483
g_printerr("Can't register client interface\n");
459
484
dbus_connection_unref(conn);
460
485
exit(EXIT_FAILURE);
463
488
event_loop = g_main_loop_new(NULL, FALSE);
490
log_option = LOG_NDELAY | LOG_PID;
492
if (option_stderr == TRUE)
493
log_option |= LOG_PERROR;
495
openlog("obex-client", log_option, LOG_DAEMON);
497
if (option_debug == TRUE) {
498
info("Enabling debug information");
465
502
memset(&sa, 0, sizeof(sa));
466
503
sa.sa_handler = sig_term;
467
504
sigaction(SIGINT, &sa, NULL);