swconfig: improve failure reporting
authorJo-Philipp Wich <jo@mein.io>
Fri, 10 Jun 2016 22:51:22 +0000 (00:51 +0200)
committerJo-Philipp Wich <jo@mein.io>
Fri, 10 Jun 2016 22:51:22 +0000 (00:51 +0200)
Report the translated error to the user if a get/set netlink operation failed.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
package/network/config/swconfig/Makefile
package/network/config/swconfig/src/cli.c

index 2856742fcd0f5a398b0801495441adfed3dafb48..f4ba3a9d699cd858fa530c3b7ca9551428481602 100644 (file)
@@ -8,7 +8,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=swconfig
-PKG_RELEASE:=10
+PKG_RELEASE:=11
 
 PKG_MAINTAINER:=Felix Fietkau <nbd@nbd.name>
 PKG_LICENSE:=GPL-2.0
index 331f3d5dac1852a6a150ace78d6aeeb6731d2883..eab6c64742e96d1453c62b07d40b4824db6ed9fb 100644 (file)
@@ -335,10 +335,10 @@ int main(int argc, char **argv)
                if(cvlan > -1)
                        cport = cvlan;
 
-               if(swlib_set_attr_string(dev, a, cport, cvalue) < 0)
+               retval = swlib_set_attr_string(dev, a, cport, cvalue);
+               if (retval < 0)
                {
-                       fprintf(stderr, "failed\n");
-                       retval = -1;
+                       nl_perror(-retval, "Failed to set attribute");
                        goto out;
                }
                break;
@@ -347,10 +347,10 @@ int main(int argc, char **argv)
                        val.port_vlan = cvlan;
                if(cport > -1)
                        val.port_vlan = cport;
-               if(swlib_get_attr(dev, a, &val) < 0)
+               retval = swlib_get_attr(dev, a, &val);
+               if (retval < 0)
                {
-                       fprintf(stderr, "failed\n");
-                       retval = -1;
+                       nl_perror(-retval, "Failed to get attribute");
                        goto out;
                }
                print_attr_val(a, &val);