iptables: Refactor default return code usage
authorTomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Mon, 13 Aug 2012 10:28:51 +0000 (13:28 +0300)
committerPatrik Flykt <patrik.flykt@linux.intel.com>
Tue, 14 Aug 2012 12:08:45 +0000 (15:08 +0300)
src/iptables.c

index 531e933..cce2fb5 100644 (file)
@@ -1533,7 +1533,8 @@ static int iptables_command(int argc, char *argv[])
        xt_rm = NULL;
        xt_m = NULL;
        xt_t = NULL;
-       ret = 0;
+       /* Default code for options parsing */
+       ret = -EINVAL;
 
        /* extension's options will generate false-positives errors */
        opterr = 0;
@@ -1670,10 +1671,8 @@ static int iptables_command(int argc, char *argv[])
                        table_name = optarg;
 
                        table = iptables_init(table_name);
-                       if (table == NULL) {
-                               ret = -EINVAL;
+                       if (table == NULL)
                                goto out;
-                       }
 
                        break;
 
@@ -1686,7 +1685,6 @@ static int iptables_command(int argc, char *argv[])
 
                        connman_error("Invalid option");
 
-                       ret = -EINVAL;
                        goto out;
 
                default:
@@ -1769,12 +1767,13 @@ static int iptables_command(int argc, char *argv[])
                table_name = "filter";
 
                table = iptables_init(table_name);
-               if (table == NULL) {
-                       ret = -EINVAL;
+               if (table == NULL)
                        goto out;
-               }
        }
 
+       /* Option parsing went fine, falling back to succes code */
+       ret = 0;
+
        if (delete_chain != NULL) {
                printf("Delete chain %s\n", delete_chain);
 
@@ -1786,7 +1785,6 @@ static int iptables_command(int argc, char *argv[])
        if (dump) {
                iptables_dump(table);
 
-               ret = 0;
                goto out;
        }