chiark / gitweb /
tmpfiles: Fix parse_acl error message
[elogind.git] / src / network / networkd-wait-online.c
index 714343656b268d7019aaa96377f61a7348fc3b49..f0ca6def874989c67608aada33373086851b3deb 100644 (file)
@@ -28,7 +28,9 @@
 #include "build.h"
 
 static bool arg_quiet = false;
+static usec_t arg_timeout = 120 * USEC_PER_SEC;
 static char **arg_interfaces = NULL;
+static char **arg_ignore = NULL;
 
 static void help(void) {
         printf("%s [OPTIONS...]\n\n"
@@ -37,6 +39,8 @@ static void help(void) {
                "     --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"
+               "     --ignore=INTERFACE     Don't take these interfaces into account\n"
+               "     --timeout=SECS         Maximum time to wait for network connectivity\n"
                , program_invocation_short_name);
 }
 
@@ -44,6 +48,8 @@ static int parse_argv(int argc, char *argv[]) {
 
         enum {
                 ARG_VERSION = 0x100,
+                ARG_IGNORE,
+                ARG_TIMEOUT,
         };
 
         static const struct option options[] = {
@@ -51,10 +57,12 @@ static int parse_argv(int argc, char *argv[]) {
                 { "version",         no_argument,       NULL, ARG_VERSION },
                 { "quiet",           no_argument,       NULL, 'q'         },
                 { "interface",       required_argument, NULL, 'i'         },
+                { "ignore",          required_argument, NULL, ARG_IGNORE  },
+                { "timeout",         required_argument, NULL, ARG_TIMEOUT  },
                 {}
         };
 
-        int c;
+        int c, r;
 
         assert(argc >= 0);
         assert(argv);
@@ -82,6 +90,19 @@ static int parse_argv(int argc, char *argv[]) {
 
                         break;
 
+                case ARG_IGNORE:
+                        if (strv_extend(&arg_ignore, optarg) < 0)
+                                return log_oom();
+
+                        break;
+
+                case ARG_TIMEOUT:
+                        r = parse_sec(optarg, &arg_timeout);
+                        if (r < 0)
+                                return r;
+
+                        break;
+
                 case '?':
                         return -EINVAL;
 
@@ -111,9 +132,9 @@ int main(int argc, char *argv[]) {
 
         assert_se(sigprocmask_many(SIG_BLOCK, SIGTERM, SIGINT, -1) == 0);
 
-        r = manager_new(&m, arg_interfaces);
+        r = manager_new(&m, arg_interfaces, arg_ignore, arg_timeout);
         if (r < 0) {
-                log_error("Could not create manager: %s", strerror(-r));
+                log_error_errno(r, "Could not create manager: %m");
                 goto finish;
         }
 
@@ -128,12 +149,21 @@ int main(int argc, char *argv[]) {
 
         r = sd_event_loop(m->event);
         if (r < 0) {
-                log_error("Event loop failed: %s", strerror(-r));
+                log_error_errno(r, "Event loop failed: %m");
                 goto finish;
         }
 
 finish:
-        sd_notify(false, "STATUS=All interfaces configured...");
+        strv_free(arg_interfaces);
+        strv_free(arg_ignore);
+
+        if (r >= 0) {
+                sd_notify(false, "STATUS=All interfaces configured...");
 
-        return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
+                return EXIT_SUCCESS;
+        } else {
+                sd_notify(false, "STATUS=Failed waiting for network connectivity...");
+
+                return EXIT_FAILURE;
+        }
 }