Revision b32f6c28 qemu-nbd.c

b/qemu-nbd.c
202 202
    socklen_t addr_len = sizeof(addr);
203 203
    off_t fd_size;
204 204
    char *device = NULL;
205
    char *socket = NULL;
206
    char sockpath[128];
205
    char *sockpath = NULL;
207 206
    const char *sopt = "hVb:o:p:rsnP:c:dvk:e:t";
208 207
    struct option lopt[] = {
209 208
        { "help", 0, NULL, 'h' },
......
294 293
                errx(EXIT_FAILURE, "Invalid partition %d", partition);
295 294
            break;
296 295
        case 'k':
297
            socket = optarg;
298
            if (socket[0] != '/')
296
            sockpath = optarg;
297
            if (sockpath[0] != '/')
299 298
                errx(EXIT_FAILURE, "socket path must be absolute\n");
300 299
            break;
301 300
        case 'd':
......
384 383
            }
385 384
        }
386 385

  
387
        if (socket == NULL) {
388
            snprintf(sockpath, sizeof(sockpath), SOCKET_PATH,
389
                     basename(device));
390
            socket = sockpath;
386
        if (sockpath == NULL) {
387
            sockpath = g_malloc(128);
388
            snprintf(sockpath, 128, SOCKET_PATH, basename(device));
391 389
        }
392 390

  
393 391
        pid = fork();
......
401 399
            bdrv_close(bs);
402 400

  
403 401
            do {
404
                sock = unix_socket_outgoing(socket);
402
                sock = unix_socket_outgoing(sockpath);
405 403
                if (sock == -1) {
406 404
                    if (errno != ENOENT && errno != ECONNREFUSED) {
407 405
                        ret = 1;
......
452 450

  
453 451
    sharing_fds = g_malloc((shared + 1) * sizeof(int));
454 452

  
455
    if (socket) {
456
        sharing_fds[0] = unix_socket_incoming(socket);
453
    if (sockpath) {
454
        sharing_fds[0] = unix_socket_incoming(sockpath);
457 455
    } else {
458 456
        sharing_fds[0] = tcp_socket_incoming(bindto, port);
459 457
    }
......
515 513
    close(sharing_fds[0]);
516 514
    bdrv_close(bs);
517 515
    g_free(sharing_fds);
518
    if (socket)
519
        unlink(socket);
516
    if (sockpath) {
517
        unlink(sockpath);
518
    }
520 519

  
521 520
    return 0;
522 521
}

Also available in: Unified diff