summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--Makefile.am11
-rw-r--r--Makefile.plugins24
-rw-r--r--README12
-rwxr-xr-xbootstrap-configure1
-rw-r--r--configure.ac17
-rw-r--r--plugins/dhclient.c237
-rw-r--r--scripts/dhclient-script.c133
-rw-r--r--scripts/dhclient.conf6
-rw-r--r--tools/dhclient-test.c264
10 files changed, 1 insertions, 706 deletions
diff --git a/.gitignore b/.gitignore
index 25710a54..3ea81abf 100644
--- a/.gitignore
+++ b/.gitignore
@@ -34,7 +34,6 @@ src/connman.service
src/*-connman.rules
plugins/connman.policy
scripts/connman
-scripts/dhclient-script
scripts/openconnect-script
client/cm
tools/wispr
@@ -47,7 +46,6 @@ tools/wpad-test
tools/resolv-test
tools/polkit-test
tools/iptables-test
-tools/dhclient-test
tools/supplicant-test
tools/dbus-test
doc/*.bak
diff --git a/Makefile.am b/Makefile.am
index b4d4250d..b31cf72c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -165,16 +165,6 @@ tools_dbus_test_LDADD = @GLIB_LIBS@ @DBUS_LIBS@
tools_polkit_test_LDADD = @DBUS_LIBS@
tools_iptables_test_LDADD = @GLIB_LIBS@ @XTABLES_LIBS@
-
-if DHCLIENT
-noinst_PROGRAMS += tools/dhclient-test
-
-tools_dhclient_test_SOURCES = gdbus/gdbus.h gdbus/mainloop.c gdbus/watch.c \
- tools/dhclient-test.c
-tools_dhclient_test_LDADD = @GLIB_LIBS@ @DBUS_LIBS@
-
-tools_dhclient_test_CFLAGS = $(AM_CFLAGS) -DDHCLIENT=\"@DHCLIENT@\"
-endif
endif
test_scripts = test/get-state test/list-profiles test/list-services \
@@ -214,7 +204,6 @@ DISTCHECK_CONFIGURE_FLAGS = --disable-gtk-doc \
--enable-wifi \
--enable-bluetooth \
--enable-ofono \
- --enable-dhclient \
--enable-dnsproxy \
--enable-pacrunner \
--enable-google \
diff --git a/Makefile.plugins b/Makefile.plugins
index 07aa1db9..79edda5a 100644
--- a/Makefile.plugins
+++ b/Makefile.plugins
@@ -95,21 +95,6 @@ plugins_ofono_la_LDFLAGS = $(plugin_ldflags)
endif
endif
-if DHCLIENT
-if DHCLIENT_BUILTIN
-builtin_modules += dhclient
-builtin_sources += plugins/dhclient.c
-builtin_cflags += -DDHCLIENT=\"@DHCLIENT@\"
-else
-plugin_LTLIBRARIES += plugins/dhclient.la
-plugin_objects += $(plugins_dhclient_la_OBJECTS)
-plugins_dhclient_la_CFLAGS = $(plugin_cflags) -DDHCLIENT=\"@DHCLIENT@\" \
- -DSTATEDIR=\""$(statedir)"\" \
- -DSCRIPTDIR=\""$(build_scriptdir)"\"
-plugins_dhclient_la_LDFLAGS = $(plugin_ldflags)
-endif
-endif
-
if OPENCONNECT
if OPENCONNECT_BUILTIN
builtin_modules += openconnect
@@ -265,13 +250,6 @@ script_PROGRAMS += scripts/openvpn-script
scripts_openvpn_script_LDADD = @DBUS_LIBS@
endif
-if DHCLIENT
-script_DATA += scripts/dhclient.conf
-script_PROGRAMS += scripts/dhclient-script
-
-scripts_dhclient_script_LDADD = @DBUS_LIBS@
-endif
-
if NTPD
if NTPD_BUILTIN
builtin_modules += ntpd
@@ -285,7 +263,7 @@ plugins_ntpd_la_LDFLAGS = $(plugin_ldflags)
endif
endif
-EXTRA_DIST += plugins/polkit.policy scripts/dhclient.conf
+EXTRA_DIST += plugins/polkit.policy
plugins/connman.policy: plugins/polkit.policy
if POLKIT
diff --git a/README b/README
index a547f0dc..d19da3be 100644
--- a/README
+++ b/README
@@ -18,7 +18,6 @@ Various plugins can be enabled for networking support:
- Bluetooth plugin
Also plugins with additional features are available:
- - DHCP plugin (dhclient)
- Resolver plugin (DNS proxy)
- Loopback setup
- PolicyKit support
@@ -60,17 +59,6 @@ For a working system, certain configuration options need to be enabled:
Enable support for Bluetooth devices (requires BlueZ)
- --enable-dhclient
-
- Enable DHCP client support for ISC dhclient based systems
-
- The location of the dhclient binary is auto-detected, but it
- can be overwritten via --with-dhclient=<path-to-binary>.
-
- At least one DHCP client option should be selected. It is
- possible to select both and then uDHCP will be tried first
- before falling back to dhclient.
-
--enable-dnsproxy
Enable DNS proxy support for /etc/resolv.conf abstraction
diff --git a/bootstrap-configure b/bootstrap-configure
index 3bce9474..4126f67a 100755
--- a/bootstrap-configure
+++ b/bootstrap-configure
@@ -21,7 +21,6 @@ fi
--enable-wifi=builtin \
--enable-bluetooth=builtin \
--enable-ofono=builtin \
- --enable-dhclient=builtin \
--enable-openconnect=builtin \
--enable-openvpn=builtin \
--enable-pacrunner=builtin \
diff --git a/configure.ac b/configure.ac
index a1390f08..ba73bf03 100644
--- a/configure.ac
+++ b/configure.ac
@@ -95,23 +95,6 @@ AC_ARG_ENABLE(ofono,
AM_CONDITIONAL(OFONO, test "${enable_ofono}" != "no")
AM_CONDITIONAL(OFONO_BUILTIN, test "${enable_ofono}" = "builtin")
-AC_ARG_WITH(dhclient, AC_HELP_STRING([--with-dhclient=PROGRAM],
- [specify location of dhclient binary]), [path_dhclient=${withval}])
-
-AC_ARG_ENABLE(dhclient,
- AC_HELP_STRING([--enable-dhclient], [enable dhclient support]),
- [enable_dhclient=${enableval}], [enable_dhclient="no"])
-if (test "${enable_dhclient}" != "no"); then
- if (test -z "${path_dhclient}"); then
- AC_PATH_PROG(DHCLIENT, [dhclient], [], $PATH:/sbin:/usr/sbin)
- else
- DHCLIENT="${path_dhclient}"
- AC_SUBST(DHCLIENT)
- fi
-fi
-AM_CONDITIONAL(DHCLIENT, test "${enable_dhclient}" != "no")
-AM_CONDITIONAL(DHCLIENT_BUILTIN, test "${enable_dhclient}" = "builtin")
-
AC_ARG_WITH(openconnect, AC_HELP_STRING([--with-openconnect=PROGRAM],
[specify location of openconnect binary]), [path_openconnect=${withval}])
diff --git a/plugins/dhclient.c b/plugins/dhclient.c
deleted file mode 100644
index 7e74a930..00000000
--- a/plugins/dhclient.c
+++ /dev/null
@@ -1,237 +0,0 @@
-/*
- *
- * Connection Manager
- *
- * Copyright (C) 2007-2010 Intel Corporation. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-#include <errno.h>
-#include <unistd.h>
-#include <arpa/inet.h>
-
-#include <glib.h>
-
-#define CONNMAN_API_SUBJECT_TO_CHANGE
-#include <connman/plugin.h>
-#include <connman/utsname.h>
-#include <connman/dhcp.h>
-#include <connman/task.h>
-#include <connman/log.h>
-
-static void dhclient_notify(struct connman_task *task,
- DBusMessage *msg, void *user_data)
-{
- struct connman_dhcp *dhcp = user_data;
- DBusMessageIter iter, dict;
- dbus_uint32_t pid;
- const char *text, *key, *value;
-
- dbus_message_iter_init(msg, &iter);
-
- dbus_message_iter_get_basic(&iter, &pid);
- dbus_message_iter_next(&iter);
-
- dbus_message_iter_get_basic(&iter, &text);
- dbus_message_iter_next(&iter);
-
- DBG("change %d to %s", pid, text);
-
- dbus_message_iter_recurse(&iter, &dict);
-
- while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
- DBusMessageIter entry;
-
- dbus_message_iter_recurse(&dict, &entry);
- dbus_message_iter_get_basic(&entry, &key);
- dbus_message_iter_next(&entry);
- dbus_message_iter_get_basic(&entry, &value);
-
- DBG("%s = %s", key, value);
-
- if (g_strcmp0(key, "new_ip_address") == 0) {
- connman_dhcp_set_value(dhcp, "Address", value);
- } else if (g_strcmp0(key, "new_subnet_mask") == 0) {
- connman_dhcp_set_value(dhcp, "Netmask", value);
- } else if (g_strcmp0(key, "new_routers") == 0) {
- connman_dhcp_set_value(dhcp, "Gateway", value);
- } else if (g_strcmp0(key, "new_network_number") == 0) {
- connman_dhcp_set_value(dhcp, "Network", value);
- } else if (g_strcmp0(key, "new_broadcast_address") == 0) {
- connman_dhcp_set_value(dhcp, "Broadcast", value);
- } else if (g_strcmp0(key, "new_domain_name_servers") == 0) {
- connman_dhcp_set_value(dhcp, "Nameserver", value);
- } else if (g_ascii_strcasecmp(key, "new_domain_name") == 0) {
- connman_dhcp_set_value(dhcp, "Domainname", value);
- } else if (g_ascii_strcasecmp(key, "new_domain_search") == 0) {
- } else if (g_ascii_strcasecmp(key, "new_host_name") == 0) {
- connman_dhcp_set_value(dhcp, "Hostname", value);
- } else if (g_ascii_strcasecmp(key, "new_ntp_servers") == 0) {
- connman_dhcp_set_value(dhcp, "Timeserver", value);
- } else if (g_ascii_strcasecmp(key, "new_interface_mtu") == 0) {
- connman_dhcp_set_value(dhcp, "MTU", value);
- } else if (g_ascii_strcasecmp(key, "new_proxy_auto_config") == 0) {
- connman_dhcp_set_value(dhcp, "PAC", value);
- }
-
- dbus_message_iter_next(&dict);
- }
-
- if (g_strcmp0(text, "PREINIT") == 0) {
- } else if (g_strcmp0(text, "BOUND") == 0 ||
- g_strcmp0(text, "REBOOT") == 0) {
- connman_dhcp_bound(dhcp);
- } else if (g_strcmp0(text, "RENEW") == 0 ||
- g_strcmp0(text, "REBIND") == 0) {
- connman_dhcp_renew(dhcp);
- } else if (g_strcmp0(text, "FAIL") == 0) {
- connman_dhcp_fail(dhcp);
- } else {
- }
-}
-
-struct dhclient_data {
- struct connman_task *task;
- struct connman_dhcp *dhcp;
- char *ifname;
-};
-
-static void dhclient_unlink(const char *ifname)
-{
- char *pathname;
-
- pathname = g_strdup_printf("%s/dhclient.%s.pid",
- STATEDIR, ifname);
- unlink(pathname);
- g_free(pathname);
-
- pathname = g_strdup_printf("%s/dhclient.%s.leases",
- STATEDIR, ifname);
- unlink(pathname);
- g_free(pathname);
-}
-
-static void dhclient_died(struct connman_task *task, void *user_data)
-{
- struct dhclient_data *dhclient = user_data;
-
- connman_dhcp_set_data(dhclient->dhcp, NULL);
-
- connman_dhcp_unref(dhclient->dhcp);
-
- connman_task_destroy(dhclient->task);
- dhclient->task = NULL;
-
- dhclient_unlink(dhclient->ifname);
-
- g_free(dhclient->ifname);
- g_free(dhclient);
-}
-
-static void dhclient_setup(struct connman_task *task, const char *ifname)
-{
- const char *path, *intf = "net.connman.Task";
-
- path = connman_task_get_path(task);
-
- connman_task_add_argument(task, "-d", NULL);
- connman_task_add_argument(task, "-q", NULL);
- connman_task_add_argument(task, "-e", "BUSNAME=net.connman");
- connman_task_add_argument(task, "-e", "BUSINTF=%s", intf);
- connman_task_add_argument(task, "-e", "BUSPATH=%s", path);
- connman_task_add_argument(task, "-pf", "%s/dhclient.%s.pid",
- STATEDIR, ifname);
- connman_task_add_argument(task, "-lf", "%s/dhclient.%s.leases",
- STATEDIR, ifname);
- connman_task_add_argument(task, "-cf", "%s/dhclient.conf", SCRIPTDIR);
- connman_task_add_argument(task, "-sf", "%s/dhclient-script", SCRIPTDIR);
- connman_task_add_argument(task, ifname, NULL);
- connman_task_add_argument(task, "-n", NULL);
-}
-
-static int dhclient_request(struct connman_dhcp *dhcp)
-{
- struct dhclient_data *dhclient;
-
- DBG("dhcp %p", dhcp);
-
- if (access(DHCLIENT, X_OK) < 0)
- return -EIO;
-
- dhclient = g_try_new0(struct dhclient_data, 1);
- if (dhclient == NULL)
- return -ENOMEM;
-
- dhclient->task = connman_task_create(DHCLIENT);
- if (dhclient->task == NULL) {
- g_free(dhclient);
- return -ENOMEM;
- }
-
- dhclient->dhcp = connman_dhcp_ref(dhcp);
- dhclient->ifname = connman_dhcp_get_interface(dhcp);
-
- dhclient_setup(dhclient->task, dhclient->ifname);
-
- connman_dhcp_set_data(dhcp, dhclient);
-
- connman_task_set_notify(dhclient->task, "Notify",
- dhclient_notify, dhcp);
-
- connman_task_run(dhclient->task, dhclient_died, dhclient,
- NULL, NULL, NULL);
-
- return 0;
-}
-
-static int dhclient_release(struct connman_dhcp *dhcp)
-{
- struct dhclient_data *dhclient = connman_dhcp_get_data(dhcp);
-
- DBG("dhcp %p", dhcp);
-
- if (dhclient == NULL)
- return -ESRCH;
-
- connman_task_stop(dhclient->task);
-
- return 0;
-}
-
-static struct connman_dhcp_driver dhclient_driver = {
- .name = "dhclient",
- .priority = CONNMAN_DHCP_PRIORITY_LOW,
- .request = dhclient_request,
- .release = dhclient_release,
-};
-
-static int dhclient_init(void)
-{
- return connman_dhcp_driver_register(&dhclient_driver);
-}
-
-static void dhclient_exit(void)
-{
- connman_dhcp_driver_unregister(&dhclient_driver);
-}
-
-CONNMAN_PLUGIN_DEFINE(dhclient, "ISC DHCP client plugin", VERSION,
- CONNMAN_PLUGIN_PRIORITY_DEFAULT, dhclient_init, dhclient_exit)
diff --git a/scripts/dhclient-script.c b/scripts/dhclient-script.c
deleted file mode 100644
index 35ede29a..00000000
--- a/scripts/dhclient-script.c
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- *
- * Connection Manager
- *
- * Copyright (C) 2007-2010 Intel Corporation. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <dbus/dbus.h>
-
-extern char **environ;
-
-static void append(DBusMessageIter *dict, const char *pattern)
-{
- DBusMessageIter entry;
- const char *key, *value;
- char *delim;
-
- delim = strchr(pattern, '=');
- *delim = '\0';
-
- key = pattern;
- value = delim + 1;
-
- dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
- NULL, &entry);
-
- dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
-
- dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &value);
-
- dbus_message_iter_close_container(dict, &entry);
-}
-
-int main(int argc, char *argv[])
-{
- DBusConnection *conn;
- DBusError error;
- DBusMessage *msg;
- DBusMessageIter iter, dict;
- dbus_uint32_t pid;
- char **envp, *busname, *busintf, *buspath, *reason, *interface;
-
- busname = getenv("BUSNAME");
- busintf = getenv("BUSINTF");
- buspath = getenv("BUSPATH");
-
- if (busname == NULL || busintf == NULL || buspath == NULL)
- return 0;
-
- pid = atoi(getenv("pid"));
- reason = getenv("reason");
- interface = getenv("interface");
-
- if (pid == 0 || reason == NULL)
- return 0;
-
- dbus_error_init(&error);
-
- conn = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
- if (conn == NULL) {
- if (dbus_error_is_set(&error) == TRUE) {
- fprintf(stderr, "%s\n", error.message);
- dbus_error_free(&error);
- } else
- fprintf(stderr, "Failed to get on system bus\n");
- return 0;
- }
-
- msg = dbus_message_new_method_call(busname, buspath,
- busintf, "Notify");
- if (msg == NULL) {
- dbus_connection_unref(conn);
- fprintf(stderr, "Failed to allocate method call\n");
- return 0;
- }
-
- dbus_message_set_no_reply(msg, TRUE);
-
- dbus_message_append_args(msg, DBUS_TYPE_UINT32, &pid,
- DBUS_TYPE_STRING, &reason, DBUS_TYPE_INVALID);
-
- dbus_message_iter_init_append(msg, &iter);
-
- dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
- DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
- DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_STRING_AS_STRING
- DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
-
- for (envp = environ; envp && *envp; envp++) {
- if (strlen(*envp) < 5)
- continue;
-
- if (strncmp(*envp, "new_", 4) == 0 ||
- strncmp(*envp, "old_", 4) == 0 ||
- strncmp(*envp, "alia", 4) == 0)
- append(&dict, *envp);
- }
-
- dbus_message_iter_close_container(&iter, &dict);
-
- if (dbus_connection_send(conn, msg, NULL) == FALSE)
- fprintf(stderr, "Failed to send message\n");
-
- dbus_connection_flush(conn);
-
- dbus_message_unref(msg);
-
- dbus_connection_unref(conn);
-
- return 0;
-}
diff --git a/scripts/dhclient.conf b/scripts/dhclient.conf
deleted file mode 100644
index 39741b12..00000000
--- a/scripts/dhclient.conf
+++ /dev/null
@@ -1,6 +0,0 @@
-option proxy-auto-config code 252 = text;
-request subnet-mask, broadcast-address, routers, host-name,
- domain-search, domain-name, domain-name-servers,
- time-offset, time-servers, ntp-servers, interface-mtu,
- proxy-auto-config;
-require subnet-mask, domain-name-servers;
diff --git a/tools/dhclient-test.c b/tools/dhclient-test.c
deleted file mode 100644
index ca969195..00000000
--- a/tools/dhclient-test.c
+++ /dev/null
@@ -1,264 +0,0 @@
-/*
- *
- * Connection Manager
- *
- * Copyright (C) 2007-2010 Intel Corporation. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <signal.h>
-#include <sys/wait.h>
-
-#include <gdbus.h>
-
-#define INTERFACE "isc.dhclient"
-#define PATH "/dhclient"
-
-static GTimer *timer;
-
-static GMainLoop *main_loop;
-
-static guint child_watch = 0;
-static pid_t pid = 0;
-
-static void sig_term(int sig)
-{
- g_main_loop_quit(main_loop);
-}
-
-static void free_pointer(gpointer data, gpointer user_data)
-{
- g_free(data);
-}
-
-static void dhclient_died(GPid pid, gint status, gpointer user_data)
-{
- if (WIFEXITED(status))
- printf("exit status %d\n", WEXITSTATUS(status));
- else
- printf("signal %d\n", WTERMSIG(status));
-
- g_spawn_close_pid(pid);
-
- child_watch = 0;
-}
-
-static void dhclient_setup(gpointer user_data)
-{
- printf("dhclient process setup\n");
-}
-
-static void add_argument(GPtrArray *array, const char *name,
- const char *format, ...)
-{
- va_list ap;
- char *str;
-
- str = g_strdup(name);
- g_ptr_array_add(array, str);
-
- va_start(ap, format);
-
- if (format != NULL) {
- str = g_strdup_vprintf(format, ap);
- g_ptr_array_add(array, str);
- }
-
- va_end(ap);
-}
-
-static void start_dhclient(DBusConnection *conn, const char *ifname)
-{
- GSpawnFlags flags = G_SPAWN_DO_NOT_REAP_CHILD;
- GPtrArray *argv;
- GPtrArray *envp;
- gboolean result;
- const char *busname;
-
- busname = dbus_bus_get_unique_name(conn);
- busname = "net.connman";
-
- argv = g_ptr_array_new();
- add_argument(argv, DHCLIENT, NULL);
- add_argument(argv, "-d", NULL);
- add_argument(argv, "-q", NULL);
- add_argument(argv, "-e", "BUSNAME=%s", busname);
- add_argument(argv, "-e", "BUSINTF=%s", INTERFACE);
- add_argument(argv, "-e", "BUSPATH=%s", PATH);
- add_argument(argv, "-pf", "%s/dhclient.%s.pid", STATEDIR, ifname);
- add_argument(argv, "-lf", "%s/dhclient.%s.leases", STATEDIR, ifname);
- add_argument(argv, "-cf", "%s/dhclient.conf", SCRIPTDIR);
- add_argument(argv, "-sf", "%s/dhclient-script", SCRIPTDIR);
- add_argument(argv, ifname, NULL);
- add_argument(argv, "-n", NULL);
- g_ptr_array_add(argv, NULL);
-
- envp = g_ptr_array_new();
- g_ptr_array_add(envp, NULL);
-
- result = g_spawn_async_with_pipes(NULL, (char **) argv->pdata,
- (char **) envp->pdata,
- flags, dhclient_setup, NULL,
- &pid, NULL, NULL, NULL, NULL);
-
- child_watch = g_child_watch_add(pid, dhclient_died, NULL);
-
- g_ptr_array_foreach(envp, free_pointer, NULL);
- g_ptr_array_free(envp, TRUE);
-
- g_ptr_array_foreach(argv, free_pointer, NULL);
- g_ptr_array_free(argv, TRUE);
-}
-
-static void parse_notification(DBusMessage *msg)
-{
- DBusMessageIter iter, dict;
- dbus_uint32_t pid;
- gdouble elapsed;
- const char *text, *key, *value;
-
- dbus_message_iter_init(msg, &iter);
-
- dbus_message_iter_get_basic(&iter, &pid);
- dbus_message_iter_next(&iter);
-
- dbus_message_iter_get_basic(&iter, &text);
- dbus_message_iter_next(&iter);
-
- printf("change %d to %s\n", pid, text);
-
- dbus_message_iter_recurse(&iter, &dict);
-
- while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
- DBusMessageIter entry;
-
- dbus_message_iter_recurse(&dict, &entry);
- dbus_message_iter_get_basic(&entry, &key);
- dbus_message_iter_next(&entry);
- dbus_message_iter_get_basic(&entry, &value);
-
- printf("%s = %s\n", key, value);
-
- dbus_message_iter_next(&dict);
- }
-
- if (g_strcmp0(text, "PREINIT") == 0)
- return;
-
- elapsed = g_timer_elapsed(timer, NULL);
-
- g_print("elapsed %f seconds\n", elapsed);
-
- g_main_loop_quit(main_loop);
-}
-
-static DBusHandlerResult notify_filter(DBusConnection *conn,
- DBusMessage *msg, void *user_data)
-{
- if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_METHOD_CALL)
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
- if (dbus_message_has_interface(msg, INTERFACE) == FALSE)
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
- if (dbus_message_has_path(msg, PATH) == FALSE)
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
- if (dbus_message_has_member(msg, "Notify") == FALSE)
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
- parse_notification(msg);
-
- return DBUS_HANDLER_RESULT_HANDLED;
-}
-
-static const char *notify_rule = "type=method_call"
- ",interface=" INTERFACE;
-
-int main(int argc, char *argv[])
-{
- DBusConnection *conn;
- DBusError err;
- struct sigaction sa;
- const char *ifname;
-
- if (argc < 2) {
- printf("Usage: dhclient-test <interface name>\n");
- exit(0);
- }
-
- ifname = argv[1];
-
- printf("Create DHCP client for interface %s\n", ifname);
-
- main_loop = g_main_loop_new(NULL, FALSE);
-
- dbus_error_init(&err);
-
- conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, "net.connman", &err);
- if (conn == NULL) {
- if (dbus_error_is_set(&err) == TRUE) {
- fprintf(stderr, "%s\n", err.message);
- dbus_error_free(&err);
- } else
- fprintf(stderr, "Can't register with system bus\n");
- exit(1);
- }
-
- dbus_connection_add_filter(conn, notify_filter, NULL, NULL);
-
- dbus_bus_add_match(conn, notify_rule, NULL);
- dbus_connection_flush(conn);
-
- printf("Start DHCP operation\n");
-
- timer = g_timer_new();
-
- start_dhclient(conn, ifname);
-
- memset(&sa, 0, sizeof(sa));
- sa.sa_handler = sig_term;
- sigaction(SIGINT, &sa, NULL);
- sigaction(SIGTERM, &sa, NULL);
-
- g_main_loop_run(main_loop);
-
- if (pid > 0)
- kill(pid, SIGTERM);
-
- if (child_watch > 0)
- g_source_remove(child_watch);
-
- g_timer_destroy(timer);
-
- dbus_bus_remove_match(conn, notify_rule, NULL);
- dbus_connection_flush(conn);
-
- dbus_connection_remove_filter(conn, notify_filter, NULL);
-
- dbus_connection_unref(conn);
-
- g_main_loop_unref(main_loop);
-
- return 0;
-}