}
if (def->os.nBootDevs) {
virBuffer boot_buf = VIR_BUFFER_INITIALIZER;
- char *bootstr;
virCommandAddArg(cmd, "-boot");
boot[def->os.nBootDevs] = '\0';
virBufferVSprintf(&boot_buf, "%s", boot);
}
- if (virBufferError(&boot_buf)) {
- virReportOOMError();
- goto error;
- }
-
- bootstr = virBufferContentAndReset(&boot_buf);
- virCommandAddArg(cmd, bootstr);
- VIR_FREE(bootstr);
+ virCommandAddArgBuffer(cmd, &boot_buf);
}
if (def->os.kernel)
disk->protocol == VIR_DOMAIN_DISK_PROTOCOL_RBD) {
for (j = 0 ; j < disk->nhosts ; j++) {
if (!has_rbd_hosts) {
- virBufferAddLit(&rbd_hosts, "-m ");
+ virBufferAddLit(&rbd_hosts, "CEPH_ARGS=-m ");
has_rbd_hosts = true;
} else {
virBufferAddLit(&rbd_hosts, ",");
snprintf(file, PATH_MAX, "rbd:%s,", disk->src);
for (j = 0 ; j < disk->nhosts ; j++) {
if (!has_rbd_hosts) {
- virBufferAddLit(&rbd_hosts, "-m ");
+ virBufferAddLit(&rbd_hosts, "CEPH_ARGS=-m ");
has_rbd_hosts = true;
} else {
virBufferAddLit(&rbd_hosts, ",");
}
}
- if (virBufferError(&rbd_hosts)) {
- virBufferFreeAndReset(&rbd_hosts);
- goto no_memory;
- }
if (has_rbd_hosts)
- virCommandAddEnvPair(cmd, "CEPH_ARGS", virBufferContentAndReset(&rbd_hosts));
+ virCommandAddEnvBuffer(cmd, &rbd_hosts);
if (qemuCmdFlags & QEMUD_CMD_FLAG_FSDEV) {
for (i = 0 ; i < def->nfss ; i++) {
if ((def->ngraphics == 1) &&
def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
virBuffer opt = VIR_BUFFER_INITIALIZER;
- char *optstr;
if (qemuCmdFlags & QEMUD_CMD_FLAG_VNC_COLON) {
if (def->graphics[0]->data.vnc.listenAddr)
virBufferVSprintf(&opt, "%d",
def->graphics[0]->data.vnc.port - 5900);
}
- if (virBufferError(&opt)) {
- virBufferFreeAndReset(&opt);
- goto no_memory;
- }
-
- optstr = virBufferContentAndReset(&opt);
- virCommandAddArgList(cmd, "-vnc", optstr, NULL);
- VIR_FREE(optstr);
+ virCommandAddArg(cmd, "-vnc");
+ virCommandAddArgBuffer(cmd, &opt);
if (def->graphics[0]->data.vnc.keymap) {
virCommandAddArgList(cmd, "-k", def->graphics[0]->data.vnc.keymap,
NULL);
} else if ((def->ngraphics == 1) &&
def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
virBuffer opt = VIR_BUFFER_INITIALIZER;
- char *optstr;
if (!(qemuCmdFlags & QEMUD_CMD_FLAG_SPICE)) {
qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
}
}
- if (virBufferError(&opt))
- goto no_memory;
-
- optstr = virBufferContentAndReset(&opt);
-
- virCommandAddArgList(cmd, "-spice", optstr, NULL);
- VIR_FREE(optstr);
+ virCommandAddArg(cmd, "-spice");
+ virCommandAddArgBuffer(cmd, &opt);
if (def->graphics[0]->data.spice.keymap)
virCommandAddArgList(cmd, "-k",
def->graphics[0]->data.spice.keymap, NULL);
error:
for (i = 0; i <= last_good_net; i++)
virDomainConfNWFilterTeardown(def->nets[i]);
+ virBufferFreeAndReset(&rbd_hosts);
virCommandFree(cmd);
return NULL;
}
}
+/*
+ * Convert a buffer containing preformatted name=value into an
+ * environment variable of the child.
+ * Correctly transfers memory errors or contents from buf to cmd.
+ */
+void
+virCommandAddEnvBuffer(virCommandPtr cmd, virBufferPtr buf)
+{
+ if (!cmd || cmd->has_error) {
+ virBufferFreeAndReset(buf);
+ return;
+ }
+
+ /* env plus trailing NULL. */
+ if (virBufferError(buf) ||
+ VIR_RESIZE_N(cmd->env, cmd->maxenv, cmd->nenv, 1 + 1) < 0) {
+ cmd->has_error = ENOMEM;
+ virBufferFreeAndReset(buf);
+ return;
+ }
+
+ cmd->env[cmd->nenv++] = virBufferContentAndReset(buf);
+}
+
+
/*
* Pass an environment variable to the child
* using current process' value
}
+/*
+ * Convert a buffer into a command line argument to the child.
+ * Correctly transfers memory errors or contents from buf to cmd.
+ */
+void
+virCommandAddArgBuffer(virCommandPtr cmd, virBufferPtr buf)
+{
+ if (!cmd || cmd->has_error) {
+ virBufferFreeAndReset(buf);
+ return;
+ }
+
+ /* Arg plus trailing NULL. */
+ if (virBufferError(buf) ||
+ VIR_RESIZE_N(cmd->args, cmd->maxargs, cmd->nargs, 1 + 1) < 0) {
+ cmd->has_error = ENOMEM;
+ virBufferFreeAndReset(buf);
+ return;
+ }
+
+ cmd->args[cmd->nargs++] = virBufferContentAndReset(buf);
+}
+
+
/*
* Add a command line argument created by a printf-style format
*/
# include "internal.h"
# include "util.h"
+# include "buf.h"
typedef struct _virCommand virCommand;
typedef virCommand *virCommandPtr;
*/
void virCommandAddEnvString(virCommandPtr cmd,
const char *str) ATTRIBUTE_NONNULL(2);
+
+/*
+ * Convert a buffer containing preformatted name=value into an
+ * environment variable of the child.
+ * Correctly transfers memory errors or contents from buf to cmd.
+ */
+void virCommandAddEnvBuffer(virCommandPtr cmd,
+ virBufferPtr buf);
+
/*
* Pass an environment variable to the child
* using current process' value
void virCommandAddArg(virCommandPtr cmd,
const char *val) ATTRIBUTE_NONNULL(2);
+/*
+ * Convert a buffer into a command line argument to the child.
+ * Correctly transfers memory errors or contents from buf to cmd.
+ */
+void virCommandAddArgBuffer(virCommandPtr cmd,
+ virBufferPtr buf);
+
/*
* Add a command line argument created by a printf-style format
*/