- DBusError err;
- int events, error;
- GIOChannel *gchan;
- main_loop = g_main_loop_new(NULL, FALSE);
-
- dbus_error_init(&err);
-
- connection = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, &err);
-
- if (dbus_error_is_set(&err)) {
- fprintf(stderr, "Connection Error: %s\n", err.message);
- dbus_error_free(&err);
- }
-
- if (connection == NULL) {
- fprintf(stderr, "Could not connect to system bus...exiting\n");
- exit(EXIT_FAILURE);
- }
-
- if (argc < 2)
- show_interactive(connection, main_loop);
-
- error = commands(connection, argv + 1, argc -1);
-
- if (error == -1) {
- char *help = "help";
-
- printf("Usage: connmanctl [[command] [args]]\n");
- commands(connection, &help, 1);
- printf("\nNote: arguments and output are considered "
- "EXPERIMENTAL for now.\n\n");
- return -EINVAL;
- }
-
- if (error < 0)
- return error;
-
- gchan = g_io_channel_unix_new(fileno(stdin));
- events = G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL;
- g_io_add_watch(gchan, events, readmonitor, NULL);
- rl_callback_handler_install("", rl_handler);
-
- if (strcmp(argv[1], "monitor") != 0)
- g_timeout_add_full(G_PRIORITY_DEFAULT, 100, timeout_wait,
- main_loop, NULL);
- g_main_loop_run(main_loop);
- rl_callback_handler_remove();
- g_io_channel_unref(gchan);
- if (main_loop != NULL)
- g_main_loop_unref(main_loop);
- return 0;