当前位置: 首页>>代码示例>>C++>>正文


C++ xs_read函数代码示例

本文整理汇总了C++中xs_read函数的典型用法代码示例。如果您正苦于以下问题:C++ xs_read函数的具体用法?C++ xs_read怎么用?C++ xs_read使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了xs_read函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: xs_open

char *get_vm_name(int dom, int *target_dom)
{
	struct xs_handle *xs;
	char buf[64];
	char *name;
	char *target_dom_str;
	unsigned int len = 0;

	xs = xs_open(0);
	if (!xs) {
		perror("xs_daemon_open");
		exit(1);
	}
	snprintf(buf, sizeof(buf), "/local/domain/%d/target", dom);
	target_dom_str = xs_read(xs, 0, buf, &len);
	if (target_dom_str) {
		errno = 0;
		*target_dom = strtol(target_dom_str, (char **) NULL, 10);
		if (errno != 0) {
			perror("strtol");
			exit(1);
		}
	} else
		*target_dom = dom;
	snprintf(buf, sizeof(buf), "/local/domain/%d/name", *target_dom);
	name = xs_read(xs, 0, buf, &len);
	if (!name) {
		perror("xs_read domainname");
		exit(1);
	}
	xs_close(xs);
	return name;
}
开发者ID:joesaland,项目名称:qubes-gui-agent-xen-hvm-stubdom,代码行数:33,代码来源:txrx-vchan.c

示例2: xs_get_domain_path

char *xenstore_vm_read(int domid, char *key, unsigned int *len)
{
    char *buf = NULL, *path = NULL, *value = NULL;

    if (xsh == NULL)
        goto out;

    path = xs_get_domain_path(xsh, domid);
    if (path == NULL) {
        fprintf(logfile, "xs_get_domain_path(%d): error\n", domid);
        goto out;
    }

    pasprintf(&buf, "%s/vm", path);
    free(path);
    path = xs_read(xsh, XBT_NULL, buf, NULL);
    if (path == NULL) {
        fprintf(logfile, "xs_read(%s): read error\n", buf);
        goto out;
    }

    pasprintf(&buf, "%s/%s", path, key);
    value = xs_read(xsh, XBT_NULL, buf, len);
    if (value == NULL) {
        fprintf(logfile, "xs_read(%s): read error\n", buf);
        goto out;
    }

 out:
    free(path);
    free(buf);
    return value;
}
开发者ID:B-Rich,项目名称:afterburner,代码行数:33,代码来源:xenstore.c

示例3: xenStoreDomainGetDiskID

/*
 * xenStoreDomainGetDiskID:
 * @conn: pointer to the connection.
 * @id: the domain id
 * @dev: the virtual block device name
 *
 * Get the reference (i.e. the string number) for the device on that domain
 * which uses the given virtual block device name
 *
 * The caller must hold the lock on the privateData
 * associated with the 'conn' parameter.
 *
 * Returns the new string or NULL in case of error, the string must be
 *         freed by the caller.
 */
char *
xenStoreDomainGetDiskID(virConnectPtr conn, int id, const char *dev)
{
    char dir[80], path[128], **list = NULL, *val = NULL;
    unsigned int devlen, len, num;
    size_t i;
    char *ret = NULL;
    xenUnifiedPrivatePtr priv = conn->privateData;

    if (id < 0 || priv->xshandle == NULL || dev == NULL)
        return NULL;
    devlen = strlen(dev);
    if (devlen <= 0)
        return NULL;

    snprintf(dir, sizeof(dir), "/local/domain/0/backend/vbd/%d", id);
    list = xs_directory(priv->xshandle, 0, dir, &num);
    if (list != NULL) {
        for (i = 0; i < num; i++) {
            snprintf(path, sizeof(path), "%s/%s/%s", dir, list[i], "dev");
            val = xs_read(priv->xshandle, 0, path, &len);
            if (val == NULL)
                break;
            if ((devlen != len) || memcmp(val, dev, len)) {
                VIR_FREE(val);
            } else {
                ignore_value(VIR_STRDUP(ret, list[i]));

                VIR_FREE(val);
                VIR_FREE(list);
                return ret;
            }
        }
        VIR_FREE(list);
    }
    snprintf(dir, sizeof(dir), "/local/domain/0/backend/tap/%d", id);
    list = xs_directory(priv->xshandle, 0, dir, &num);
    if (list != NULL) {
        for (i = 0; i < num; i++) {
            snprintf(path, sizeof(path), "%s/%s/%s", dir, list[i], "dev");
            val = xs_read(priv->xshandle, 0, path, &len);
            if (val == NULL)
                break;
            if ((devlen != len) || memcmp(val, dev, len)) {
                VIR_FREE(val);
            } else {
                ignore_value(VIR_STRDUP(ret, list[i]));

                VIR_FREE(val);
                VIR_FREE(list);
                return ret;
            }
        }
        VIR_FREE(list);
    }
    return NULL;
}
开发者ID:TelekomCloud,项目名称:libvirt,代码行数:72,代码来源:xs_internal.c

示例4: read_param

static char* read_param(const char *paramname) {
    char keybuf[128];
    unsigned int len;
    int my_domid;

    my_domid = atoi(xs_read(xsh, 0, "domid", &len));
    snprintf(keybuf, sizeof(keybuf), "/local/domain/0/backend/audio/%d/%d/%s", my_domid, device_id, paramname);
    /* remember to free lvalue! */
    return xs_read(xsh, 0, keybuf, &len);
}
开发者ID:Oboyma,项目名称:pulseaudio,代码行数:10,代码来源:module-xenpv-sink.c

示例5: wait_for_backend_state_change

static int wait_for_backend_state_change() {
    char keybuf[128];
    int my_domid;
    unsigned int len;

    int backend_state;
    int seconds;
    char *buf, **vec;
    int ret;

    int xs_fd;
    struct timeval tv;
	fd_set watch_fdset;
    int start, now;

    backend_state = STATE_UNDEFINED;
    xs_fd = xs_fileno(xsh);
    start = now = time(NULL);

    my_domid = atoi(xs_read(xsh, 0, "domid", &len));
    snprintf(keybuf, sizeof(keybuf), "/local/domain/0/backend/audio/%d/%d/state", my_domid, device_id);

    /*XXX: hardcoded */
    seconds = 10;
	do {
		tv.tv_usec = 0;
		tv.tv_sec = (start + seconds) - now;
		FD_ZERO(&watch_fdset);
		FD_SET(xs_fd, &watch_fdset);
        ret=select(xs_fd + 1, &watch_fdset, NULL, NULL, &tv);

        if (ret==-1)
            /* error */
            return -1;
        else if (ret) {

			/* Read the watch to drain the buffer */
			vec = xs_read_watch(xsh, &len);

            buf = xs_read(xsh, XBT_NULL, vec[0], &len);
            if (buf == 0) {
                /* usually means that the backend isn't there yet */
                continue;
            };
            backend_state = atoi(buf);

            free(buf);
            free(vec);
		}
        /* else: timeout */
	} while (backend_state == STATE_UNDEFINED && \
            (now = time(NULL)) < start + seconds);

    return backend_state;
}
开发者ID:Oboyma,项目名称:pulseaudio,代码行数:55,代码来源:module-xenpv-sink.c

示例6: getMyDomId

ivc_connection_t *makeConnection(libIVC_t *iface,
                                 char *name,
                                 ivc_contype_t type,
                                 float per)
{
  char *key, *val, *rdomstr = NULL, *rrefstr = NULL, *rpstr = NULL;
  uint32_t me, other, num_refs, *grants;
  struct xs_permissions perms;
  ivc_connection_t *res;
  evtchn_port_t port;
  unsigned int len;
  void *buffer;

  /* me <- xsGetDomId */
  me = getMyDomId(iface);
  /* removePath xs targetPath */
  ASPRINTF(&key, "/rendezvous/%s", name);
  xs_rm(iface->xs, 0, key);
  /* xsMakeDirectory xs targetPath */
  xs_mkdir(iface->xs, 0, key);
  /* xsSetPermissions xs targetPath [ReadWritePerm me] */
  perms.id = me;
  perms.perms = XS_PERM_READ | XS_PERM_WRITE;
  xs_set_permissions(iface->xs, 0, key, &perms, 1);
  /* xsWrite xs (targetPath ++ "/LeftDomId") (show me) */
  free(key), ASPRINTF(&key, "/rendezvous/%s/LeftDomId", name);
             ASPRINTF(&val, "dom%d", me);
  xs_write(iface->xs, 0, key, val, strlen(val));
  /* other <- read <$> waitForKey xs (targetPAth ++ "/RightDomId") */
  free(key), ASPRINTF(&key, "/rendezvous/%s/RightDomId", name);
  while(!rdomstr) { rdomstr = xs_read(iface->xs, 0, key, &len); };
  sscanf(rdomstr, "dom%d", &other);
  /* grants <- read <$> waitForKey xs (targetPAth ++ "/RightGrantRefs") */
  free(key), ASPRINTF(&key, "/rendezvous/%s/RightGrantRefs", name);
  while(!rrefstr) { rrefstr = xs_read(iface->xs, 0, key, &len); }
  grants = parseRefs(rrefstr, &num_refs);
  buffer = xc_gnttab_map_domain_grant_refs(iface->gt, num_refs, other, grants,
                                           PROT_READWRITE);
  assert(buffer);
  /* ports  <- read <$> waitForKey xs (targetPAth ++ "/RightPorts") */
  free(key), ASPRINTF(&key, "/rendezvous/%s/RightPorts", name);
  while(!rpstr) { rpstr = xs_read(iface->xs, 0, key, &len); }
  sscanf(rpstr, "[echan:%d]", &port);
  port = xc_evtchn_bind_interdomain(iface->ec, other, port);
  assert(port >= 0);
  /* res <- acceptConnection other grants ports extra */
  res = buildChannel(iface, other, type, port, buffer, num_refs * 4096, per, 0);
  /* xsWrite xs (targetPath ++ "/LeftConnectionConfirmed") "True" */
  free(key), ASPRINTF(&key, "/rendezvous/%s/LeftConnectionConfirmed", name);
  free(val), ASPRINTF(&val, "True");
  xs_write(iface->xs, 0, key, val, strlen(val));
  /* return res */
  return res;
}
开发者ID:AlexanderAA,项目名称:HaLVM,代码行数:54,代码来源:libIVC.c

示例7: xenstore_read_vncpasswd

int xenstore_read_vncpasswd(int domid, char *pwbuf, size_t pwbuflen)
{
    char *buf = NULL, *path, *uuid = NULL, *passwd = NULL;
    unsigned int i, len, rc = 0;

    if (xsh == NULL) {
        return -1;
    }

    path = xs_get_domain_path(xsh, domid);
    if (path == NULL) {
        fprintf(logfile, "xs_get_domain_path() error. domid %d.\n", domid);
        return -1;
    }

    pasprintf(&buf, "%s/vm", path);
    uuid = xs_read(xsh, XBT_NULL, buf, &len);
    if (uuid == NULL) {
        fprintf(logfile, "xs_read(): uuid get error. %s.\n", buf);
        free(path);
        return -1;
    }

    pasprintf(&buf, "%s/vncpasswd", uuid);
    passwd = xs_read(xsh, XBT_NULL, buf, &len);
    if (passwd == NULL) {
        fprintf(logfile, "xs_read(): vncpasswd get error. %s.\n", buf);
        pwbuf[0] = '\0';
        free(uuid);
        free(path);
        return rc;
    }

    for (i=0; i<len && i<pwbuflen; i++) {
        pwbuf[i] = passwd[i];
    }
    pwbuf[len < (pwbuflen-1) ? len : (pwbuflen-1)] = '\0';
    passwd[0] = '\0';
    pasprintf(&buf, "%s/vncpasswd", uuid);
    if (xs_write(xsh, XBT_NULL, buf, passwd, len) == 0) {
        fprintf(logfile, "xs_write() vncpasswd failed.\n");
        rc = -1;
    }

    free(passwd);
    free(uuid);
    free(path);

    return rc;
}
开发者ID:B-Rich,项目名称:afterburner,代码行数:50,代码来源:xenstore.c

示例8: do_read

/*  wrapper around xs_read
 */
static char*
do_read (xs_handle_t *xsh, char* path)
{
        char *val = NULL, *san_val = NULL, *tmp = NULL;
        static struct expanding_buffer ebuf = { 0, };
        unsigned len = 0;

        val = xs_read (xsh, 0, path, &len);
        if (val == NULL) {
                syslog (LOG_WARNING,
                        "xs_read on %s returned null",
                        path);
                return NULL;
        }
        san_val = sanitise_value (&ebuf, val, len);
        if (san_val == NULL) {
                syslog (LOG_CRIT, "sanitise_value returned NULL");
                free (val);
                return NULL;
        }
        tmp = strdup (san_val);
        /*  don't free san_val  */
        free (val);
        return tmp;
}
开发者ID:cjp256,项目名称:xenclient-oe,代码行数:27,代码来源:svirt-interpose.c

示例9: xenStoreDomainGetUUID

/*
 * The caller must hold the lock on the privateData
 * associated with the 'conn' parameter.
 */
int
xenStoreDomainGetUUID(virConnectPtr conn, int id, unsigned char *uuid)
{
    char prop[200];
    xenUnifiedPrivatePtr priv = conn->privateData;
    unsigned int len;
    char *uuidstr;
    int ret = 0;

    if (priv->xshandle == NULL)
        return -1;

    snprintf(prop, 199, "/local/domain/%d/vm", id);
    prop[199] = 0;
    /* This will return something like
     * /vm/00000000-0000-0000-0000-000000000000[-*] */
    uuidstr = xs_read(priv->xshandle, 0, prop, &len);
    /* Strip optional version suffix when VM was renamed */
    if (len > 40) /* strlen('/vm/') + VIR_UUID_STRING_BUFLEN - sizeof('\0') */
        uuidstr[40] = '\0';

    /* remove "/vm/" */
    ret = virUUIDParse(uuidstr + 4, uuid);

    VIR_FREE(uuidstr);

    return ret;
}
开发者ID:TelekomCloud,项目名称:libvirt,代码行数:32,代码来源:xs_internal.c

示例10: xen_battery_init_mode

/* This function initializes the mode of the power management. */
static int32_t xen_battery_init_mode(struct xen_battery_manager *xbm)
{
    char dompath[XEN_BUFSIZE];
    char *value = NULL;

    /* xen_extended_power_mgmt xenstore entry indicates whether or not extended
     * power management support is requested for the hvm guest.  Extended power
     * management support includes power management support beyond S3, S4, S5.
     * A value of 1 indicates pass-through pm support where upon pm resources
     * are mapped to the guest as appropriate where as a value of 2 as set in
     * non pass-through mode, requires qemu to take the onus of responding to
     * relevant pm port reads/writes. */
    if (0 > snprintf(dompath, sizeof(dompath),
                     "/local/domain/0/device-model/%d/xen_extended_power_mgmt",
                     xen_domid)) {
        XBM_ERROR_MSG("snprintf failed\n");
        return -1;
    }

    value = xs_read(xenstore, XBT_NULL, dompath, NULL);

    if (NULL == value) {
        XBM_ERROR_MSG("unable to read the content of \"%s\"\n", dompath);
        return -1;
    }

    xbm->mode = strtoull(value, NULL, 10);

    free(value);

    return 0;
}
开发者ID:rossphilipson,项目名称:travail,代码行数:33,代码来源:xen_acpi_pm.c

示例11: xenStoreDomainGetPCIID

/*
 * xenStoreDomainGetPCIID:
 * @conn: pointer to the connection.
 * @id: the domain id
 * @bdf: the PCI BDF
 *
 * Get the reference (i.e. the string number) for the device on that domain
 * which uses the given PCI address
 *
 * The caller must hold the lock on the privateData
 * associated with the 'conn' parameter.
 *
 * Returns the new string or NULL in case of error, the string must be
 *         freed by the caller.
 */
char *
xenStoreDomainGetPCIID(virConnectPtr conn, int id, const char *bdf)
{
    char dir[80], path[128], **list = NULL, *val = NULL;
    unsigned int len, num;
    size_t i;
    char *ret = NULL;
    xenUnifiedPrivatePtr priv = conn->privateData;

    if (id < 0 || priv->xshandle == NULL || bdf == NULL)
        return NULL;

    snprintf(dir, sizeof(dir), "/local/domain/0/backend/pci/%d", id);
    list = xs_directory(priv->xshandle, 0, dir, &num);
    if (list == NULL)
        return NULL;
    for (i = 0; i < num; i++) {
        snprintf(path, sizeof(path), "%s/%s/%s", dir, list[i], "dev-0");
        if ((val = xs_read(priv->xshandle, 0, path, &len)) == NULL)
            break;

        bool match = STREQ(val, bdf);

        VIR_FREE(val);

        if (match) {
            ignore_value(VIR_STRDUP(ret, list[i]));
            break;
        }
    }

    VIR_FREE(list);
    return ret;
}
开发者ID:TelekomCloud,项目名称:libvirt,代码行数:49,代码来源:xs_internal.c

示例12: check_bd_connected

/* In Xenstore, /local/domain/0/backend/vbd/<domid>/<device>/state,
 * if available, must be XenbusStateConnected (= 4), otherwise there
 * is no connected device.
 */
static int
check_bd_connected (xenUnifiedPrivatePtr priv, int device, int domid)
{
    char s[256], *rs;
    int r;
    unsigned len = 0;

    /* This code assumes we're connected if we can't get to
     * xenstore, etc.
     */
    if (!priv->xshandle) return 1;
    snprintf (s, sizeof s, "/local/domain/0/backend/vbd/%d/%d/state",
              domid, device);
    s[sizeof s - 1] = '\0';

    rs = xs_read (priv->xshandle, 0, s, &len);
    if (!rs) return 1;
    if (len == 0) {
        /* Hmmm ... we can get to xenstore but it returns an empty
         * string instead of an error.  Assume it's not connected
         * in this case.
         */
        VIR_FREE(rs);
        return 0;
    }

    r = STREQ (rs, "4");
    VIR_FREE(rs);
    return r;
}
开发者ID:rbu,项目名称:libvirt,代码行数:34,代码来源:block_stats.c

示例13: get_pty_fd

static int get_pty_fd(struct xs_handle *xs, char *path, int seconds)
/* Check for a pty in xenstore, open it and return its fd.
 * Assumes there is already a watch set in the store for this path. */
{
	struct timeval tv;
	fd_set watch_fdset;
	int xs_fd = xs_fileno(xs), pty_fd = -1;
	int start, now;
	unsigned int len = 0;
	char *pty_path, **watch_paths;;

	start = now = time(NULL);
	do {
		tv.tv_usec = 0;
		tv.tv_sec = (start + seconds) - now;
		FD_ZERO(&watch_fdset);
		FD_SET(xs_fd, &watch_fdset);
		if (select(xs_fd + 1, &watch_fdset, NULL, NULL, &tv)) {
			/* Read the watch to drain the buffer */
			watch_paths = xs_read_watch(xs, &len);
			free(watch_paths);
			/* We only watch for one thing, so no need to 
			 * disambiguate: just read the pty path */
			pty_path = xs_read(xs, XBT_NULL, path, &len);
			if (pty_path != NULL) {
				pty_fd = open(pty_path, O_RDWR | O_NOCTTY);
				if (pty_fd == -1) 
					err(errno, "Could not open tty `%s'", 
					    pty_path);
				free(pty_path);
			}
		}
	} while (pty_fd == -1 && (now = time(NULL)) < start + seconds);
	return pty_fd;
}
开发者ID:mikesun,项目名称:xen-cow-checkpointing,代码行数:35,代码来源:main.c

示例14: get_pty_fd

static int get_pty_fd(struct xs_handle *xs, char *path, int seconds)
/* Check for a pty in xenstore, open it and return its fd.
 * Assumes there is already a watch set in the store for this path. */
{
	struct timeval tv;
	fd_set watch_fdset;
	int xs_fd = xs_fileno(xs), pty_fd = -1;
	int start, now;
	unsigned int len = 0;
	char *pty_path, **watch_paths;

	start = now = time(NULL);
	do {
		tv.tv_usec = 0;
		tv.tv_sec = (start + seconds) - now;
		FD_ZERO(&watch_fdset);
		FD_SET(xs_fd, &watch_fdset);
		if (select(xs_fd + 1, &watch_fdset, NULL, NULL, &tv)) {
			/* Read the watch to drain the buffer */
			watch_paths = xs_read_watch(xs, &len);
			free(watch_paths);
			/* We only watch for one thing, so no need to 
			 * disambiguate: just read the pty path */
			pty_path = xs_read(xs, XBT_NULL, path, &len);
			if (pty_path != NULL) {
				if (access(pty_path, R_OK|W_OK) != 0)
					continue;
				pty_fd = open(pty_path, O_RDWR | O_NOCTTY);
				if (pty_fd == -1) 
					err(errno, "Could not open tty `%s'", 
					    pty_path);
				free(pty_path);
			}
		}
	} while (pty_fd == -1 && (now = time(NULL)) < start + seconds);

#ifdef __sun__
	if (pty_fd != -1) {
		struct termios term;

		/*
		 * The pty may come from either xend (with pygrub) or
		 * xenconsoled.  It may have tty semantics set up, or not.
		 * While it isn't strictly necessary to have those
		 * semantics here, it is good to have a consistent
		 * state that is the same as under Linux.
		 *
		 * If tcgetattr fails, they have not been set up,
		 * so go ahead and set them up now, by pushing the
		 * ptem and ldterm streams modules.
		 */
		if (tcgetattr(pty_fd, &term) < 0) {
			ioctl(pty_fd, I_PUSH, "ptem");
			ioctl(pty_fd, I_PUSH, "ldterm");
		}
	}
#endif

	return pty_fd;
}
开发者ID:Angel666,项目名称:android_hardware_intel,代码行数:60,代码来源:main.c

示例15: suspend_qemu

static int suspend_qemu(checkpoint_state *s)
{
    char path[128];

    fprintf(stderr, "pausing QEMU\n");

    sprintf(path, "/local/domain/0/device-model/%d/command", s->domid);
    if (!xs_write(s->xsh, XBT_NULL, path, "save", 4)) {
       fprintf(stderr, "error signalling QEMU to save\n");
       return -1;
    }

    sprintf(path, "/local/domain/0/device-model/%d/state", s->domid);

    do {
       char* state;
       unsigned int len;

       state = xs_read(s->xsh, XBT_NULL, path, &len);
       if (!state) {
           s->errstr = "error reading QEMU state";
           return -1;
       }

       if (!strcmp(state, "paused")) {
           free(state);
           return 0;
       }

       free(state);
       usleep(1000);
    } while(1);

    return -1;
}
开发者ID:avasani,项目名称:modified-xen,代码行数:35,代码来源:libcheckpoint.c


注:本文中的xs_read函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。