ret = build_post(ctx, domid, info, state, vments, localents);
if (ret) goto out;
- if (info->hvm)
- asprintf(&(dm_info->saved_state), "/var/lib/xen/qemu-save.%d", domid);
- else
- dm_info->saved_state = NULL;
+ dm_info->saved_state = NULL;
+ if (info->hvm) {
+ ret = asprintf(&dm_info->saved_state,
+ "/var/lib/xen/qemu-save.%d", domid);
+ ret = (ret < 0) ? ERROR_FAIL : 0;
+ }
+
out:
esave = errno;
core_suspend(ctx, domid, fd, hvm, live, debug);
if (hvm)
- save_device_model(ctx, domid, fd);
+ return save_device_model(ctx, domid, fd);
return 0;
}
int libxl_wait_for_domain_death(struct libxl_ctx *ctx, uint32_t domid, libxl_waiter *waiter)
{
waiter->path = strdup("@releaseDomain");
- asprintf(&(waiter->token), "%d", DOMAIN_DEATH);
+ if (asprintf(&(waiter->token), "%d", DOMAIN_DEATH) < 0)
+ return -1;
if (!xs_watch(ctx->xsh, waiter->path, waiter->token))
return -1;
return 0;
domid = guest_domid;
for (i = 0; i < num_disks; i++) {
- asprintf(&(waiter[i].path), "%s/device/vbd/%d/eject", libxl_xs_get_dompath(ctx, domid), device_disk_dev_number(disks[i].virtpath));
- asprintf(&(waiter[i].token), "%d", DISK_EJECT);
+ if (asprintf(&(waiter[i].path), "%s/device/vbd/%d/eject",
+ libxl_xs_get_dompath(ctx, domid),
+ device_disk_dev_number(disks[i].virtpath)) < 0)
+ return -1;
+ if (asprintf(&(waiter[i].token), "%d", DISK_EJECT) < 0)
+ return -1;
xs_watch(ctx->xsh, waiter->path, waiter->token);
}
return 0;
/* we mustn't use the parent's handle in the child */
kvs[0] = "image/device-model-pid";
- asprintf(&kvs[1], "%d", innerchild);
+ if (asprintf(&kvs[1], "%d", innerchild) < 0)
+ return;
kvs[2] = NULL;
rc = xs_writev(xsh, XBT_NULL, starting->dom_path, kvs);
libxl_xs_write(ctx, XBT_NULL, libxl_sprintf(ctx, "/local/domain/0/device-model/%d/command", domid), "save", strlen("save"));
libxl_wait_for_device_model(ctx, domid, "paused", NULL, NULL);
- write(fd, QEMU_SIGNATURE, strlen(QEMU_SIGNATURE));
+ c = libxl_write_exactly(ctx, fd, QEMU_SIGNATURE, strlen(QEMU_SIGNATURE),
+ "saved-state file", "qemu signature");
+ if (c)
+ return c;
fd2 = open(filename, O_RDONLY);
while ((c = read(fd2, buf, sizeof(buf))) != 0) {
- write(fd, buf, c);
+ if (c < 0) {
+ if (errno == EINTR)
+ continue;
+ return errno;
+ }
+ c = libxl_write_exactly(
+ ctx, fd, buf, c, "saved-state file", "qemu state");
+ if (c)
+ return c;
}
close(fd2);
unlink(filename);
got = rw(fd, data, sz); \
if (got == -1) { \
if (errno == EINTR) continue; \
+ if (!ctx) return errno; \
XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "failed to " #rw " %s%s%s", \
what?what:"", what?" from ":"", filename); \
return errno; \
} \
if (got == 0) { \
+ if (!ctx) return EPROTO; \
XL_LOG(ctx, XL_LOG_ERROR, \
zero_is_eof \
? "file/stream truncated reading %s%s%s" \
return 0;
for (i = 0; kvs[i] != NULL; i += 2) {
- asprintf(&path, "%s/%s", dir, kvs[i]);
+ if (asprintf(&path, "%s/%s", dir, kvs[i]) < 0)
+ return -1;
if (path && kvs[i + 1]) {
int length = strlen(kvs[i + 1]);
xs_write(xsh, t, path, kvs[i + 1], length);
#include <inttypes.h>
#include "libxl.h"
+#include "libxl_utils.h"
#include "xl_cmdimpl.h"
#include "xl_cmdtable.h"
extern struct libxl_ctx ctx;
extern int logfile;
-void log_callback(void *userdata, int loglevel, const char *file, int line, const char *func, char *s)
+void log_callback(
+ void *userdata, int loglevel, const char *file,
+ int line, const char *func, char *s)
{
char str[1024];
- snprintf(str, sizeof(str), "[%d] %s:%d:%s: %s\n", loglevel, file, line, func, s);
- write(logfile, str, strlen(str));
+ snprintf(str, sizeof(str), "[%d] %s:%d:%s: %s\n",
+ loglevel, file, line, func, s);
+ libxl_write_exactly(NULL, logfile, str, strlen(str), NULL, NULL);
}
int main(int argc, char **argv)
rc = vasprintf(&s, fmt, ap);
va_end(ap);
if (rc >= 0)
- write(logfile, s, rc);
+ libxl_write_exactly(NULL, logfile, s, rc, NULL, NULL);
}
static void init_create_info(libxl_domain_create_info *c_info)
} else {
char *cmdline;
if (!xlu_cfg_get_string (config, "root", &buf)) {
- asprintf(&cmdline, "root=%s", buf);
+ if (asprintf(&cmdline, "root=%s", buf) < 0) {
+ fprintf(stderr, "Failed to allocate memory in asprintf\n");
+ exit(1);
+ }
b_info->u.pv.cmdline = cmdline;
}
if (!xlu_cfg_get_string (config, "ramdisk", &buf))
* file; and we receive it to a temporary name */
assert(!common_domname);
common_domname = info1.name;
- asprintf(migration_domname_r, "%s--incoming", info1.name);
+ if (asprintf(migration_domname_r, "%s--incoming", info1.name) < 0) {
+ fprintf(stderr, "Failed to allocate memory in asprintf\n");
+ exit(1);
+ }
info1.name = *migration_domname_r;
}
}
exit(-1);
}
- asprintf(&name, "xl-%s", info1.name);
+ if (asprintf(&name, "xl-%s", info1.name) < 0) {
+ LOG("Failed to allocate memory in asprintf");
+ exit(1);
+ }
rc = libxl_create_logfile(&ctx, name, &fullname);
if (rc) {
LOG("failed to open logfile %s",fullname,strerror(errno));
dup2(logfile, 1);
dup2(logfile, 2);
- daemon(0, 1);
+ CHK_ERRNO(daemon(0, 1) < 0);
need_daemon = 0;
}
LOG("Waiting for domain %s (domid %d) to die [pid %ld]",
save_domain_core_writeconfig(fd, filename, config_data, config_len);
- libxl_domain_suspend(&ctx, NULL, domid, fd);
+ CHK_ERRNO(libxl_domain_suspend(&ctx, NULL, domid, fd));
close(fd);
if (checkpoint)
fprintf(stderr, "migration sender: Target has acknowledged transfer.\n");
if (common_domname) {
- asprintf(&away_domname, "%s--migratedaway", common_domname);
+ if (asprintf(&away_domname, "%s--migratedaway", common_domname) < 0)
+ goto failed_resume;
rc = libxl_domain_rename(&ctx, domid,
common_domname, away_domname, 0);
if (rc) goto failed_resume;
if (!ssh_command[0]) {
rune= host;
} else {
- asprintf(&rune, "exec %s %s xl migrate-receive%s%s",
- ssh_command, host,
- daemonize ? "" : " -e",
- debug ? " -d" : "");
+ if (asprintf(&rune, "exec %s %s xl migrate-receive%s%s",
+ ssh_command, host,
+ daemonize ? "" : " -e",
+ debug ? " -d" : "") < 0)
+ exit(1);
}
migrate_domain(p, rune, config_filename);