debuggers.hg

view tools/libxl/libxl_xshelp.c @ 21067:b4a1832a916f

Update Xen version to 4.0.0-rc6
author Keir Fraser <keir.fraser@citrix.com>
date Tue Mar 09 18:18:05 2010 +0000 (2010-03-09)
parents 819c21064517
children a6ed354be9e3
line source
1 /*
2 * Copyright (C) 2009 Citrix Ltd.
3 * Author Vincent Hanquez <vincent.hanquez@eu.citrix.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published
7 * by the Free Software Foundation; version 2.1 only. with the special
8 * exception on linking described in file LICENSE.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 */
16 #include "libxl_osdeps.h"
18 #include <string.h>
19 #include <stddef.h>
20 #include <stdio.h>
21 #include <stdarg.h>
23 #include "libxl.h"
24 #include "libxl_internal.h"
26 int xs_writev(struct xs_handle *xsh, xs_transaction_t t, char *dir, char *kvs[])
27 {
28 char *path;
29 int i;
31 if (!kvs)
32 return 0;
34 for (i = 0; kvs[i] != NULL; i += 2) {
35 asprintf(&path, "%s/%s", dir, kvs[i]);
36 if (path) {
37 int length = strlen(kvs[i + 1]);
38 xs_write(xsh, t, path, kvs[i + 1], length);
39 free(path);
40 }
41 }
42 return 0;
43 }
45 char **libxl_xs_kvs_of_flexarray(struct libxl_ctx *ctx, flexarray_t *array, int length)
46 {
47 char **kvs;
48 int i;
50 kvs = libxl_calloc(ctx, length + 2, sizeof(char *));
51 if (kvs) {
52 for (i = 0; i < length; i += 2) {
53 void *ptr;
55 flexarray_get(array, i, &ptr);
56 kvs[i] = (char *) ptr;
57 flexarray_get(array, i + 1, &ptr);
58 kvs[i + 1] = (char *) ptr;
59 }
60 kvs[i] = NULL;
61 kvs[i + 1] = NULL;
62 }
63 return kvs;
64 }
66 int libxl_xs_writev(struct libxl_ctx *ctx, xs_transaction_t t,
67 char *dir, char *kvs[])
68 {
69 char *path;
70 int i;
72 if (!kvs)
73 return 0;
75 for (i = 0; kvs[i] != NULL; i += 2) {
76 path = libxl_sprintf(ctx, "%s/%s", dir, kvs[i]);
77 if (path) {
78 int length = strlen(kvs[i + 1]);
79 xs_write(ctx->xsh, t, path, kvs[i + 1], length);
80 }
81 libxl_free(ctx, path);
82 }
83 return 0;
84 }
86 int libxl_xs_write(struct libxl_ctx *ctx, xs_transaction_t t,
87 char *path, char *fmt, ...)
88 {
89 char *s;
90 va_list ap;
91 int ret;
92 va_start(ap, fmt);
93 ret = vasprintf(&s, fmt, ap);
94 va_end(ap);
96 if (ret == -1) {
97 return -1;
98 }
99 xs_write(ctx->xsh, t, path, s, ret);
100 free(s);
101 return 0;
102 }
104 char * libxl_xs_read(struct libxl_ctx *ctx, xs_transaction_t t, char *path)
105 {
106 unsigned int len;
107 char *ptr;
109 ptr = xs_read(ctx->xsh, t, path, &len);
110 if (ptr != NULL) {
111 libxl_ptr_add(ctx, ptr);
112 return ptr;
113 }
114 return 0;
115 }
117 char *libxl_xs_get_dompath(struct libxl_ctx *ctx, uint32_t domid)
118 {
119 char *s = xs_get_domain_path(ctx->xsh, domid);
120 if (!s) {
121 XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "failed to get dompath for %lu",
122 domid);
123 return NULL;
124 }
125 libxl_ptr_add(ctx, s);
126 return s;
127 }
129 char **libxl_xs_directory(struct libxl_ctx *ctx, xs_transaction_t t, char *path, unsigned int *nb)
130 {
131 char **ret = NULL;
132 ret = xs_directory(ctx->xsh, XBT_NULL, path, nb);
133 libxl_ptr_add(ctx, ret);
134 return ret;
135 }