core: Make Kernel D-Bus setup optional

This commit is contained in:
Marcel Holtmann 2014-08-09 10:59:48 -07:00
parent ebeeb143cb
commit 70bc082d41
1 changed files with 30 additions and 17 deletions

View File

@ -52,11 +52,13 @@ static void usage(void)
printf("\tiwd [options]\n"); printf("\tiwd [options]\n");
printf("Options:\n" printf("Options:\n"
"\t-S, --ssid <ssid> SSID of network\n" "\t-S, --ssid <ssid> SSID of network\n"
"\t-K, --kdbus Setup Kernel D-Bus\n"
"\t-h, --help Show help options\n"); "\t-h, --help Show help options\n");
} }
static const struct option main_options[] = { static const struct option main_options[] = {
{ "ssid", required_argument, NULL, 'S' }, { "ssid", required_argument, NULL, 'S' },
{ "kdbus", no_argument, NULL, 'K' },
{ "version", no_argument, NULL, 'v' }, { "version", no_argument, NULL, 'v' },
{ "help", no_argument, NULL, 'h' }, { "help", no_argument, NULL, 'h' },
{ } { }
@ -64,9 +66,9 @@ static const struct option main_options[] = {
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
bool enable_kdbus = false;
struct l_signal *signal; struct l_signal *signal;
sigset_t mask; sigset_t mask;
char *bus_name;
int exit_status; int exit_status;
for (;;) { for (;;) {
@ -80,6 +82,9 @@ int main(int argc, char *argv[])
case 'S': case 'S':
wiphy_set_ssid(optarg); wiphy_set_ssid(optarg);
break; break;
case 'K':
enable_kdbus = true;
break;
case 'v': case 'v':
printf("%s\n", VERSION); printf("%s\n", VERSION);
return EXIT_SUCCESS; return EXIT_SUCCESS;
@ -107,22 +112,31 @@ int main(int argc, char *argv[])
l_info("Wireless daemon version %s", VERSION); l_info("Wireless daemon version %s", VERSION);
if (!kdbus_create_bus()) { if (enable_kdbus) {
exit_status = EXIT_FAILURE; char *bus_name;
goto done; bool result;
}
bus_name = kdbus_lookup_bus(); if (!kdbus_create_bus()) {
if (!bus_name) { exit_status = EXIT_FAILURE;
exit_status = EXIT_FAILURE; goto done;
goto destroy; }
}
l_debug("Bus location: %s", bus_name); bus_name = kdbus_lookup_bus();
if (!bus_name) {
exit_status = EXIT_FAILURE;
goto destroy;
}
if (!kdbus_open_bus(bus_name, "net.connman.iwd", "iwd")) { l_debug("Bus location: %s", bus_name);
exit_status = EXIT_FAILURE;
goto destroy; result = kdbus_open_bus(bus_name, "net.connman.iwd", "iwd");
l_free(bus_name);
if (!result) {
exit_status = EXIT_FAILURE;
goto destroy;
}
} }
if (!netdev_init()) { if (!netdev_init()) {
@ -144,9 +158,8 @@ int main(int argc, char *argv[])
exit_status = EXIT_SUCCESS; exit_status = EXIT_SUCCESS;
destroy: destroy:
l_free(bus_name); if (enable_kdbus)
kdbus_destroy_bus();
kdbus_destroy_bus();
done: done:
l_signal_remove(signal); l_signal_remove(signal);