[systemd-commits] 2 commits - Makefile.am Makefile-man.am man/networkd-wait-online.conf.xml man/systemd-networkd-wait-online.service.xml src/network

Tom Gundersen tomegun at kemper.freedesktop.org
Fri Apr 25 16:26:31 PDT 2014


 Makefile-man.am                              |    1 
 Makefile.am                                  |   10 -
 man/networkd-wait-online.conf.xml            |   95 -------------
 man/systemd-networkd-wait-online.service.xml |   33 +++-
 src/network/.gitignore                       |    1 
 src/network/networkd-wait-online-gperf.gperf |   17 --
 src/network/networkd-wait-online.c           |  187 ++++++++++++++++-----------
 src/network/networkd-wait-online.conf        |   11 -
 src/network/networkd-wait-online.h           |    4 
 9 files changed, 138 insertions(+), 221 deletions(-)

New commits:
commit 27134b2f052c7dc6bedff6c09e97c5df3b2d7a54
Author: Tom Gundersen <teg at jklm.no>
Date:   Thu Apr 24 21:32:25 2014 +0200

    networkd-wait-online: refactor a bit
    
    Clarify that we are waiting for any link to reach 'carrier' state, regardless
    of who manages it. This will be useful when we add support for waiting for more
    operational states.

diff --git a/src/network/networkd-wait-online.c b/src/network/networkd-wait-online.c
index 6530659..ba02586 100644
--- a/src/network/networkd-wait-online.c
+++ b/src/network/networkd-wait-online.c
@@ -164,56 +164,51 @@ static bool all_configured(Manager *m) {
                 if (!found) {
                         /* link exists, but networkd is not yet aware of it */
                         return false;
+                }
         }
 
         for (i = 0; i < n; i++) {
                 _cleanup_free_ char *state = NULL;
+                _cleanup_rtnl_message_unref_ sd_rtnl_message *message = NULL, *reply = NULL;
+                unsigned flags;
+                uint8_t operstate;
 
                 r = sd_network_get_link_state(indices[i], &state);
-                if (r == -EUNATCH) {
-                        _cleanup_rtnl_message_unref_ sd_rtnl_message *message = NULL, *reply = NULL;
-                        unsigned flags;
-                        uint8_t operstate;
-
-                        r = sd_rtnl_message_new_link(m->rtnl, &message, RTM_GETLINK, indices[i]);
-                        if (r < 0) {
-                                log_warning("could not create GETLINK message: %s", strerror(-r));
-                                return false;
-                        }
-
-                        r = sd_rtnl_call(m->rtnl, message, 0, &reply);
-                        if (r < 0) {
-                                log_debug("could not get link %u: %s", indices[i], strerror(-r));
-                                continue;
-                        }
-
-                        r = sd_rtnl_message_link_get_flags(reply, &flags);
-                        if (r < 0) {
-                                log_warning("could not get link flags: %s", strerror(-r));
-                                return false;
-                        }
+                if (r != -EUNATCH && (r < 0 || !streq(state, "configured"))) {
+                        /* managed by networkd, but not yet configured */
+                        return false;
+                }
 
-                        r = sd_rtnl_message_read_u8(reply, IFLA_OPERSTATE, &operstate);
-                        if (r < 0) {
-                                log_debug("could not get link operational state: %s", strerror(-r));
-                                operstate = IF_OPER_UNKNOWN;
-                        }
-                        
-                        if (!(flags & IFF_LOOPBACK) &&
-                            link_has_carrier(flags, operstate)) {
-                                /* this link is not managed by us,
-                                   but something else may have
-                                   made it ready, so don't block */
-                                one_ready = true;
-                        }
+                r = sd_rtnl_message_new_link(m->rtnl, &message, RTM_GETLINK, indices[i]);
+                if (r < 0) {
+                        log_warning("could not create GETLINK message: %s", strerror(-r));
+                        return false;
+                }
 
+                r = sd_rtnl_call(m->rtnl, message, 0, &reply);
+                if (r < 0) {
+                        log_debug("could not get link %u: %s", indices[i], strerror(-r));
                         continue;
-                } else if (r < 0 || !streq(state, "configured"))
-                        /* managed by networkd, but not yet configured */
+                }
+
+                r = sd_rtnl_message_link_get_flags(reply, &flags);
+                if (r < 0) {
+                        log_warning("could not get link flags: %s", strerror(-r));
                         return false;
+                }
+
+                r = sd_rtnl_message_read_u8(reply, IFLA_OPERSTATE, &operstate);
+                if (r < 0) {
+                        log_debug("could not get link operational state: %s", strerror(-r));
+                        operstate = IF_OPER_UNKNOWN;
+                }
 
-                /* we wait for at least one link to appear */
-                one_ready = true;
+                if (!(flags & IFF_LOOPBACK) &&
+                    link_has_carrier(flags, operstate)) {
+                        /* we wait for at least one link to be ready,
+                           regardless of who manages it */
+                        one_ready = true;
+                }
         }
 
         return one_ready;

commit cef8b0735831b2bfeaf21d8a245d8024c3de816a
Author: Tom Gundersen <teg at jklm.no>
Date:   Thu Apr 24 21:28:46 2014 +0200

    networkd-wait-online: drop config file and add commandline options instead

diff --git a/Makefile-man.am b/Makefile-man.am
index db66e02..60ee991 100644
--- a/Makefile-man.am
+++ b/Makefile-man.am
@@ -1040,7 +1040,6 @@ if ENABLE_NETWORKD
 MANPAGES += \
 	man/systemd-networkd.service.8 \
 	man/systemd-networkd-wait-online.service.8 \
-	man/networkd-wait-online.conf.5 \
 	man/systemd.netdev.5 \
 	man/systemd.network.5
 MANPAGES_ALIAS += \
diff --git a/Makefile.am b/Makefile.am
index 1d37357..7f3924f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -4170,9 +4170,6 @@ systemd_networkd_wait_online_SOURCES = \
 	src/network/networkd-wait-online.c \
 	src/network/networkd-wait-online.h
 
-nodist_systemd_networkd_wait_online_SOURCES = \
-	src/network/networkd-wait-online-gperf.c
-
 systemd_networkd_wait_online_LDADD = \
 	libsystemd-internal.la \
 	libsystemd-network.la
@@ -4186,19 +4183,14 @@ test_network_LDADD = \
 tests += \
 	test-network
 
-dist_pkgsysconf_DATA += \
-	src/network/networkd-wait-online.conf
-
 EXTRA_DIST += \
 	src/network/networkd-network-gperf.gperf \
 	src/network/networkd-netdev-gperf.gperf \
-	src/network/networkd-wait-online-gperf.gperf \
 	units/systemd-networkd.service.in
 
 CLEANFILES += \
 	src/network/networkd-network-gperf.c \
-	src/network/networkd-netdev-gperf.c \
-	src/network/networkd-wait-online-gperf.c
+	src/network/networkd-netdev-gperf.c
 endif
 
 # ------------------------------------------------------------------------------
diff --git a/man/networkd-wait-online.conf.xml b/man/networkd-wait-online.conf.xml
deleted file mode 100644
index 821b0ef..0000000
--- a/man/networkd-wait-online.conf.xml
+++ /dev/null
@@ -1,95 +0,0 @@
-<?xml version='1.0'?> <!--*-nxml-*-->
-<?xml-stylesheet type="text/xsl" href="http://docbook.sourceforge.net/release/xsl/current/xhtml/docbook.xsl"?>
-<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
-        "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
-
-<!--
-  This file is part of systemd.
-
-  Copyright 2014 Tom Gundersen
-
-  systemd is free software; you can redistribute it and/or modify it
-  under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or
-  (at your option) any later version.
-
-  systemd 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
-  Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public License
-  along with systemd; If not, see <http://www.gnu.org/licenses/>.
--->
-
-<refentry id="networkd-wait-online.conf" conditional='ENABLE_NETWORKD'>
-        <refentryinfo>
-                <title>networkd-wait-online.conf</title>
-                <productname>systemd</productname>
-
-                <authorgroup>
-                        <author>
-                                <contrib>Developer</contrib>
-                                <firstname>Tom</firstname>
-                                <surname>Gundersen</surname>
-                                <email>teg at jklm.no</email>
-                        </author>
-                </authorgroup>
-        </refentryinfo>
-
-        <refmeta>
-                <refentrytitle>networkd-wait-online.conf</refentrytitle>
-                <manvolnum>5</manvolnum>
-        </refmeta>
-
-        <refnamediv>
-                <refname>networkd-wait-online.conf</refname>
-                <refpurpose>Network manager configuration file</refpurpose>
-        </refnamediv>
-
-        <refsynopsisdiv>
-                <para><filename>/etc/systemd/networkd-wait-online.conf</filename></para>
-        </refsynopsisdiv>
-
-        <refsect1>
-                <title>Description</title>
-
-                <para>This file configures various parameters of the systemd network manager's wait-online service, <citerefentry><refentrytitle>systemd-networkd-wait-online.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>.</para>
-
-        </refsect1>
-
-        <refsect1>
-                <title>Options</title>
-
-                <para>All options are configured in the
-                <literal>[WaitOnline]</literal> section:</para>
-
-                <variablelist>
-
-                        <varlistentry>
-                                <term><varname>After=</varname></term>
-
-                                <listitem><para>Takes a white-space
-                                separated list of network interface
-                                names. Configures which network interfaces
-                                to wait for before deciding if the machine
-                                is considered to be online. The default is
-                                to wait for at least one that is managed by
-                                <citerefentry><refentrytitle>systemd-networkd.service
-                                </refentrytitle><manvolnum>8</manvolnum></citerefentry>,
-                                or one other which is brought up by someone else.
-                                </para></listitem>
-                        </varlistentry>
-
-                </variablelist>
-        </refsect1>
-
-        <refsect1>
-                  <title>See Also</title>
-                  <para>
-                          <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
-                          <citerefentry><refentrytitle>systemd-networkd.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
-                  </para>
-        </refsect1>
-
-</refentry>
diff --git a/man/systemd-networkd-wait-online.service.xml b/man/systemd-networkd-wait-online.service.xml
index d8f2226..c8190e1 100644
--- a/man/systemd-networkd-wait-online.service.xml
+++ b/man/systemd-networkd-wait-online.service.xml
@@ -45,7 +45,7 @@
         <refnamediv>
                 <refname>systemd-networkd-wait-online.service</refname>
                 <refname>systemd-networkd-wait-online</refname>
-                <refpurpose>Wait for network to become online</refpurpose>
+                <refpurpose>Wait for network to come online</refpurpose>
         </refnamediv>
 
         <refsynopsisdiv>
@@ -58,22 +58,37 @@
 
                 <para><command>systemd-networkd-wait-online</command> is a
                 one-shot system service that waits for the network to be configured.
-                It will wait for all links managed by
+                By default it will wait for all links it is aware of that are managed by
                 <citerefentry><refentrytitle>systemd-networkd.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
-                to be fully configured. It will wait for at least one link managed by
-                systemd-networkd to appear, or for a link to be brought up by someone else.
+                to be fully configured or failed, and for at least one link to gain a
+                carrier.</para>
+        </refsect1>
 
-                To wait for a specific set of links, see
-                <citerefentry><refentrytitle>systemd-networkd.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
-                This may be necessary on systems with more than one active link.
-                </para>
+        <refsect1>
+                <title>Options</title>
+
+                <para>The following options are understood:</para>
+
+                <variablelist>
+                        <varlistentry>
+                                <term><option>-i</option></term>
+                                <term><option>--interface=</option></term>
+
+                                <listitem><para>Network interface to wait for
+                                before deciding if the system is online. This is
+                                useful when a system has several interfaces which
+                                will be configured, but a particular one is necessary
+                                to access some network resources. This option may be
+                                used more than once to wait for multiple network
+                                interfaces.</para></listitem>
+                        </varlistentry>
+                </variablelist>
         </refsect1>
 
         <refsect1>
                 <title>See Also</title>
                 <para>
                         <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
-                        <citerefentry><refentrytitle>systemd-networkd.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
                         <citerefentry><refentrytitle>systemd-networkd.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
                 </para>
         </refsect1>
diff --git a/src/network/.gitignore b/src/network/.gitignore
index e3b86e2..8858596 100644
--- a/src/network/.gitignore
+++ b/src/network/.gitignore
@@ -1,3 +1,2 @@
 /networkd-network-gperf.c
 /networkd-netdev-gperf.c
-/networkd-wait-online-gperf.c
diff --git a/src/network/networkd-wait-online-gperf.gperf b/src/network/networkd-wait-online-gperf.gperf
deleted file mode 100644
index 0a5e5ee..0000000
--- a/src/network/networkd-wait-online-gperf.gperf
+++ /dev/null
@@ -1,17 +0,0 @@
-%{
-#include <stddef.h>
-#include "conf-parser.h"
-#include "networkd-wait-online.h"
-%}
-struct ConfigPerfItem;
-%null_strings
-%language=ANSI-C
-%define slot-name section_and_lvalue
-%define hash-function-name wait_online_gperf_hash
-%define lookup-function-name wait_online_gperf_lookup
-%readonly-tables
-%omit-struct-type
-%struct-type
-%includes
-%%
-WaitOnline.ExpectedLinks,               config_parse_strv,          0, offsetof(Manager, expected_links)
diff --git a/src/network/networkd-wait-online.c b/src/network/networkd-wait-online.c
index 6a7c62f..6530659 100644
--- a/src/network/networkd-wait-online.c
+++ b/src/network/networkd-wait-online.c
@@ -21,6 +21,7 @@
 
 #include <netinet/ether.h>
 #include <linux/if.h>
+#include <getopt.h>
 
 #include "sd-event.h"
 #include "event-util.h"
@@ -35,6 +36,75 @@
 #include "conf-parser.h"
 #include "strv.h"
 #include "util.h"
+#include "build.h"
+
+static bool arg_quiet = false;
+static char **arg_interfaces = NULL;
+
+static int help(void) {
+
+        printf("%s [OPTIONS...]\n\n"
+               "Block until network is configured.\n\n"
+               "  -h --help                 Show this help\n"
+               "     --version              Print version string\n"
+               "  -q --quiet                Do not show status information\n"
+               "  -i --interface=INTERFACE  Block until at least these interfaces have appeared\n",
+               program_invocation_short_name);
+
+        return 0;
+}
+
+static int parse_argv(int argc, char *argv[]) {
+
+        enum {
+                ARG_VERSION = 0x100,
+        };
+
+        static const struct option options[] = {
+                { "help",            no_argument,       NULL, 'h'         },
+                { "version",         no_argument,       NULL, ARG_VERSION },
+                { "quiet",           no_argument,       NULL, 'q'         },
+                { "interface",       required_argument, NULL, 'i'         },
+                {}
+        };
+
+        int c;
+
+        assert(argc >= 0);
+        assert(argv);
+
+        while ((c = getopt_long(argc, argv, "+hq", options, NULL)) >= 0) {
+
+                switch (c) {
+
+                case 'h':
+                        return help();
+
+                case 'q':
+                        arg_quiet = true;
+                        break;
+
+                case ARG_VERSION:
+                        puts(PACKAGE_STRING);
+                        puts(SYSTEMD_FEATURES);
+                        return 0;
+
+                case 'i':
+                        if (strv_extend(&arg_interfaces, optarg) < 0)
+                                return log_oom();
+
+                        break;
+
+                case '?':
+                        return -EINVAL;
+
+                default:
+                        assert_not_reached("Unhandled option");
+                }
+        }
+
+        return 1;
+}
 
 static bool all_configured(Manager *m) {
         _cleanup_free_ unsigned *indices = NULL;
@@ -46,7 +116,7 @@ static bool all_configured(Manager *m) {
         if (n <= 0)
                 return false;
 
-        STRV_FOREACH(ifname, m->expected_links) {
+        STRV_FOREACH(ifname, arg_interfaces) {
                 _cleanup_rtnl_message_unref_ sd_rtnl_message *message = NULL, *reply = NULL;
                 bool found = false;
                 int index;
@@ -91,7 +161,7 @@ static bool all_configured(Manager *m) {
                         }
                 }
 
-                if (!found)
+                if (!found) {
                         /* link exists, but networkd is not yet aware of it */
                         return false;
         }
@@ -139,6 +209,7 @@ static bool all_configured(Manager *m) {
 
                         continue;
                 } else if (r < 0 || !streq(state, "configured"))
+                        /* managed by networkd, but not yet configured */
                         return false;
 
                 /* we wait for at least one link to appear */
@@ -173,35 +244,12 @@ static int newlink_event_handler(sd_rtnl *rtnl, sd_rtnl_message *message, void *
         return 1;
 }
 
-static int parse_config_file(Manager *m) {
-        static const char fn[] = "/etc/systemd/networkd-wait-online.conf";
-        _cleanup_fclose_ FILE *f = NULL;
-        int r;
-
-        f = fopen(fn, "re");
-        if (!f) {
-                if (errno == ENOENT)
-                        return 0;
-
-                log_warning("Failed to open configuration file %s: %m", fn);
-                return -errno;
-        }
-
-        r = config_parse(NULL, fn, f, "WaitOnline\0", config_item_perf_lookup,
-                         (void*) wait_online_gperf_lookup, false, false, m);
-        if (r < 0)
-                log_warning("Failed to parse configuration file: %s", strerror(-r));
-
-        return r;
-}
-
 void manager_free(Manager *m) {
         if (!m)
                 return;
 
         sd_event_unref(m->event);
         sd_rtnl_unref(m->rtnl);
-        strv_free(m->expected_links);
 
         free(m);
 }
@@ -212,26 +260,22 @@ int main(int argc, char *argv[]) {
         _cleanup_network_monitor_unref_ sd_network_monitor *monitor = NULL;
         int r, fd, events;
 
-        log_set_target(LOG_TARGET_AUTO);
+        umask(0022);
+
         log_parse_environment();
         log_open();
 
-        umask(0022);
+        r = parse_argv(argc, argv);
+        if (r <= 0)
+                return r;
 
-        if (argc != 1) {
-                log_error("This program takes no arguments.");
-                r = -EINVAL;
-                goto out;
-        }
+        if (arg_quiet)
+                log_set_max_level(LOG_WARNING);
 
         m = new0(Manager, 1);
         if (!m)
                 return log_oom();
 
-        r = parse_config_file(m);
-        if (r < 0)
-                goto out;
-
         r = sd_network_monitor_new(NULL, &monitor);
         if (r < 0) {
                 log_error("Could not create monitor: %s", strerror(-r));
diff --git a/src/network/networkd-wait-online.conf b/src/network/networkd-wait-online.conf
deleted file mode 100644
index fa3d92f..0000000
--- a/src/network/networkd-wait-online.conf
+++ /dev/null
@@ -1,11 +0,0 @@
-#  This file is part of systemd.
-#
-#  systemd is free software; you can redistribute it and/or modify it
-#  under the terms of the GNU Lesser General Public License as published by
-#  the Free Software Foundation; either version 2.1 of the License, or
-#  (at your option) any later version.
-#
-# See networkd-wait-online.conf(5) for details
-
-[WaitOnline]
-#ExpectedLinks=
diff --git a/src/network/networkd-wait-online.h b/src/network/networkd-wait-online.h
index 463df16..91edce1 100644
--- a/src/network/networkd-wait-online.h
+++ b/src/network/networkd-wait-online.h
@@ -29,13 +29,9 @@
 typedef struct Manager {
         sd_event *event;
         sd_rtnl *rtnl;
-        char **expected_links;
 } Manager;
 
 void manager_free(Manager *m);
 
 DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
 #define _cleanup_manager_free_ _cleanup_(manager_freep)
-
-/* gperf lookup function */
-const struct ConfigPerfItem* wait_online_gperf_lookup(const char *key, unsigned length);



More information about the systemd-commits mailing list