]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Merge pull request #4104 from ssahani/ethtool_xlink_settings
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 10 Nov 2016 22:09:44 +0000 (17:09 -0500)
committerGitHub <noreply@github.com>
Thu, 10 Nov 2016 22:09:44 +0000 (17:09 -0500)
Link: port to new ethtool ETHTOOL_xLINKSETTINGS

src/core/namespace.c
src/libsystemd/sd-bus/busctl-introspect.c

index 308e4d768e4320adec22e2808b5ba6b00e45f4d5..67b203ba76d124181f9c3f4b9b7cfcbc19fb6fd3 100644 (file)
@@ -331,7 +331,7 @@ static void drop_duplicates(BindMount *m, unsigned *n) {
 
         /* Drops duplicate entries. Expects that the array is properly ordered already. */
 
-        for (f = m, t = m, previous = NULL; f < m+*n; f++) {
+        for (f = m, t = m, previous = NULL; f < m + *n; f++) {
 
                 /* The first one wins (which is the one with the more restrictive mode), see mount_path_compare()
                  * above. */
@@ -359,7 +359,7 @@ static void drop_inaccessible(BindMount *m, unsigned *n) {
         /* Drops all entries obstructed by another entry further up the tree. Expects that the array is properly
          * ordered already. */
 
-        for (f = m, t = m; f < m+*n; f++) {
+        for (f = m, t = m; f < m + *n; f++) {
 
                 /* If we found a path set for INACCESSIBLE earlier, and this entry has it as prefix we should drop
                  * it, as inaccessible paths really should drop the entire subtree. */
@@ -387,7 +387,7 @@ static void drop_nop(BindMount *m, unsigned *n) {
         /* Drops all entries which have an immediate parent that has the same type, as they are redundant. Assumes the
          * list is ordered by prefixes. */
 
-        for (f = m, t = m; f < m+*n; f++) {
+        for (f = m, t = m; f < m + *n; f++) {
 
                 /* Only suppress such subtrees for READONLY and READWRITE entries */
                 if (IN_SET(f->mode, READONLY, READWRITE)) {
@@ -423,12 +423,13 @@ static void drop_outside_root(const char *root_directory, BindMount *m, unsigned
         assert(m);
         assert(n);
 
+        /* Nothing to do */
         if (!root_directory)
                 return;
 
         /* Drops all mounts that are outside of the root directory. */
 
-        for (f = m, t = m; f < m+*n; f++) {
+        for (f = m, t = m; f < m + *n; f++) {
 
                 if (!path_startswith(f->path, root_directory)) {
                         log_debug("%s is outside of root directory.", f->path);
@@ -671,9 +672,10 @@ static int make_read_only(BindMount *m, char **blacklist) {
         return r;
 }
 
+/* Chase symlinks and remove failed paths from mounts */
 static int chase_all_symlinks(const char *root_directory, BindMount *m, unsigned *n) {
         BindMount *f, *t;
-        int r;
+        int r = 0;
 
         assert(m);
         assert(n);
@@ -683,22 +685,24 @@ static int chase_all_symlinks(const char *root_directory, BindMount *m, unsigned
          * can't resolve the path, and which have been marked for such removal. */
 
         for (f = m, t = m; f < m + *n; f++) {
+                int k;
                 _cleanup_free_ char *chased = NULL;
 
-                r = chase_symlinks(f->path, root_directory, &chased);
-                if (r == -ENOENT && f->ignore) {
-                        /* Doesn't exist? Then remove it! */
+                k = chase_symlinks(f->path, root_directory, &chased);
+                if (k < 0) {
+                        /* Get only real errors */
+                        if (r >= 0 && (k != -ENOENT || !f->ignore))
+                                r = k;
+
+                        log_debug_errno(r, "Failed to chase symlinks for %s: %m", f->path);
+                        /* Doesn't exist or failed? Then remove it and continue! */
                         f->path = mfree(f->path);
                         continue;
                 }
-                if (r < 0)
-                        return log_debug_errno(r, "Failed to chase symlinks for %s: %m", f->path);
 
                 if (!path_equal(f->path, chased)) {
                         log_debug("Chased %s → %s", f->path, chased);
-                        r = free_and_replace(f->path, chased);
-                        if (r < 0)
-                                return r;
+                        free_and_replace(f->path, chased);
                 }
 
                 *t = *f;
@@ -706,7 +710,7 @@ static int chase_all_symlinks(const char *root_directory, BindMount *m, unsigned
         }
 
         *n = t - m;
-        return 0;
+        return r;
 }
 
 static unsigned namespace_calculate_mounts(
index 09cbd9ab449d16c35c8cda960ba0a6cbb03058bb..a05794941fea90a271099d7a431216f03c1a0a74 100644 (file)
@@ -143,9 +143,7 @@ static int parse_xml_annotation(Context *context, uint64_t *flags) {
                 case STATE_NAME:
 
                         if (t == XML_ATTRIBUTE_VALUE) {
-                                free(field);
-                                field = name;
-                                name = NULL;
+                                free_and_replace(field, name);
 
                                 state = STATE_ANNOTATION;
                         } else {
@@ -158,9 +156,7 @@ static int parse_xml_annotation(Context *context, uint64_t *flags) {
                 case STATE_VALUE:
 
                         if (t == XML_ATTRIBUTE_VALUE) {
-                                free(value);
-                                value = name;
-                                name = NULL;
+                                free_and_replace(value, name);
 
                                 state = STATE_ANNOTATION;
                         } else {
@@ -194,6 +190,7 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
                 STATE_SIGNAL_ARG,
                 STATE_SIGNAL_ARG_NAME,
                 STATE_SIGNAL_ARG_TYPE,
+                STATE_SIGNAL_ARG_DIRECTION,
                 STATE_PROPERTY,
                 STATE_PROPERTY_NAME,
                 STATE_PROPERTY_TYPE,
@@ -350,11 +347,8 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
                 case STATE_INTERFACE_NAME:
 
                         if (t == XML_ATTRIBUTE_VALUE) {
-                                if (n_depth == 0) {
-                                        free(context->interface_name);
-                                        context->interface_name = name;
-                                        name = NULL;
-                                }
+                                if (n_depth == 0)
+                                        free_and_replace(context->interface_name, name);
 
                                 state = STATE_INTERFACE;
                         } else {
@@ -409,12 +403,8 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
                 case STATE_METHOD_NAME:
 
                         if (t == XML_ATTRIBUTE_VALUE) {
-
-                                if (n_depth == 0) {
-                                        free(context->member_name);
-                                        context->member_name = name;
-                                        name = NULL;
-                                }
+                                if (n_depth == 0)
+                                        free_and_replace(context->member_name, name);
 
                                 state = STATE_METHOD;
                         } else {
@@ -432,7 +422,7 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
                                 else if (streq_ptr(name, "type"))
                                         state = STATE_METHOD_ARG_TYPE;
                                 else if (streq_ptr(name, "direction"))
-                                         state = STATE_METHOD_ARG_DIRECTION;
+                                        state = STATE_METHOD_ARG_DIRECTION;
                                 else {
                                         log_error("Unexpected method <arg> attribute %s.", name);
                                         return -EBADMSG;
@@ -458,7 +448,8 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
                                                 } else if (streq(argument_direction, "out")) {
                                                         if (!strextend(&context->member_result, argument_type, NULL))
                                                                 return log_oom();
-                                                }
+                                                } else
+                                                        log_error("Unexpected method <arg> direction value '%s'.", argument_direction);
                                         }
 
                                         argument_type = mfree(argument_type);
@@ -487,9 +478,7 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
                 case STATE_METHOD_ARG_TYPE:
 
                         if (t == XML_ATTRIBUTE_VALUE) {
-                                free(argument_type);
-                                argument_type = name;
-                                name = NULL;
+                                free_and_replace(argument_type, name);
 
                                 state = STATE_METHOD_ARG;
                         } else {
@@ -502,9 +491,7 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
                 case STATE_METHOD_ARG_DIRECTION:
 
                         if (t == XML_ATTRIBUTE_VALUE) {
-                                free(argument_direction);
-                                argument_direction = name;
-                                name = NULL;
+                                free_and_replace(argument_direction, name);
 
                                 state = STATE_METHOD_ARG;
                         } else {
@@ -559,12 +546,8 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
                 case STATE_SIGNAL_NAME:
 
                         if (t == XML_ATTRIBUTE_VALUE) {
-
-                                if (n_depth == 0) {
-                                        free(context->member_name);
-                                        context->member_name = name;
-                                        name = NULL;
-                                }
+                                if (n_depth == 0)
+                                        free_and_replace(context->member_name, name);
 
                                 state = STATE_SIGNAL;
                         } else {
@@ -582,6 +565,8 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
                                         state = STATE_SIGNAL_ARG_NAME;
                                 else if (streq_ptr(name, "type"))
                                         state = STATE_SIGNAL_ARG_TYPE;
+                                else if (streq_ptr(name, "direction"))
+                                        state = STATE_SIGNAL_ARG_DIRECTION;
                                 else {
                                         log_error("Unexpected signal <arg> attribute %s.", name);
                                         return -EBADMSG;
@@ -599,8 +584,11 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
                                    (t == XML_TAG_CLOSE && streq_ptr(name, "arg"))) {
 
                                 if (argument_type) {
-                                        if (!strextend(&context->member_signature, argument_type, NULL))
-                                                return log_oom();
+                                        if (!argument_direction || streq(argument_direction, "out")) {
+                                                if (!strextend(&context->member_signature, argument_type, NULL))
+                                                        return log_oom();
+                                        } else
+                                                log_error("Unexpected signal <arg> direction value '%s'.", argument_direction);
 
                                         argument_type = mfree(argument_type);
                                 }
@@ -627,9 +615,7 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
                 case STATE_SIGNAL_ARG_TYPE:
 
                         if (t == XML_ATTRIBUTE_VALUE) {
-                                free(argument_type);
-                                argument_type = name;
-                                name = NULL;
+                                free_and_replace(argument_type, name);
 
                                 state = STATE_SIGNAL_ARG;
                         } else {
@@ -639,6 +625,19 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
 
                         break;
 
+                case STATE_SIGNAL_ARG_DIRECTION:
+
+                        if (t == XML_ATTRIBUTE_VALUE) {
+                                free_and_replace(argument_direction, name);
+
+                                state = STATE_SIGNAL_ARG;
+                        } else {
+                                log_error("Unexpected token in signal <arg>. (4)");
+                                return -EINVAL;
+                        }
+
+                        break;
+
                 case STATE_PROPERTY:
 
                         if (t == XML_ATTRIBUTE_NAME) {
@@ -688,12 +687,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
                 case STATE_PROPERTY_NAME:
 
                         if (t == XML_ATTRIBUTE_VALUE) {
+                                if (n_depth == 0)
+                                        free_and_replace(context->member_name, name);
 
-                                if (n_depth == 0) {
-                                        free(context->member_name);
-                                        context->member_name = name;
-                                        name = NULL;
-                                }
                                 state = STATE_PROPERTY;
                         } else {
                                 log_error("Unexpected token in <property>. (2)");
@@ -705,12 +701,8 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
                 case STATE_PROPERTY_TYPE:
 
                         if (t == XML_ATTRIBUTE_VALUE) {
-
-                                if (n_depth == 0) {
-                                        free(context->member_signature);
-                                        context->member_signature = name;
-                                        name = NULL;
-                                }
+                                if (n_depth == 0)
+                                        free_and_replace(context->member_signature, name);
 
                                 state = STATE_PROPERTY;
                         } else {