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);
}