aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2015-04-07 13:11:55 -0700
committerRob Landley <rob@landley.net>2015-04-10 20:42:31 -0500
commit6425277b218ceea473baf453e3bfc632a0f518d9 (patch)
tree155e2793c1c9e3099f0192e687ed45b5f0416a29 /toys
parent39d52a8e5a14b322b862c4dbd43053699db90e70 (diff)
downloadtoybox-6425277b218ceea473baf453e3bfc632a0f518d9.tar.gz
Fix load_policy error reporting.
Also switch to xopen for O_CLOEXEC paranoia and to avoid a conditional. Change-Id: Iee5c4c124bcac800313f586768ffcaade542bd22
Diffstat (limited to 'toys')
-rw-r--r--toys/android/load_policy.c15
1 files changed, 5 insertions, 10 deletions
diff --git a/toys/android/load_policy.c b/toys/android/load_policy.c
index aa59f36c..84967360 100644
--- a/toys/android/load_policy.c
+++ b/toys/android/load_policy.c
@@ -20,18 +20,13 @@ config LOAD_POLICY
void load_policy_main(void)
{
char *path = *toys.optargs;
- char *policy_data = 0;
- off_t policy_len;
- int fd;
-
- if ((fd = open(path, O_RDONLY)) != -1) {
- policy_len = fdlength(fd);
- policy_data = mmap(0, policy_len, PROT_READ, MAP_PRIVATE, fd, 0);
- close(fd);
- }
+ int fd = xopen(path, O_RDONLY);
+ off_t policy_len = fdlength(fd);
+ char *policy_data = mmap(0, policy_len, PROT_READ, MAP_PRIVATE, fd, 0);
+ close(fd);
if (!policy_data || security_load_policy(policy_data, policy_len) < 0)
- perror_exit("Couldn't %s %s: %s", policy_data ? "load" : "read", path);
+ perror_exit("Couldn't %s %s", policy_data ? "load" : "read", path);
munmap(policy_data, policy_len);
}