Revision cb7cf0e3

b/qemu-nbd.c
112 112
    uint8_t data[512];
113 113
    int i;
114 114
    int ext_partnum = 4;
115
    int ret;
115 116

  
116
    if (bdrv_read(bs, 0, data, 1))
117
        errx(EXIT_FAILURE, "error while reading");
117
    if ((ret = bdrv_read(bs, 0, data, 1)) < 0) {
118
        errno = -ret;
119
        err(EXIT_FAILURE, "error while reading");
120
    }
118 121

  
119 122
    if (data[510] != 0x55 || data[511] != 0xaa) {
120 123
        errno = -EINVAL;
......
132 135
            uint8_t data1[512];
133 136
            int j;
134 137

  
135
            if (bdrv_read(bs, mbr[i].start_sector_abs, data1, 1))
136
                errx(EXIT_FAILURE, "error while reading");
138
            if ((ret = bdrv_read(bs, mbr[i].start_sector_abs, data1, 1)) < 0) {
139
                errno = -ret;
140
                err(EXIT_FAILURE, "error while reading");
141
            }
137 142

  
138 143
            for (j = 0; j < 4; j++) {
139 144
                read_partition(&data1[446 + 16 * j], &ext[j]);
......
316 321
    if (disconnect) {
317 322
        fd = open(argv[optind], O_RDWR);
318 323
        if (fd == -1)
319
            errx(EXIT_FAILURE, "Cannot open %s", argv[optind]);
324
            err(EXIT_FAILURE, "Cannot open %s", argv[optind]);
320 325

  
321 326
        nbd_disconnect(fd);
322 327

  
......
333 338
    if (bs == NULL)
334 339
        return 1;
335 340

  
336
    if (bdrv_open(bs, argv[optind], flags, NULL) < 0)
337
        return 1;
341
    if ((ret = bdrv_open(bs, argv[optind], flags, NULL)) < 0) {
342
        errno = -ret;
343
        err(EXIT_FAILURE, "Failed to bdrv_open '%s'", argv[optind]);
344
    }
338 345

  
339 346
    fd_size = bs->total_sectors * 512;
340 347

  
341 348
    if (partition != -1 &&
342 349
        find_partition(bs, partition, &dev_offset, &fd_size))
343
        errx(EXIT_FAILURE, "Could not find partition %d", partition);
350
        err(EXIT_FAILURE, "Could not find partition %d", partition);
344 351

  
345 352
    if (device) {
346 353
        pid_t pid;
347 354
        int sock;
348 355

  
356
        /* want to fail before daemonizing */
357
        if (access(device, R_OK|W_OK) == -1) {
358
            err(EXIT_FAILURE, "Could not access '%s'", device);
359
        }
360

  
349 361
        if (!verbose) {
350 362
            /* detach client and server */
351 363
            if (daemon(0, 0) == -1) {
352
                errx(EXIT_FAILURE, "Failed to daemonize");
364
                err(EXIT_FAILURE, "Failed to daemonize");
353 365
            }
354 366
        }
355 367

  
......
372 384
            do {
373 385
                sock = unix_socket_outgoing(socket);
374 386
                if (sock == -1) {
375
                    if (errno != ENOENT && errno != ECONNREFUSED)
387
                    if (errno != ENOENT && errno != ECONNREFUSED) {
388
                        ret = 1;
376 389
                        goto out;
390
                    }
377 391
                    sleep(1);	/* wait children */
378 392
                }
379 393
            } while (sock == -1);

Also available in: Unified diff