int ret;
if ((ret = blk_read(blk, 0, data, 1)) < 0) {
- errno = -ret;
- error_report("error while reading: %s", strerror(errno));
+ error_report("error while reading: %s", strerror(-ret));
exit(EXIT_FAILURE);
}
int j;
if ((ret = blk_read(blk, mbr[i].start_sector_abs, data1, 1)) < 0) {
- errno = -ret;
- error_report("error while reading: %s", strerror(errno));
+ error_report("error while reading: %s", strerror(-ret));
exit(EXIT_FAILURE);
}
fd = open(device, O_RDWR);
if (fd < 0) {
/* Linux-only, we can use %m in printf. */
- fprintf(stderr, "Failed to open %s: %m\n", device);
+ error_report("Failed to open %s: %m", device);
goto out_socket;
}
return;
}
- if (nbd_client_new(exp, fd, nbd_client_closed)) {
- nb_fds++;
- nbd_update_server_fd_handler(server_fd);
- } else {
- shutdown(fd, 2);
- close(fd);
- }
+ nb_fds++;
+ nbd_update_server_fd_handler(server_fd);
+ nbd_client_new(exp, fd, nbd_client_closed);
}
static void nbd_update_server_fd_handler(int fd)
BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF,
&local_err);
if (local_err) {
- error_report("Failed to parse detect_zeroes mode: %s",
- error_get_pretty(local_err));
+ error_reportf_err(local_err,
+ "Failed to parse detect_zeroes mode: ");
exit(EXIT_FAILURE);
}
if (detect_zeroes == BLOCKDEV_DETECT_ZEROES_OPTIONS_UNMAP &&
case 'k':
sockpath = optarg;
if (sockpath[0] != '/') {
- error_report("socket path must be absolute\n");
+ error_report("socket path must be absolute");
exit(EXIT_FAILURE);
}
break;
exit(EXIT_FAILURE);
}
if (shared < 1) {
- error_report("Shared device number must be greater than 0\n");
+ error_report("Shared device number must be greater than 0");
exit(EXIT_FAILURE);
}
break;
}
if ((argc - optind) != 1) {
- error_report("Invalid number of argument.\n"
- "Try `%s --help' for more information.",
- argv[0]);
+ error_report("Invalid number of arguments");
+ error_printf("Try `%s --help' for more information.\n", argv[0]);
exit(EXIT_FAILURE);
}
srcpath = argv[optind];
blk = blk_new_open("hda", srcpath, NULL, options, flags, &local_err);
if (!blk) {
- error_report("Failed to blk_new_open '%s': %s", argv[optind],
- error_get_pretty(local_err));
+ error_reportf_err(local_err, "Failed to blk_new_open '%s': ",
+ argv[optind]);
exit(EXIT_FAILURE);
}
bs = blk_bs(blk);
&local_err);
}
if (ret < 0) {
- errno = -ret;
- error_report("Failed to load snapshot: %s: %s",
- error_get_pretty(local_err), strerror(errno));
+ error_reportf_err(local_err, "Failed to load snapshot: ");
exit(EXIT_FAILURE);
}
if (partition != -1) {
ret = find_partition(blk, partition, &dev_offset, &fd_size);
if (ret < 0) {
- errno = -ret;
error_report("Could not find partition %d: %s", partition,
- strerror(errno));
+ strerror(-ret));
exit(EXIT_FAILURE);
}
}