2009-03-18 13:22:21 +03:00
|
|
|
/* $NetBSD: rumpuser.c,v 1.36 2009/03/18 10:22:45 cegger Exp $ */
|
2007-08-06 02:28:00 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
|
|
|
|
*
|
2007-11-04 21:43:55 +03:00
|
|
|
* Development of this software was supported by Google Summer of Code
|
|
|
|
* and the Finnish Cultural Foundation.
|
2007-08-06 02:28:00 +04:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
|
|
|
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2008-12-18 03:21:52 +03:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#if !defined(lint)
|
2009-03-18 13:22:21 +03:00
|
|
|
__RCSID("$NetBSD: rumpuser.c,v 1.36 2009/03/18 10:22:45 cegger Exp $");
|
2008-12-18 03:21:52 +03:00
|
|
|
#endif /* !lint */
|
|
|
|
|
2007-08-20 19:58:13 +04:00
|
|
|
/* thank the maker for this */
|
|
|
|
#ifdef __linux__
|
|
|
|
#define _XOPEN_SOURCE 500
|
|
|
|
#define _BSD_SOURCE
|
|
|
|
#define _FILE_OFFSET_BITS 64
|
|
|
|
#include <features.h>
|
|
|
|
#endif
|
|
|
|
|
2007-08-07 02:20:57 +04:00
|
|
|
#include <sys/param.h>
|
2009-02-28 18:49:12 +03:00
|
|
|
#include <sys/event.h>
|
2007-08-20 19:58:13 +04:00
|
|
|
#include <sys/ioctl.h>
|
2009-01-23 15:47:32 +03:00
|
|
|
#include <sys/mman.h>
|
2008-10-09 05:19:06 +04:00
|
|
|
#include <sys/uio.h>
|
2007-08-06 02:28:00 +04:00
|
|
|
|
2009-01-23 15:47:32 +03:00
|
|
|
#include <assert.h>
|
2007-08-06 02:28:00 +04:00
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2008-10-03 01:37:59 +04:00
|
|
|
#include <poll.h>
|
2007-08-20 19:58:13 +04:00
|
|
|
#include <stdint.h>
|
2007-08-06 02:28:00 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2007-08-16 02:13:15 +04:00
|
|
|
#include <string.h>
|
2008-06-24 18:11:44 +04:00
|
|
|
#include <time.h>
|
2007-08-06 02:28:00 +04:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2008-10-03 01:37:59 +04:00
|
|
|
#include <rump/rumpuser.h>
|
2007-08-06 02:28:00 +04:00
|
|
|
|
2008-10-03 01:37:59 +04:00
|
|
|
#include "rumpuser_int.h"
|
2007-08-06 02:28:00 +04:00
|
|
|
|
|
|
|
int
|
2009-02-26 03:32:49 +03:00
|
|
|
rumpuser_getfileinfo(const char *path, uint64_t *size, int *ft, int *error)
|
2007-08-06 02:28:00 +04:00
|
|
|
{
|
2009-02-26 03:32:49 +03:00
|
|
|
struct stat sb;
|
|
|
|
int rv;
|
2007-08-06 02:28:00 +04:00
|
|
|
|
2009-02-26 03:32:49 +03:00
|
|
|
rv = stat(path, &sb);
|
|
|
|
if (rv == -1) {
|
|
|
|
*error = errno;
|
|
|
|
return rv;
|
|
|
|
}
|
2007-08-06 02:28:00 +04:00
|
|
|
|
2009-02-26 03:32:49 +03:00
|
|
|
*size = sb.st_size;
|
|
|
|
switch (sb.st_mode & S_IFMT) {
|
|
|
|
case S_IFDIR:
|
|
|
|
*ft = RUMPUSER_FT_DIR;
|
|
|
|
break;
|
|
|
|
case S_IFREG:
|
|
|
|
*ft = RUMPUSER_FT_REG;
|
|
|
|
break;
|
|
|
|
case S_IFBLK:
|
|
|
|
*ft = RUMPUSER_FT_BLK;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*ft = RUMPUSER_FT_OTHER;
|
|
|
|
break;
|
|
|
|
}
|
2007-08-06 02:28:00 +04:00
|
|
|
|
2009-02-26 03:32:49 +03:00
|
|
|
return rv;
|
2007-08-06 02:28:00 +04:00
|
|
|
}
|
|
|
|
|
2008-06-24 18:11:44 +04:00
|
|
|
int
|
2009-02-26 03:32:49 +03:00
|
|
|
rumpuser_nanosleep(uint64_t *sec, uint64_t *nsec, int *error)
|
2008-06-24 18:11:44 +04:00
|
|
|
{
|
2009-02-26 03:32:49 +03:00
|
|
|
struct timespec rqt, rmt;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
/*LINTED*/
|
|
|
|
rqt.tv_sec = *sec;
|
|
|
|
/*LINTED*/
|
|
|
|
rqt.tv_nsec = *nsec;
|
|
|
|
|
|
|
|
KLOCK_WRAP(rv = nanosleep(&rqt, &rmt));
|
|
|
|
if (rv == -1)
|
|
|
|
*error = errno;
|
|
|
|
|
|
|
|
*sec = rmt.tv_sec;
|
|
|
|
*nsec = rmt.tv_nsec;
|
2008-06-24 18:11:44 +04:00
|
|
|
|
2009-02-26 03:32:49 +03:00
|
|
|
return rv;
|
2008-06-24 18:11:44 +04:00
|
|
|
}
|
|
|
|
|
2007-08-06 02:28:00 +04:00
|
|
|
void *
|
2009-01-07 22:49:48 +03:00
|
|
|
rumpuser__malloc(size_t howmuch, int canfail, const char *func, int line)
|
2007-08-06 02:28:00 +04:00
|
|
|
{
|
|
|
|
void *rv;
|
|
|
|
|
|
|
|
rv = malloc(howmuch);
|
|
|
|
if (rv == NULL && canfail == 0) {
|
|
|
|
warn("malloc failed %s (%d)", func, line);
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2007-08-16 02:13:15 +04:00
|
|
|
if (rv)
|
|
|
|
memset(rv, 0, howmuch);
|
|
|
|
|
2007-08-06 02:28:00 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
2009-01-07 22:49:48 +03:00
|
|
|
rumpuser__realloc(void *ptr, size_t howmuch, int canfail,
|
2007-08-06 02:28:00 +04:00
|
|
|
const char *func, int line)
|
|
|
|
{
|
|
|
|
void *rv;
|
|
|
|
|
|
|
|
rv = realloc(ptr, howmuch);
|
|
|
|
if (rv == NULL && canfail == 0) {
|
|
|
|
warn("realloc failed %s (%d)", func, line);
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rumpuser_free(void *ptr)
|
|
|
|
{
|
|
|
|
|
|
|
|
free(ptr);
|
|
|
|
}
|
|
|
|
|
2009-01-23 15:47:32 +03:00
|
|
|
void *
|
|
|
|
rumpuser_anonmmap(size_t size, int alignbit, int exec, int *error)
|
|
|
|
{
|
|
|
|
void *rv;
|
|
|
|
int prot;
|
|
|
|
|
|
|
|
prot = PROT_READ|PROT_WRITE;
|
|
|
|
if (exec)
|
|
|
|
prot |= PROT_EXEC;
|
|
|
|
/* XXX: MAP_ALIGNED() is not portable */
|
|
|
|
rv = mmap(NULL, size, prot, MAP_ANON | MAP_ALIGNED(alignbit), -1, 0);
|
2009-01-27 13:05:08 +03:00
|
|
|
if (rv == MAP_FAILED) {
|
|
|
|
*error = errno;
|
2009-01-23 15:47:32 +03:00
|
|
|
return NULL;
|
2009-01-27 13:05:08 +03:00
|
|
|
}
|
2009-01-23 15:47:32 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rumpuser_unmap(void *addr, size_t len)
|
|
|
|
{
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
rv = munmap(addr, len);
|
|
|
|
assert(rv == 0);
|
|
|
|
}
|
|
|
|
|
2009-02-28 18:49:12 +03:00
|
|
|
void *
|
|
|
|
rumpuser_filemmap(int fd, off_t offset, size_t len, int shared,
|
|
|
|
int dotruncate, int *error)
|
|
|
|
{
|
|
|
|
void *rv;
|
|
|
|
int flags;
|
|
|
|
|
|
|
|
if (dotruncate)
|
|
|
|
ftruncate(fd, offset + len);
|
|
|
|
|
|
|
|
flags = MAP_FILE;
|
|
|
|
if (shared)
|
|
|
|
flags |= MAP_SHARED;
|
|
|
|
else
|
|
|
|
flags |= MAP_PRIVATE;
|
|
|
|
|
|
|
|
rv = mmap(NULL, len, PROT_READ|PROT_WRITE, flags, fd, offset);
|
|
|
|
if (rv == MAP_FAILED) {
|
|
|
|
*error = errno;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*error = 0;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2007-08-06 02:28:00 +04:00
|
|
|
int
|
|
|
|
rumpuser_open(const char *path, int flags, int *error)
|
|
|
|
{
|
|
|
|
|
2009-02-28 18:49:12 +03:00
|
|
|
DOCALL(int, (open(path, flags, 0644)));
|
2007-08-06 02:28:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
rumpuser_ioctl(int fd, u_long cmd, void *data, int *error)
|
|
|
|
{
|
|
|
|
|
2008-10-09 05:19:06 +04:00
|
|
|
DOCALL_KLOCK(int, (ioctl(fd, cmd, data)));
|
2007-08-06 02:28:00 +04:00
|
|
|
}
|
|
|
|
|
2007-09-10 23:11:44 +04:00
|
|
|
int
|
|
|
|
rumpuser_close(int fd, int *error)
|
2007-08-06 02:28:00 +04:00
|
|
|
{
|
|
|
|
|
2007-09-10 23:11:44 +04:00
|
|
|
DOCALL(int, close(fd));
|
2007-08-06 02:28:00 +04:00
|
|
|
}
|
|
|
|
|
2007-09-21 03:43:44 +04:00
|
|
|
int
|
|
|
|
rumpuser_fsync(int fd, int *error)
|
|
|
|
{
|
|
|
|
|
2008-10-09 05:19:06 +04:00
|
|
|
DOCALL_KLOCK(int, fsync(fd));
|
2007-09-21 03:43:44 +04:00
|
|
|
}
|
|
|
|
|
2008-01-02 21:15:12 +03:00
|
|
|
ssize_t
|
|
|
|
rumpuser_read(int fd, void *data, size_t size, int *error)
|
|
|
|
{
|
|
|
|
ssize_t rv;
|
|
|
|
|
2008-10-09 05:19:06 +04:00
|
|
|
KLOCK_WRAP(rv = read(fd, data, size));
|
2008-01-02 21:15:12 +03:00
|
|
|
if (rv == -1)
|
|
|
|
*error = errno;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t
|
|
|
|
rumpuser_pread(int fd, void *data, size_t size, off_t offset, int *error)
|
|
|
|
{
|
|
|
|
ssize_t rv;
|
|
|
|
|
2008-10-09 05:19:06 +04:00
|
|
|
KLOCK_WRAP(rv = pread(fd, data, size, offset));
|
|
|
|
if (rv == -1)
|
|
|
|
*error = errno;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2007-11-04 21:43:55 +03:00
|
|
|
void
|
2008-01-02 21:15:12 +03:00
|
|
|
rumpuser_read_bio(int fd, void *data, size_t size, off_t offset,
|
2008-11-18 15:39:35 +03:00
|
|
|
rump_biodone_fn biodone, void *biodonecookie)
|
2007-08-06 02:28:00 +04:00
|
|
|
{
|
2007-11-04 21:43:55 +03:00
|
|
|
ssize_t rv;
|
2008-01-03 05:38:23 +03:00
|
|
|
int error = 0;
|
2007-11-04 21:43:55 +03:00
|
|
|
|
2008-10-09 05:19:06 +04:00
|
|
|
KLOCK_WRAP(rv = rumpuser_pread(fd, data, size, offset, &error));
|
2007-11-04 21:43:55 +03:00
|
|
|
/* check against <0 instead of ==-1 to get typing below right */
|
2008-01-02 21:15:12 +03:00
|
|
|
if (rv < 0)
|
2007-11-04 21:43:55 +03:00
|
|
|
rv = 0;
|
2008-01-02 21:15:12 +03:00
|
|
|
|
2008-07-29 17:17:40 +04:00
|
|
|
/* LINTED: see above */
|
2008-11-18 15:39:35 +03:00
|
|
|
biodone(biodonecookie, rv, error);
|
2007-08-06 02:28:00 +04:00
|
|
|
}
|
|
|
|
|
2008-01-02 21:15:12 +03:00
|
|
|
ssize_t
|
|
|
|
rumpuser_write(int fd, const void *data, size_t size, int *error)
|
|
|
|
{
|
|
|
|
ssize_t rv;
|
|
|
|
|
2008-10-09 05:19:06 +04:00
|
|
|
KLOCK_WRAP(rv = write(fd, data, size));
|
2008-01-02 21:15:12 +03:00
|
|
|
if (rv == -1)
|
|
|
|
*error = errno;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t
|
|
|
|
rumpuser_pwrite(int fd, const void *data, size_t size, off_t offset, int *error)
|
|
|
|
{
|
|
|
|
ssize_t rv;
|
|
|
|
|
2008-10-09 05:19:06 +04:00
|
|
|
KLOCK_WRAP(rv = pwrite(fd, data, size, offset));
|
|
|
|
if (rv == -1)
|
|
|
|
*error = errno;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2007-11-04 21:43:55 +03:00
|
|
|
void
|
2008-01-02 21:15:12 +03:00
|
|
|
rumpuser_write_bio(int fd, const void *data, size_t size, off_t offset,
|
2008-11-18 15:39:35 +03:00
|
|
|
rump_biodone_fn biodone, void *biodonecookie)
|
2007-08-06 02:28:00 +04:00
|
|
|
{
|
2007-11-04 21:43:55 +03:00
|
|
|
ssize_t rv;
|
2008-01-03 05:38:23 +03:00
|
|
|
int error = 0;
|
2007-11-04 21:43:55 +03:00
|
|
|
|
2008-10-09 05:19:06 +04:00
|
|
|
KLOCK_WRAP(rv = rumpuser_pwrite(fd, data, size, offset, &error));
|
2007-11-04 21:43:55 +03:00
|
|
|
/* check against <0 instead of ==-1 to get typing below right */
|
2008-01-02 21:15:12 +03:00
|
|
|
if (rv < 0)
|
2007-11-04 21:43:55 +03:00
|
|
|
rv = 0;
|
2007-08-06 02:28:00 +04:00
|
|
|
|
2008-07-29 17:17:40 +04:00
|
|
|
/* LINTED: see above */
|
2008-11-18 15:39:35 +03:00
|
|
|
biodone(biodonecookie, rv, error);
|
2007-08-06 02:28:00 +04:00
|
|
|
}
|
|
|
|
|
2009-02-26 03:59:31 +03:00
|
|
|
ssize_t
|
|
|
|
rumpuser_readv(int fd, const struct rumpuser_iovec *riov, int iovcnt,
|
|
|
|
int *error)
|
|
|
|
{
|
|
|
|
struct iovec *iovp;
|
|
|
|
ssize_t rv;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
iovp = malloc(iovcnt * sizeof(struct iovec));
|
|
|
|
if (iovp == NULL) {
|
|
|
|
*error = ENOMEM;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
for (i = 0; i < iovcnt; i++) {
|
|
|
|
iovp[i].iov_base = riov[i].iov_base;
|
|
|
|
/*LINTED*/
|
|
|
|
iovp[i].iov_len = riov[i].iov_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
KLOCK_WRAP(rv = readv(fd, iovp, iovcnt));
|
|
|
|
if (rv == -1)
|
|
|
|
*error = errno;
|
|
|
|
free(iovp);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t
|
|
|
|
rumpuser_writev(int fd, const struct rumpuser_iovec *riov, int iovcnt,
|
|
|
|
int *error)
|
|
|
|
{
|
|
|
|
struct iovec *iovp;
|
|
|
|
ssize_t rv;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
iovp = malloc(iovcnt * sizeof(struct iovec));
|
|
|
|
if (iovp == NULL) {
|
|
|
|
*error = ENOMEM;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
for (i = 0; i < iovcnt; i++) {
|
|
|
|
iovp[i].iov_base = riov[i].iov_base;
|
|
|
|
/*LINTED*/
|
|
|
|
iovp[i].iov_len = riov[i].iov_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
KLOCK_WRAP(rv = writev(fd, iovp, iovcnt));
|
|
|
|
if (rv == -1)
|
|
|
|
*error = errno;
|
|
|
|
free(iovp);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2007-08-06 02:28:00 +04:00
|
|
|
int
|
2009-02-27 18:15:19 +03:00
|
|
|
rumpuser_gettime(uint64_t *sec, uint64_t *nsec, int *error)
|
2007-08-06 02:28:00 +04:00
|
|
|
{
|
2009-02-27 18:15:19 +03:00
|
|
|
struct timeval tv;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
rv = gettimeofday(&tv, NULL);
|
|
|
|
if (rv == -1) {
|
|
|
|
*error = errno;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
*sec = tv.tv_sec;
|
|
|
|
*nsec = tv.tv_usec * 1000;
|
2007-08-06 02:28:00 +04:00
|
|
|
|
2009-02-27 18:15:19 +03:00
|
|
|
return 0;
|
2007-08-06 02:28:00 +04:00
|
|
|
}
|
|
|
|
|
2008-03-11 13:50:16 +03:00
|
|
|
int
|
|
|
|
rumpuser_getenv(const char *name, char *buf, size_t blen, int *error)
|
|
|
|
{
|
|
|
|
|
|
|
|
DOCALL(int, getenv_r(name, buf, blen));
|
|
|
|
}
|
|
|
|
|
2007-08-06 02:28:00 +04:00
|
|
|
int
|
|
|
|
rumpuser_gethostname(char *name, size_t namelen, int *error)
|
|
|
|
{
|
|
|
|
|
|
|
|
DOCALL(int, (gethostname(name, namelen)));
|
|
|
|
}
|
|
|
|
|
2007-08-07 02:20:57 +04:00
|
|
|
char *
|
2007-08-08 00:40:53 +04:00
|
|
|
rumpuser_realpath(const char *path, char resolvedname[MAXPATHLEN], int *error)
|
2007-08-07 02:20:57 +04:00
|
|
|
{
|
2007-08-08 00:40:53 +04:00
|
|
|
char *rv;
|
2007-08-07 02:20:57 +04:00
|
|
|
|
2007-08-08 00:40:53 +04:00
|
|
|
rv = realpath(path, resolvedname);
|
|
|
|
if (rv == NULL)
|
|
|
|
*error = errno;
|
|
|
|
else
|
|
|
|
*error = 0;
|
|
|
|
|
|
|
|
return rv;
|
2007-08-07 02:20:57 +04:00
|
|
|
}
|
2007-08-20 19:58:13 +04:00
|
|
|
|
2008-10-03 01:37:59 +04:00
|
|
|
int
|
|
|
|
rumpuser_poll(struct pollfd *fds, int nfds, int timeout, int *error)
|
|
|
|
{
|
|
|
|
|
2008-10-09 05:19:06 +04:00
|
|
|
DOCALL_KLOCK(int, (poll(fds, (nfds_t)nfds, timeout)));
|
2008-10-03 01:37:59 +04:00
|
|
|
}
|
|
|
|
|
2009-01-02 05:54:13 +03:00
|
|
|
int
|
|
|
|
rumpuser_putchar(int c, int *error)
|
|
|
|
{
|
|
|
|
|
2009-02-28 18:49:12 +03:00
|
|
|
DOCALL(int, (putchar(c)));
|
2009-01-02 05:54:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-03-18 13:22:21 +03:00
|
|
|
rumpuser_panic(void)
|
2009-01-02 05:54:13 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
abort();
|
|
|
|
}
|
2009-01-23 22:19:32 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
rumpuser_seterrno(int error)
|
|
|
|
{
|
|
|
|
|
|
|
|
errno = error;
|
|
|
|
}
|
2009-02-28 18:49:12 +03:00
|
|
|
|
|
|
|
int
|
|
|
|
rumpuser_writewatchfile_setup(int kq, int fd, intptr_t opaque, int *error)
|
|
|
|
{
|
|
|
|
struct kevent kev;
|
|
|
|
|
|
|
|
if (kq == -1) {
|
|
|
|
kq = kqueue();
|
|
|
|
if (kq == -1) {
|
|
|
|
*error = errno;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EV_SET(&kev, fd, EVFILT_VNODE, EV_ADD|EV_ENABLE|EV_CLEAR,
|
|
|
|
NOTE_WRITE, 0, opaque);
|
|
|
|
if (kevent(kq, &kev, 1, NULL, 0, NULL) == -1) {
|
|
|
|
*error = errno;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return kq;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
rumpuser_writewatchfile_wait(int kq, intptr_t *opaque, int *error)
|
|
|
|
{
|
|
|
|
struct kevent kev;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
KLOCK_WRAP(rv = kevent(kq, NULL, 0, &kev, 1, NULL));
|
|
|
|
if (rv == -1) {
|
|
|
|
*error = errno;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opaque)
|
|
|
|
*opaque = kev.udata;
|
|
|
|
return rv;
|
|
|
|
}
|