summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2008-04-14 01:50:19 +0200
committerMarcel Holtmann <marcel@holtmann.org>2008-04-14 01:50:19 +0200
commitf9f84ccfa0cd338e2de22878f277352436570b83 (patch)
tree5bc5e33c7352433028008e3c6cda83003371946b /src
parent4b4e384e215fa0479325629a9c26b9325a1dae91 (diff)
downloadconnman-f9f84ccfa0cd338e2de22878f277352436570b83.tar.gz
connman-f9f84ccfa0cd338e2de22878f277352436570b83.tar.bz2
connman-f9f84ccfa0cd338e2de22878f277352436570b83.zip
Use GLib option parsing
Diffstat (limited to 'src')
-rw-r--r--src/connman.h4
-rw-r--r--src/iface.c1
-rw-r--r--src/log.c8
-rw-r--r--src/main.c99
-rw-r--r--src/manager.c10
5 files changed, 52 insertions, 70 deletions
diff --git a/src/connman.h b/src/connman.h
index 66dd487b..866f9c9e 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -44,7 +44,7 @@
#define NM_INTERFACE NM_SERVICE
#define NM_DEVICE NM_SERVICE ".Devices"
-int __connman_manager_init(DBusConnection *conn, int compat);
+int __connman_manager_init(DBusConnection *conn, gboolean compat);
void __connman_manager_cleanup(void);
int __connman_agent_init(DBusConnection *conn);
@@ -55,7 +55,7 @@ int __connman_agent_unregister(const char *sender, const char *path);
#include <connman/log.h>
-int __connman_log_init(int detach, int debug);
+int __connman_log_init(gboolean detach, gboolean debug);
void __connman_log_cleanup(void);
#include <connman/plugin.h>
diff --git a/src/iface.c b/src/iface.c
index 51b8e017..b2fd6d10 100644
--- a/src/iface.c
+++ b/src/iface.c
@@ -1268,7 +1268,6 @@ static int probe_device(LibHalContext *ctx,
ifname = libhal_device_get_property_string(ctx, udi,
"net.interface", NULL);
if (ifname != NULL && ifname_filter != NULL &&
- *ifname_filter != '\0' &&
g_str_equal(ifname, ifname_filter) == FALSE) {
device_free(iface);
return -1;
diff --git a/src/log.c b/src/log.c
index 0b94fd60..93026d53 100644
--- a/src/log.c
+++ b/src/log.c
@@ -28,7 +28,7 @@
#include "connman.h"
-static volatile int debug_enabled = 0;
+static volatile gboolean debug_enabled = FALSE;
void connman_info(const char *format, ...)
{
@@ -56,7 +56,7 @@ void connman_debug(const char *format, ...)
{
va_list ap;
- if (!debug_enabled)
+ if (debug_enabled == FALSE)
return;
va_start(ap, format);
@@ -66,11 +66,11 @@ void connman_debug(const char *format, ...)
va_end(ap);
}
-int __connman_log_init(int detach, int debug)
+int __connman_log_init(gboolean detach, gboolean debug)
{
int option = LOG_NDELAY | LOG_PID;
- if (!detach)
+ if (detach == FALSE)
option |= LOG_PERROR;
openlog("connmand", option, LOG_DAEMON);
diff --git a/src/main.c b/src/main.c
index dc8439df..9bfb3bc1 100644
--- a/src/main.c
+++ b/src/main.c
@@ -43,66 +43,50 @@ static void sig_term(int sig)
g_main_loop_quit(main_loop);
}
-static void usage(void)
-{
- printf("Connection Manager version %s\n\n", VERSION);
-
- printf("Usage:\n"
- "\tconnmand [-i <interface>] [options]\n"
- "\n");
-
- printf("Options:\n"
- "\t-c, --compat Enable Network Manager compatibility\n"
- "\t-n, --nodaemon Don't fork daemon to background\n"
- "\t-h, --help Display help\n"
- "\n");
-}
-
-static struct option options[] = {
- { "interface", 1, 0, 'i' },
- { "nodaemon", 0, 0, 'n' },
- { "compat", 0, 0, 'c' },
- { "debug", 0, 0, 'd' },
- { "help", 0, 0, 'h' },
- { }
+static gchar *option_interface = NULL;
+static gboolean option_detach = TRUE;
+static gboolean option_compat = FALSE;
+static gboolean option_debug = FALSE;
+
+static GOptionEntry options[] = {
+ { "interface", 'i', 0, G_OPTION_ARG_STRING, &option_interface,
+ "Specify network interface", "IFACE" },
+ { "nodaemon", 'n', G_OPTION_FLAG_REVERSE,
+ G_OPTION_ARG_NONE, &option_detach,
+ "Don't fork daemon to background" },
+ { "compat", 'c', 0, G_OPTION_ARG_NONE, &option_compat,
+ "Enable Network Manager compatibility" },
+ { "debug", 'd', 0, G_OPTION_ARG_NONE, &option_debug,
+ "Enable debug information output" },
+ { NULL },
};
int main(int argc, char *argv[])
{
+ GOptionContext *context;
+ GError *error = NULL;
DBusConnection *conn;
DBusError err;
struct sigaction sa;
- char interface[IFNAMSIZ];
- int opt, detach = 1, compat = 0, debug = 0;
-
- memset(interface, 0, IFNAMSIZ);
-
- while ((opt = getopt_long(argc, argv, "+i:ncdh", options, NULL)) != EOF) {
- switch (opt) {
- case 'i':
- snprintf(interface, IFNAMSIZ, "%s", optarg);
- break;
- case 'n':
- detach = 0;
- break;
- case 'c':
- compat = 1;
- break;
- case 'd':
- debug = 1;
- break;
- case 'h':
- default:
- usage();
- exit(0);
- }
+
+ if (g_thread_supported() == FALSE)
+ g_thread_init(NULL);
+
+ context = g_option_context_new(NULL);
+ g_option_context_add_main_entries(context, options, NULL);
+
+ if (g_option_context_parse(context, &argc, &argv, &error) == FALSE) {
+ if (error != NULL) {
+ g_printerr("%s\n", error->message);
+ g_error_free(error);
+ } else
+ g_printerr("An unknown error occurred\n");
+ exit(1);
}
- argc -= optind;
- argv += optind;
- optind = 0;
+ g_option_context_free(context);
- if (detach) {
+ if (option_detach == TRUE) {
if (daemon(0, 0)) {
perror("Can't start daemon");
exit(1);
@@ -115,9 +99,6 @@ int main(int argc, char *argv[])
mkdir(STORAGEDIR, S_IRUSR | S_IWUSR | S_IXUSR |
S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
- if (g_thread_supported() == FALSE)
- g_thread_init(NULL);
-
main_loop = g_main_loop_new(NULL, FALSE);
if (dbus_threads_init_default() == FALSE) {
@@ -137,18 +118,18 @@ int main(int argc, char *argv[])
exit(1);
}
- if (compat) {
+ if (option_compat == TRUE) {
if (g_dbus_request_name(conn, NM_SERVICE, NULL) == FALSE) {
fprintf(stderr, "Can't register compat service\n");
- compat = 0;
+ option_compat = FALSE;
}
}
- __connman_log_init(detach, debug);
+ __connman_log_init(option_detach, option_debug);
__connman_agent_init(conn);
- __connman_manager_init(conn, compat);
+ __connman_manager_init(conn, option_compat);
__connman_plugin_init();
@@ -156,7 +137,9 @@ int main(int argc, char *argv[])
__connman_network_init(conn);
- __connman_iface_init(conn, interface);
+ __connman_iface_init(conn, option_interface);
+
+ g_free(option_interface);
memset(&sa, 0, sizeof(sa));
sa.sa_handler = sig_term;
diff --git a/src/manager.c b/src/manager.c
index 218d34e7..9d14cd74 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -208,9 +208,9 @@ static GDBusMethodTable nm_methods[] = {
};
static DBusConnection *connection = NULL;
-static int nm_compat = 0;
+static gboolean nm_compat = FALSE;
-int __connman_manager_init(DBusConnection *conn, int compat)
+int __connman_manager_init(DBusConnection *conn, gboolean compat)
{
DBG("conn %p", conn);
@@ -225,13 +225,13 @@ int __connman_manager_init(DBusConnection *conn, int compat)
manager_methods,
manager_signals, NULL);
- if (compat) {
+ if (compat == TRUE) {
g_dbus_register_object(connection, NM_PATH, NULL, NULL);
g_dbus_register_interface(connection, NM_PATH, NM_INTERFACE,
nm_methods, NULL, NULL);
- nm_compat = 1;
+ nm_compat = TRUE;
}
return 0;
@@ -241,7 +241,7 @@ void __connman_manager_cleanup(void)
{
DBG("conn %p", connection);
- if (nm_compat) {
+ if (nm_compat == TRUE) {
g_dbus_unregister_interface(connection, NM_PATH, NM_INTERFACE);
g_dbus_unregister_object(connection, NM_PATH);