Send connman mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        https://lists.01.org/mailman/listinfo/connman
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of connman digest..."


Today's Topics:

   1. [PATCH v3 6/9] connmand-wait-online: Add option to ignore
      interfaces (Patrik Flykt)
   2. [PATCH v3 7/9] connmand-wait-online: Add timeout option
      (Patrik Flykt)
   3. [PATCH v3 9/9] connman.service: Remove dependencies on
      remote-fs.target (Patrik Flykt)
   4. [PATCH v3 5/9] connmand-wait-online: Add command line switch
      for interfaces (Patrik Flykt)
   5. Re: [PATCH v3 1/9] connmand-wait-online: Add program and
      initial main loop (Peter Meerwald-Stadler)


----------------------------------------------------------------------

Message: 1
Date: Mon,  7 Dec 2015 10:51:32 +0200
From: Patrik Flykt <[email protected]>
To: [email protected]
Subject: [PATCH v3 6/9] connmand-wait-online: Add option to ignore
        interfaces
Message-ID:
        <[email protected]>

Add command line option to ignore interfaces. Interfaces are
first matched against the ignored ones, then the expected ones.
---
 src/connmand-wait-online.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/connmand-wait-online.c b/src/connmand-wait-online.c
index fc89df5..5b89b83 100644
--- a/src/connmand-wait-online.c
+++ b/src/connmand-wait-online.c
@@ -38,14 +38,18 @@ static GMainLoop *main_loop;
 
 static gboolean option_version = FALSE;
 static gchar *option_interface = NULL;
+static gchar *option_ignore = NULL;
 
 struct devices {
        char **interface;
+       char **ignore;
 };
 
 static GOptionEntry options[] = {
        { "interface", 'i', 0, G_OPTION_ARG_STRING, &option_interface,
          "Specify networking device or interface", "DEV" },
+       { "ignore", 'I', 0, G_OPTION_ARG_STRING, &option_ignore,
+         "Specify networking device or interface to ignore", "DEV" },
        { "version", 'v', 0, G_OPTION_ARG_NONE, &option_version,
          "Show version information and exit" },
        { NULL },
@@ -58,6 +62,13 @@ static bool compare_interface(const char *interface, struct 
devices *devices)
        if (!interface || !devices)
                return false;
 
+       for (i = 0; devices->ignore && devices->ignore[i]; i++)
+               if (!strcmp(interface, devices->ignore[i]))
+                       return false;
+
+       if (!devices->interface)
+               return true;
+
        for (i = 0; devices->interface[i]; i++)
                if (!strcmp(interface, devices->interface[i]))
                        return true;
@@ -348,7 +359,7 @@ int main(int argc, char *argv[])
                CONNMAN_MANAGER_INTERFACE "'";
        int err = 0;
        GError *g_err = NULL;
-       struct devices devices = { NULL };
+       struct devices devices = { NULL, NULL };
        DBusError dbus_err;
        GOptionContext *context;
 
@@ -372,6 +383,11 @@ int main(int argc, char *argv[])
                g_free(option_interface);
        }
 
+       if (option_ignore) {
+               devices.ignore = g_strsplit(option_ignore, ",", -1);
+               g_free(option_ignore);
+       }
+
         if (option_version) {
                fprintf(stdout, "%s\n", VERSION);
                goto free;
@@ -417,6 +433,7 @@ fail:
        dbus_error_free(&dbus_err);
 free:
        g_strfreev(devices.interface);
+       g_strfreev(devices.ignore);
 
        return -err;
 }
-- 
2.1.4



------------------------------

Message: 2
Date: Mon,  7 Dec 2015 10:51:33 +0200
From: Patrik Flykt <[email protected]>
To: [email protected]
Subject: [PATCH v3 7/9] connmand-wait-online: Add timeout option
Message-ID:
        <[email protected]>

Add a timeout option in order not to wait forever for networks.
The default timeout is 120 seconds and can be disabled entirely
by setting timeout to 0.
---
 src/connmand-wait-online.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/src/connmand-wait-online.c b/src/connmand-wait-online.c
index 5b89b83..2711d56 100644
--- a/src/connmand-wait-online.c
+++ b/src/connmand-wait-online.c
@@ -35,10 +35,13 @@
 
 static DBusConnection *connection;
 static GMainLoop *main_loop;
+static int timeout = 0;
+static int exit_value = 0;
 
 static gboolean option_version = FALSE;
 static gchar *option_interface = NULL;
 static gchar *option_ignore = NULL;
+static gint option_timeout = 120;
 
 struct devices {
        char **interface;
@@ -50,6 +53,9 @@ static GOptionEntry options[] = {
          "Specify networking device or interface", "DEV" },
        { "ignore", 'I', 0, G_OPTION_ARG_STRING, &option_ignore,
          "Specify networking device or interface to ignore", "DEV" },
+       { "timeout", 0, 0, G_OPTION_ARG_INT, &option_timeout,
+         "Time to wait for network going online. Default is 120 seconds.",
+         "seconds" },
        { "version", 'v', 0, G_OPTION_ARG_NONE, &option_version,
          "Show version information and exit" },
        { NULL },
@@ -353,6 +359,15 @@ static DBusHandlerResult 
manager_property_changed(DBusConnection *connection,
        return DBUS_HANDLER_RESULT_HANDLED;
 }
 
+static gboolean timeout_triggered(gpointer user_data)
+{
+       exit_value = -ETIMEDOUT;
+       g_main_loop_quit(main_loop);
+       timeout = 0;
+
+       return FALSE;
+}
+
 int main(int argc, char *argv[])
 {
        const char *filter = "type='signal',interface='"
@@ -417,9 +432,14 @@ int main(int argc, char *argv[])
                goto cleanup;
        }
 
+       if (option_timeout)
+               timeout = g_timeout_add_seconds(option_timeout,
+                                               timeout_triggered, NULL);
+
        manager_get_properties(&devices);
 
        g_main_loop_run(main_loop);
+       err = exit_value;
 
 cleanup:
        dbus_bus_remove_match(connection, filter, NULL);
@@ -434,6 +454,8 @@ fail:
 free:
        g_strfreev(devices.interface);
        g_strfreev(devices.ignore);
+       if (timeout)
+               g_source_remove(timeout);
 
        return -err;
 }
-- 
2.1.4



------------------------------

Message: 3
Date: Mon,  7 Dec 2015 10:51:35 +0200
From: Patrik Flykt <[email protected]>
To: [email protected]
Subject: [PATCH v3 9/9] connman.service: Remove dependencies on
        remote-fs.target
Message-ID:
        <[email protected]>

With a working connman-wait-online.service, the extra dependency
hack on remote-fs.target can be removed and ConnMan started before
multi-user.target.
---
 src/connman.service.in | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/connman.service.in b/src/connman.service.in
index 8006a06..2198a19 100644
--- a/src/connman.service.in
+++ b/src/connman.service.in
@@ -4,8 +4,8 @@ DefaultDependencies=false
 Conflicts=shutdown.target
 RequiresMountsFor=@localstatedir@/lib/connman
 After=dbus.service network-pre.target
-Before=network.target shutdown.target remote-fs-pre.target
-Wants=network.target remote-fs-pre.target
+Before=network.target multi-user.target shutdown.target
+Wants=network.target
 
 [Service]
 Type=dbus
-- 
2.1.4



------------------------------

Message: 4
Date: Mon,  7 Dec 2015 10:51:31 +0200
From: Patrik Flykt <[email protected]>
To: [email protected]
Subject: [PATCH v3 5/9] connmand-wait-online: Add command line switch
        for interfaces
Message-ID:
        <[email protected]>

Add command line switch to specify one ore more interfaces to wait
for before deciding if the systemd is "online" in systemd terms.

Once the global Manager state is known to be online, request all
services and iterate over the service properties to find out if
the service state is 'ready' or 'online' for a service with the
specified interface name.
---
 src/connmand-wait-online.c | 219 ++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 208 insertions(+), 11 deletions(-)

diff --git a/src/connmand-wait-online.c b/src/connmand-wait-online.c
index eab8c7d..fc89df5 100644
--- a/src/connmand-wait-online.c
+++ b/src/connmand-wait-online.c
@@ -37,13 +37,34 @@ static DBusConnection *connection;
 static GMainLoop *main_loop;
 
 static gboolean option_version = FALSE;
+static gchar *option_interface = NULL;
+
+struct devices {
+       char **interface;
+};
 
 static GOptionEntry options[] = {
+       { "interface", 'i', 0, G_OPTION_ARG_STRING, &option_interface,
+         "Specify networking device or interface", "DEV" },
        { "version", 'v', 0, G_OPTION_ARG_NONE, &option_version,
          "Show version information and exit" },
        { NULL },
 };
 
+static bool compare_interface(const char *interface, struct devices *devices)
+{
+       int i;
+
+       if (!interface || !devices)
+               return false;
+
+       for (i = 0; devices->interface[i]; i++)
+               if (!strcmp(interface, devices->interface[i]))
+                       return true;
+
+       return false;
+}
+
 static bool state_online(DBusMessageIter *iter)
 {
        char *str;
@@ -73,7 +94,165 @@ static bool state_online(DBusMessageIter *iter)
        return true;
 }
 
-static void manager_properties_online(DBusMessageIter *iter)
+static bool service_properties_online(DBusMessageIter *array_entry,
+                               struct devices *devices)
+{
+       bool interface = !devices;
+       bool state = false;
+       DBusMessageIter dict, dict_entry, variant, eth_array, eth_dict,
+               eth_variant;
+       char *str;
+
+       for (dbus_message_iter_recurse(array_entry, &dict);
+            dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY;
+            dbus_message_iter_next(&dict)) {
+
+               dbus_message_iter_recurse(&dict, &dict_entry);
+               if (dbus_message_iter_get_arg_type(&dict_entry)
+                               != DBUS_TYPE_STRING)
+                       continue;
+
+               if (state_online(&dict_entry)) {
+                       state = true;
+                       continue;
+               }
+
+               dbus_message_iter_recurse(&dict, &dict_entry);
+
+               dbus_message_iter_get_basic(&dict_entry, &str);
+
+               if (devices && !strcmp(str, "Ethernet")) {
+                       dbus_message_iter_next(&dict_entry);
+
+                       if (dbus_message_iter_get_arg_type(&dict_entry)
+                                       != DBUS_TYPE_VARIANT)
+                               break;
+
+                       dbus_message_iter_recurse(&dict_entry, &variant);
+                       if (dbus_message_iter_get_arg_type(&variant)
+                                       != DBUS_TYPE_ARRAY)
+                               break;
+
+                       for (dbus_message_iter_recurse(&variant, &eth_array);
+                            dbus_message_iter_get_arg_type(&eth_array)
+                                    == DBUS_TYPE_DICT_ENTRY;
+                            dbus_message_iter_next(&eth_array)) {
+
+                               dbus_message_iter_recurse(&eth_array, 
&eth_dict);
+
+                               if (dbus_message_iter_get_arg_type(&eth_dict)
+                                               != DBUS_TYPE_STRING)
+                                       continue;
+
+                               dbus_message_iter_get_basic(&eth_dict, &str);
+                               if (!strcmp(str, "Interface")) {
+
+                                       dbus_message_iter_next(&eth_dict);
+                                       if 
(dbus_message_iter_get_arg_type(&eth_dict)
+                                                       != DBUS_TYPE_VARIANT)
+                                               break;
+
+                                       dbus_message_iter_recurse(&eth_dict,
+                                                               &eth_variant);
+                                       if 
(dbus_message_iter_get_arg_type(&eth_variant)
+                                                       != DBUS_TYPE_STRING)
+                                               break;
+
+                                       
dbus_message_iter_get_basic(&eth_variant,
+                                                               &str);
+                                       interface = compare_interface(str,
+                                                               devices);
+
+                                       break;
+                               }
+                       }
+               }
+
+               if (state && interface) {
+                       g_main_loop_quit(main_loop);
+                       return true;
+               }
+       }
+
+       return false;
+}
+
+static void services_dict_online(DBusMessageIter *iter, struct devices 
*devices)
+{
+       DBusMessageIter array, array_entry;
+
+       if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
+               return;
+
+       for (dbus_message_iter_recurse(iter, &array);
+            dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRUCT;
+            dbus_message_iter_next(&array)) {
+
+               dbus_message_iter_recurse(&array, &array_entry);
+
+               if (dbus_message_iter_get_arg_type(&array_entry) !=
+                               DBUS_TYPE_OBJECT_PATH)
+                       break;
+
+               dbus_message_iter_next(&array_entry);
+
+               if (dbus_message_iter_get_arg_type(&array_entry) !=
+                               DBUS_TYPE_ARRAY)
+                       continue;
+
+               if (service_properties_online(&array_entry, devices))
+                       break;
+       }
+}
+
+static void manager_get_services_return(DBusPendingCall *call,
+                                       void *user_data)
+{
+       struct devices *devices = user_data;
+       DBusMessage *reply;
+       DBusMessageIter iter;
+
+       reply = dbus_pending_call_steal_reply(call);
+       if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR)
+                goto fail;
+
+        if (!dbus_message_iter_init(reply, &iter))
+                goto fail;
+
+       services_dict_online(&iter, devices);
+
+fail:
+       dbus_message_unref(reply);
+       dbus_pending_call_unref(call);
+}
+
+static void manager_get_services(struct devices *devices)
+{
+       DBusMessage *message;
+       DBusPendingCall *call;
+
+       message = dbus_message_new_method_call(CONNMAN_SERVICE,
+                                       CONNMAN_MANAGER_PATH,
+                                       CONNMAN_MANAGER_INTERFACE,
+                                       "GetServices");
+       if (!message)
+               return;
+
+       if (!dbus_connection_send_with_reply(connection, message, &call, -1))
+                goto fail;
+
+        if (!call)
+                goto fail;
+
+       dbus_pending_call_set_notify(call, manager_get_services_return,
+                               devices, NULL);
+
+fail:
+        dbus_message_unref(message);
+}
+
+static void manager_properties_online(DBusMessageIter *iter,
+                               struct devices *devices)
 {
        DBusMessageIter array, dict_entry;
 
@@ -87,7 +266,11 @@ static void manager_properties_online(DBusMessageIter *iter)
                dbus_message_iter_recurse(&array, &dict_entry);
 
                if (state_online(&dict_entry)) {
-                       g_main_loop_quit(main_loop);
+                       if (devices)
+                               manager_get_services(devices);
+                       else
+                               g_main_loop_quit(main_loop);
+
                        break;
                }
        }
@@ -95,6 +278,7 @@ static void manager_properties_online(DBusMessageIter *iter)
 
 static void manager_get_properties_return(DBusPendingCall *call, void 
*user_data)
 {
+       struct devices *devices = user_data;
        DBusMessage *reply;
        DBusMessageIter iter;
 
@@ -105,14 +289,14 @@ static void manager_get_properties_return(DBusPendingCall 
*call, void *user_data
         if (!dbus_message_iter_init(reply, &iter))
                 goto fail;
 
-       manager_properties_online(&iter);
+       manager_properties_online(&iter, devices);
 
 fail:
        dbus_message_unref(reply);
        dbus_pending_call_unref(call);
 }
 
-static void manager_get_properties(void)
+static void manager_get_properties(struct devices *devices)
 {
        DBusMessage *message;
        DBusPendingCall *call;
@@ -131,7 +315,7 @@ static void manager_get_properties(void)
                 goto fail;
 
        dbus_pending_call_set_notify(call, manager_get_properties_return,
-                               NULL, NULL);
+                               devices, NULL);
 
 fail:
         dbus_message_unref(message);
@@ -140,14 +324,19 @@ fail:
 static DBusHandlerResult manager_property_changed(DBusConnection *connection,
                 DBusMessage *message, void *user_data)
 {
+       struct devices *devices = user_data;
        DBusMessageIter iter;
 
        if (dbus_message_is_signal(message, CONNMAN_MANAGER_INTERFACE,
                                        "PropertyChanged")) {
                dbus_message_iter_init(message, &iter);
 
-               if (state_online(&iter))
-                       g_main_loop_quit(main_loop);
+               if (state_online(&iter)) {
+                       if (devices)
+                               manager_get_services(devices);
+                       else
+                               g_main_loop_quit(main_loop);
+               }
        }
 
        return DBUS_HANDLER_RESULT_HANDLED;
@@ -159,6 +348,7 @@ int main(int argc, char *argv[])
                CONNMAN_MANAGER_INTERFACE "'";
        int err = 0;
        GError *g_err = NULL;
+       struct devices devices = { NULL };
        DBusError dbus_err;
        GOptionContext *context;
 
@@ -177,9 +367,14 @@ int main(int argc, char *argv[])
 
         g_option_context_free(context);
 
+       if (option_interface) {
+               devices.interface = g_strsplit(option_interface, ",", -1);
+               g_free(option_interface);
+       }
+
         if (option_version) {
                fprintf(stdout, "%s\n", VERSION);
-               return 0;
+               goto free;
        }
 
        dbus_error_init(&dbus_err);
@@ -195,7 +390,7 @@ int main(int argc, char *argv[])
        main_loop = g_main_loop_new(NULL, FALSE);
 
        dbus_connection_add_filter(connection, manager_property_changed,
-                               NULL, NULL);
+                               &devices, NULL);
 
        dbus_bus_add_match(connection, filter, &dbus_err);
 
@@ -206,20 +401,22 @@ int main(int argc, char *argv[])
                goto cleanup;
        }
 
-       manager_get_properties();
+       manager_get_properties(&devices);
 
        g_main_loop_run(main_loop);
 
 cleanup:
        dbus_bus_remove_match(connection, filter, NULL);
        dbus_connection_remove_filter(connection, manager_property_changed,
-                               NULL);
+                               &devices);
 
        dbus_connection_unref(connection);
        g_main_loop_unref(main_loop);
 
 fail:
        dbus_error_free(&dbus_err);
+free:
+       g_strfreev(devices.interface);
 
        return -err;
 }
-- 
2.1.4



------------------------------

Message: 5
Date: Mon, 7 Dec 2015 10:25:27 +0100 (CET)
From: Peter Meerwald-Stadler <[email protected]>
To: Patrik Flykt <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH v3 1/9] connmand-wait-online: Add program and
        initial main loop
Message-ID: <[email protected]>
Content-Type: TEXT/PLAIN; charset=US-ASCII


> Add connmand-wait-online program that will return once ConnMan has
> connected a service. The return value with a service connected is
> zero; on error errno will be returned.

don't be so negative :)

> ---
>  Makefile.am                |  7 +++++-
>  src/connmand-wait-online.c | 61 
> ++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 67 insertions(+), 1 deletion(-)
>  create mode 100644 src/connmand-wait-online.c
> 
> diff --git a/Makefile.am b/Makefile.am
> index 95082c1..5b0c2de 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -97,7 +97,7 @@ unit_objects =
>  
>  MANUAL_PAGES =
>  
> -sbin_PROGRAMS = src/connmand
> +sbin_PROGRAMS = src/connmand src/connmand-wait-online
>  
>  src_connmand_SOURCES = $(gdhcp_sources) $(gweb_sources) \
>                       $(builtin_sources) $(shared_sources) src/connman.ver \
> @@ -125,6 +125,11 @@ src_connmand_LDADD = gdbus/libgdbus-internal.la 
> $(builtin_libadd) \
>  src_connmand_LDFLAGS = -Wl,--export-dynamic \
>                               -Wl,--version-script=$(srcdir)/src/connman.ver
>  
> +src_connmand_wait_online_SOURCES = src/connmand-wait-online.c
> +
> +src_connmand_wait_online_LDADD = gdbus/libgdbus-internal.la \
> +                     @GLIB_LIBS@ @DBUS_LIBS@
> +
>  if VPN
>  vpn_plugin_LTLIBRARIES =
>  
> diff --git a/src/connmand-wait-online.c b/src/connmand-wait-online.c
> new file mode 100644
> index 0000000..bf7c8db
> --- /dev/null
> +++ b/src/connmand-wait-online.c
> @@ -0,0 +1,61 @@
> +/*
> + *
> + *  Connection Manager
> + *
> + *  Copyright (C) 2015  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 <glib.h>
> +#include <errno.h>
> +
> +#include <gdbus.h>
> +
> +static DBusConnection *connection;
> +static GMainLoop *main_loop;
> +
> +int main(int argc, char *argv[])
> +{
> +     int err = 0;
> +     DBusError dbus_err;
> +
> +     dbus_error_init(&dbus_err);
> +     connection = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, &dbus_err);
> +
> +     if (dbus_error_is_set(&dbus_err)) {
> +             fprintf(stderr, "Error: %s\n", dbus_err.message);
> +
> +             err = -ENOPROTOOPT;

negative

> +             goto fail;
> +     }
> +
> +     main_loop = g_main_loop_new(NULL, FALSE);
> +
> +     g_main_loop_run(main_loop);
> +
> +     dbus_connection_unref(connection);
> +     g_main_loop_unref(main_loop);
> +
> +fail:
> +     dbus_error_free(&dbus_err);
> +
> +     return -err;

double negative

> +}
> 

-- 

Peter Meerwald-Stadler
+43-664-2444418 (mobile)


------------------------------

Subject: Digest Footer

_______________________________________________
connman mailing list
[email protected]
https://lists.01.org/mailman/listinfo/connman


------------------------------

End of connman Digest, Vol 2, Issue 7
*************************************

Reply via email to