Revision bc4a957c os-posix.c

b/os-posix.c
361 361

  
362 362
    return qemu_pipe(fds);
363 363
}
364

  
365
int qemu_create_pidfile(const char *filename)
366
{
367
    char buffer[128];
368
    int len;
369
    int fd;
370

  
371
    fd = qemu_open(filename, O_RDWR | O_CREAT, 0600);
372
    if (fd == -1) {
373
        return -1;
374
    }
375
    if (lockf(fd, F_TLOCK, 0) == -1) {
376
        return -1;
377
    }
378
    len = snprintf(buffer, sizeof(buffer), "%ld\n", (long)getpid());
379
    if (write(fd, buffer, len) != len) {
380
        return -1;
381
    }
382

  
383
    return 0;
384
}

Also available in: Unified diff