/* _atonce creates a transaction and writes all keys at once */
_hidden int libxl__xs_writev_atonce(libxl__gc *gc,
const char *dir, char **kvs);
-
-_hidden int libxl__xs_printf(libxl__gc *gc, xs_transaction_t t,
- const char *path, const char *fmt, ...) PRINTF_ATTRIBUTE(4, 5);
/* Each fn returns 0 on success.
* On error: returns -1, sets errno (no logging) */
* fails it logs and returns ERROR_FAIL.
*/
+int libxl__xs_vprintf(libxl__gc *gc, xs_transaction_t t,
+ const char *path, const char *fmt, va_list ap);
+int libxl__xs_printf(libxl__gc *gc, xs_transaction_t t,
+ const char *path, const char *fmt, ...) PRINTF_ATTRIBUTE(4, 5);
+
/* On success, path will exist and will have an empty value */
int libxl__xs_mknod(libxl__gc *gc, xs_transaction_t t,
const char *path, struct xs_permissions *perms,
}
-int libxl__xs_printf(libxl__gc *gc, xs_transaction_t t,
- const char *path, const char *fmt, ...)
+int libxl__xs_vprintf(libxl__gc *gc, xs_transaction_t t,
+ const char *path, const char *fmt, va_list ap)
{
libxl_ctx *ctx = libxl__gc_owner(gc);
char *s;
+ bool ok;
+
+ s = libxl__vsprintf(gc, fmt, ap);
+
+ ok = xs_write(ctx->xsh, t, path, s, strlen(s));
+ if (!ok) {
+ LOGE(ERROR, "xenstore write failed: `%s' = `%s'", path, s);
+ return ERROR_FAIL;
+ }
+
+ return 0;
+}
+
+int libxl__xs_printf(libxl__gc *gc, xs_transaction_t t,
+ const char *path, const char *fmt, ...)
+{
va_list ap;
- int ret;
+ int rc;
+
va_start(ap, fmt);
- ret = vasprintf(&s, fmt, ap);
+ rc = libxl__xs_vprintf(gc, t, path, fmt, ap);
va_end(ap);
- if (ret == -1) {
- return -1;
- }
- xs_write(ctx->xsh, t, path, s, ret);
- free(s);
- return 0;
+ return rc;
}
char * libxl__xs_read(libxl__gc *gc, xs_transaction_t t, const char *path)