[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 1/2] bridge helper: unified error cleanup for par
From: |
Doug Goldstein |
Subject: |
[Qemu-devel] [PATCH v3 1/2] bridge helper: unified error cleanup for parse_acl_file |
Date: |
Sun, 17 Mar 2013 23:17:20 -0500 |
Handle errors and cleanup from the error in a unified place for
parse_acl_file().
Signed-off-by: Doug Goldstein <address@hidden>
Reviewed-by: Stefan Hajnoczi <address@hidden>
Reviewed-by: Corey Bryant <address@hidden>
CC: Anthony Liguori <address@hidden>
CC: Richa Marwaha <address@hidden>
CC: Corey Bryant <address@hidden>
TO: address@hidden
---
qemu-bridge-helper.c | 28 ++++++++++++++++------------
1 file changed, 16 insertions(+), 12 deletions(-)
diff --git a/qemu-bridge-helper.c b/qemu-bridge-helper.c
index 287bfd5..95486e7 100644
--- a/qemu-bridge-helper.c
+++ b/qemu-bridge-helper.c
@@ -74,11 +74,12 @@ static int parse_acl_file(const char *filename, ACLList
*acl_list)
{
FILE *f;
char line[4096];
+ int ret = -EINVAL;
ACLRule *acl_rule;
f = fopen(filename, "r");
if (f == NULL) {
- return -1;
+ return -errno;
}
while (fgets(line, sizeof(line), f) != NULL) {
@@ -102,9 +103,8 @@ static int parse_acl_file(const char *filename, ACLList
*acl_list)
if (arg == NULL) {
fprintf(stderr, "Invalid config line:\n %s\n", line);
- fclose(f);
- errno = EINVAL;
- return -1;
+ ret = -EINVAL;
+ goto failure;
}
*arg = 0;
@@ -142,15 +142,17 @@ static int parse_acl_file(const char *filename, ACLList
*acl_list)
parse_acl_file(arg, acl_list);
} else {
fprintf(stderr, "Unknown command `%s'\n", cmd);
- fclose(f);
- errno = EINVAL;
- return -1;
+ ret = -EINVAL;
+ goto failure;
}
}
+ ret = 0;
+
+failure:
fclose(f);
- return 0;
+ return ret;
}
static bool has_vnet_hdr(int fd)
@@ -238,7 +240,7 @@ int main(int argc, char **argv)
ACLRule *acl_rule;
ACLList acl_list;
int access_allowed, access_denied;
- int ret = EXIT_SUCCESS;
+ int ret;
#ifdef CONFIG_LIBCAP
/* if we're run from an suid binary, immediately drop privileges preserving
@@ -272,9 +274,10 @@ int main(int argc, char **argv)
/* parse default acl file */
QSIMPLEQ_INIT(&acl_list);
- if (parse_acl_file(DEFAULT_ACL_FILE, &acl_list) == -1) {
- fprintf(stderr, "failed to parse default acl file `%s'\n",
- DEFAULT_ACL_FILE);
+ ret = parse_acl_file(DEFAULT_ACL_FILE, &acl_list);
+ if (ret < 0) {
+ fprintf(stderr, "failed to parse default acl file `%s': %s\n",
+ DEFAULT_ACL_FILE, strerror(ret));
ret = EXIT_FAILURE;
goto cleanup;
}
@@ -416,6 +419,7 @@ int main(int argc, char **argv)
/* ... */
/* profit! */
+ ret = EXIT_SUCCESS;
cleanup:
--
1.8.1.5
- [Qemu-devel] [PATCHv2 2/2] bridge helper: support conf dirs, (continued)
- [Qemu-devel] [PATCHv2 2/2] bridge helper: support conf dirs, Doug Goldstein, 2013/03/02
- [Qemu-devel] [PATCHv3 0/2] bridge helper: includedir conf arg, Doug Goldstein, 2013/03/07
- [Qemu-devel] [PATCHv3 1/2] bridge helper: unified error cleanup for parse_acl_file, Doug Goldstein, 2013/03/07
- [Qemu-devel] [PATCHv3 2/2] bridge helper: support conf dirs, Doug Goldstein, 2013/03/07
- Re: [Qemu-devel] [PATCHv3 0/2] bridge helper: includedir conf arg, Stefan Hajnoczi, 2013/03/07
- Re: [Qemu-devel] [PATCHv3 0/2] bridge helper: includedir conf arg, Corey Bryant, 2013/03/07
- [Qemu-devel] [PATCH v3 0/2] bridge helper: includedir conf arg, Doug Goldstein, 2013/03/18