Bladeren bron

qemu-bridge-helper: move repeating code in parse_acl_file

Move repeating error handling sequence in parse_acl_file routine
to an 'err' label.

Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Li Qiang <liq3ea@gmail.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
Prasad J Pandit 6 jaren geleden
bovenliggende
commit
3283dde4b5
1 gewijzigde bestanden met toevoegingen van 9 en 10 verwijderingen
  1. 9 10
      qemu-bridge-helper.c

+ 9 - 10
qemu-bridge-helper.c

@@ -102,9 +102,7 @@ static int parse_acl_file(const char *filename, ACLList *acl_list)
 
 
         if (arg == NULL) {
         if (arg == NULL) {
             fprintf(stderr, "Invalid config line:\n  %s\n", line);
             fprintf(stderr, "Invalid config line:\n  %s\n", line);
-            fclose(f);
-            errno = EINVAL;
-            return -1;
+            goto err;
         }
         }
 
 
         *arg = 0;
         *arg = 0;
@@ -121,9 +119,7 @@ static int parse_acl_file(const char *filename, ACLList *acl_list)
 
 
         if (!g_str_equal(cmd, "include") && strlen(arg) >= IFNAMSIZ) {
         if (!g_str_equal(cmd, "include") && strlen(arg) >= IFNAMSIZ) {
             fprintf(stderr, "name `%s' too long: %zu\n", arg, strlen(arg));
             fprintf(stderr, "name `%s' too long: %zu\n", arg, strlen(arg));
-            fclose(f);
-            errno = EINVAL;
-            return -1;
+            goto err;
         }
         }
 
 
         if (strcmp(cmd, "deny") == 0) {
         if (strcmp(cmd, "deny") == 0) {
@@ -149,15 +145,18 @@ static int parse_acl_file(const char *filename, ACLList *acl_list)
             parse_acl_file(arg, acl_list);
             parse_acl_file(arg, acl_list);
         } else {
         } else {
             fprintf(stderr, "Unknown command `%s'\n", cmd);
             fprintf(stderr, "Unknown command `%s'\n", cmd);
-            fclose(f);
-            errno = EINVAL;
-            return -1;
+            goto err;
         }
         }
     }
     }
 
 
     fclose(f);
     fclose(f);
-
     return 0;
     return 0;
+
+err:
+    fclose(f);
+    errno = EINVAL;
+    return -1;
+
 }
 }
 
 
 static bool has_vnet_hdr(int fd)
 static bool has_vnet_hdr(int fd)