int rc = -2;
/* create string that is '<str> \0' for accurate matching */
- if (virAsprintf(&tmp, "%s ", str) == -1)
- return rc;
+ tmp = g_strdup_printf("%s ", str);
if (check_enforcing != 0) {
/* create string that is '<str> (enforce)\0' for accurate matching */
- if (virAsprintf(&etmp, "%s (enforce)", str) == -1) {
- VIR_FREE(tmp);
- return rc;
- }
+ etmp = g_strdup_printf("%s (enforce)", str);
}
if (virFileReadAll(APPARMOR_PROFILES_PATH, MAX_FILE_LEN, &content) < 0) {
int rc = -1;
int len;
- if (virAsprintf(&profile, "%s/%s", APPARMOR_DIR "/libvirt", str) == -1)
- return rc;
+ profile = g_strdup_printf("%s/%s", APPARMOR_DIR "/libvirt", str);
if (!virFileExists(profile))
goto failed;
}
/* create string that is ' <str> flags=(complain)\0' */
- if (virAsprintf(&tmp, " %s flags=(complain)", str) == -1)
- goto failed;
+ tmp = g_strdup_printf(" %s flags=(complain)", str);
if (strstr(content, tmp) != NULL)
rc = 0;
char *name = NULL;
virUUIDFormat(def->uuid, uuidstr);
- if (virAsprintf(&name, "%s%s", AA_PREFIX, uuidstr) < 0)
- return NULL;
+ name = g_strdup_printf("%s%s", AA_PREFIX, uuidstr);
return name;
}
return rc;
/* see if template file exists */
- if (virAsprintf(&template_qemu, "%s/TEMPLATE.qemu",
- APPARMOR_DIR "/libvirt") == -1)
- return rc;
-
- if (virAsprintf(&template_lxc, "%s/TEMPLATE.lxc",
- APPARMOR_DIR "/libvirt") == -1)
- goto cleanup;
+ template_qemu = g_strdup_printf("%s/TEMPLATE.qemu", APPARMOR_DIR "/libvirt");
+ template_lxc = g_strdup_printf("%s/TEMPLATE.lxc", APPARMOR_DIR "/libvirt");
if (!virFileExists(template_qemu)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
break;
case VIR_DOMAIN_CHR_TYPE_PIPE:
- if (virAsprintf(&in, "%s.in", dev_source->data.file.path) < 0 ||
- virAsprintf(&out, "%s.out", dev_source->data.file.path) < 0)
- goto done;
+ in = g_strdup_printf("%s.in", dev_source->data.file.path);
+ out = g_strdup_printf("%s.out", dev_source->data.file.path);
if (virFileExists(in)) {
if (reload_profile(mgr, def, in, true) < 0)
goto done;
char *full_path = NULL;
if (allowSubtree) {
- if (virAsprintf(&full_path, "%s/{,**}", path) < 0)
- return -1;
+ full_path = g_strdup_printf("%s/{,**}", path);
rc = reload_profile(mgr, def, full_path, true);
VIR_FREE(full_path);
} else {
virDomainDefPtr def,
int fd)
{
- int rc = -1;
char *proc = NULL;
char *fd_path = NULL;
if (!secdef || !secdef->imagelabel)
return 0;
- if (virAsprintf(&proc, "/proc/self/fd/%d", fd) == -1)
- return rc;
+ proc = g_strdup_printf("/proc/self/fd/%d", fd);
if (virFileResolveLink(proc, &fd_path) < 0) {
/* it's a deleted file, presumably. Ignore? */
priv->user = user;
priv->group = group;
- if (virAsprintf(&priv->baselabel, "+%u:+%u",
- (unsigned int)user,
- (unsigned int)group) < 0)
- return -1;
+ priv->baselabel = g_strdup_printf("+%u:+%u", (unsigned int)user,
+ (unsigned int)group);
return 0;
}
char *label = NULL;
int ret = -1;
- if (virAsprintf(&label, "+%u:+%u",
- (unsigned int)uid,
- (unsigned int)gid) < 0)
- return -1;
+ label = g_strdup_printf("+%u:+%u", (unsigned int)uid, (unsigned int)gid);
ret = virSecuritySetRememberedLabel(SECURITY_DAC_NAME, path, label);
VIR_FREE(label);
break;
case VIR_DOMAIN_CHR_TYPE_PIPE:
- if (virAsprintf(&in, "%s.in", dev_source->data.file.path) < 0 ||
- virAsprintf(&out, "%s.out", dev_source->data.file.path) < 0)
- goto done;
+ in = g_strdup_printf("%s.in", dev_source->data.file.path);
+ out = g_strdup_printf("%s.out", dev_source->data.file.path);
if (virFileExists(in) && virFileExists(out)) {
if (virSecurityDACSetOwnership(mgr, NULL, in, user, group, remember) < 0 ||
virSecurityDACSetOwnership(mgr, NULL, out, user, group, remember) < 0)
break;
case VIR_DOMAIN_CHR_TYPE_PIPE:
- if (virAsprintf(&out, "%s.out", dev_source->data.file.path) < 0 ||
- virAsprintf(&in, "%s.in", dev_source->data.file.path) < 0)
- goto done;
+ out = g_strdup_printf("%s.out", dev_source->data.file.path);
+ in = g_strdup_printf("%s.in", dev_source->data.file.path);
if (virFileExists(in) && virFileExists(out)) {
if (virSecurityDACRestoreFileLabelInternal(mgr, NULL, out, recall) < 0 ||
virSecurityDACRestoreFileLabelInternal(mgr, NULL, in, recall) < 0)
}
break;
case VIR_DOMAIN_SECLABEL_DYNAMIC:
- if (virAsprintf(&seclabel->label, "+%u:+%u",
- (unsigned int)priv->user,
- (unsigned int)priv->group) < 0)
- return rc;
+ seclabel->label = g_strdup_printf("+%u:+%u", (unsigned int)priv->user,
+ (unsigned int)priv->group);
if (seclabel->label == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot generate dac user and group id "
VIR_DEBUG("Getting DAC user and group on process '%d'", pid);
- if (virAsprintf(&path, "/proc/%d", (int)pid) < 0)
- goto cleanup;
+ path = g_strdup_printf("/proc/%d", (int)pid);
if (lstat(path, &sb) < 0) {
virReportSystemError(errno,
VIR_DEBUG("Try cat %s:c%d,c%d", sens, c1 + catMin, c2 + catMin);
if (c1 == c2) {
- if (virAsprintf(&mcs, "%s:c%d", sens, catMin + c1) < 0)
- return NULL;
+ mcs = g_strdup_printf("%s:c%d", sens, catMin + c1);
} else {
if (c1 > c2) {
int t = c1;
c1 = c2;
c2 = t;
}
- if (virAsprintf(&mcs, "%s:c%d,c%d", sens, catMin + c1, catMin + c2) < 0)
- return NULL;
+ mcs = g_strdup_printf("%s:c%d,c%d", sens, catMin + c1, catMin + c2);
}
if (virHashLookup(data->mcs, mcs) == NULL)
switch (dev->source.caps.type) {
case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_STORAGE: {
if (vroot) {
- if (virAsprintf(&path, "%s/%s", vroot,
- dev->source.caps.u.storage.block) < 0)
- return -1;
+ path = g_strdup_printf("%s/%s", vroot,
+ dev->source.caps.u.storage.block);
} else {
path = g_strdup(dev->source.caps.u.storage.block);
}
case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_MISC: {
if (vroot) {
- if (virAsprintf(&path, "%s/%s", vroot,
- dev->source.caps.u.misc.chardev) < 0)
- return -1;
+ path = g_strdup_printf("%s/%s", vroot,
+ dev->source.caps.u.misc.chardev);
} else {
path = g_strdup(dev->source.caps.u.misc.chardev);
}
switch (dev->source.caps.type) {
case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_STORAGE: {
if (vroot) {
- if (virAsprintf(&path, "%s/%s", vroot,
- dev->source.caps.u.storage.block) < 0)
- return -1;
+ path = g_strdup_printf("%s/%s", vroot,
+ dev->source.caps.u.storage.block);
} else {
path = g_strdup(dev->source.caps.u.storage.block);
}
case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_MISC: {
if (vroot) {
- if (virAsprintf(&path, "%s/%s", vroot,
- dev->source.caps.u.misc.chardev) < 0)
- return -1;
+ path = g_strdup_printf("%s/%s", vroot,
+ dev->source.caps.u.misc.chardev);
} else {
path = g_strdup(dev->source.caps.u.misc.chardev);
}
break;
case VIR_DOMAIN_CHR_TYPE_PIPE:
- if ((virAsprintf(&in, "%s.in", dev_source->data.file.path) < 0) ||
- (virAsprintf(&out, "%s.out", dev_source->data.file.path) < 0))
- goto done;
+ in = g_strdup_printf("%s.in", dev_source->data.file.path);
+ out = g_strdup_printf("%s.out", dev_source->data.file.path);
if (virFileExists(in) && virFileExists(out)) {
if ((virSecuritySELinuxSetFilecon(mgr, in, imagelabel, true) < 0) ||
(virSecuritySELinuxSetFilecon(mgr, out, imagelabel, true) < 0)) {
break;
case VIR_DOMAIN_CHR_TYPE_PIPE:
- if ((virAsprintf(&out, "%s.out", dev_source->data.file.path) < 0) ||
- (virAsprintf(&in, "%s.in", dev_source->data.file.path) < 0))
- goto done;
+ out = g_strdup_printf("%s.out", dev_source->data.file.path);
+ in = g_strdup_printf("%s.in", dev_source->data.file.path);
if (virFileExists(in) && virFileExists(out)) {
if ((virSecuritySELinuxRestoreFileLabel(mgr, out, true) < 0) ||
(virSecuritySELinuxRestoreFileLabel(mgr, in, true) < 0)) {
}
/* Label /dev/tap.* devices only. Leave /dev/net/tun alone! */
- if (virAsprintf(&proc, "/proc/self/fd/%d", fd) == -1)
- goto cleanup;
+ proc = g_strdup_printf("/proc/self/fd/%d", fd);
if (virFileResolveLink(proc, &fd_path) < 0) {
virReportSystemError(errno,
if (!secdef->imagelabel)
secdef->imagelabel = virSecuritySELinuxGenImageLabel(mgr, def);
- if (secdef->imagelabel &&
- virAsprintf(&opts,
- ",context=\"%s\"",
- (const char*) secdef->imagelabel) < 0)
- return NULL;
+ if (secdef->imagelabel) {
+ opts = g_strdup_printf(
+ ",context=\"%s\"",
+ (const char*) secdef->imagelabel);
+ }
}
if (!opts)
return -1;
while ((ret = virDirRead(dir, &ent, path)) > 0) {
- if (virAsprintf(&filename, "%s/%s", path, ent->d_name) < 0) {
- ret = -1;
- break;
- }
+ filename = g_strdup_printf("%s/%s", path, ent->d_name);
ret = virSecuritySELinuxSetFilecon(mgr, filename,
seclabel->imagelabel, true);
VIR_FREE(filename);
return -1;
while ((ret = virDirRead(dir, &ent, path)) > 0) {
- if (virAsprintf(&filename, "%s/%s", path, ent->d_name) < 0) {
- ret = -1;
- break;
- }
+ filename = g_strdup_printf("%s/%s", path, ent->d_name);
ret = virSecuritySELinuxRestoreFileLabel(mgr, filename, true);
VIR_FREE(filename);
if (ret < 0)
{
char *ret = NULL;
#ifdef XATTR_NAMESPACE
- ignore_value(virAsprintf(&ret, XATTR_NAMESPACE".libvirt.security.%s", name));
+ ret = g_strdup_printf(XATTR_NAMESPACE".libvirt.security.%s", name);
#else
errno = ENOSYS;
virReportSystemError(errno, "%s",
{
char *ret = NULL;
#ifdef XATTR_NAMESPACE
- ignore_value(virAsprintf(&ret, XATTR_NAMESPACE".libvirt.security.ref_%s", name));
+ ret = g_strdup_printf(XATTR_NAMESPACE".libvirt.security.ref_%s", name);
#else
errno = ENOSYS;
virReportSystemError(errno, "%s",
virSecurityGetTimestampAttrName(const char *name)
{
char *ret = NULL;
- ignore_value(virAsprintf(&ret, XATTR_NAMESPACE ".libvirt.security.timestamp_%s", name));
+ ret = g_strdup_printf(XATTR_NAMESPACE ".libvirt.security.timestamp_%s", name);
return ret;
}
#else /* !XATTR_NAMESPACE */
return NULL;
}
- ignore_value(virAsprintf(&ret, "%llu", boottime));
+ ret = g_strdup_printf("%llu", boottime);
return ret;
}
refcount--;
if (refcount > 0) {
- if (virAsprintf(&value, "%u", refcount) < 0)
- return -1;
+ value = g_strdup_printf("%u", refcount);
if (virFileSetXAttr(path, ref_name, value) < 0)
return -1;
return -1;
}
- if (virAsprintf(&value, "%u", refcount) < 0)
- return -1;
+ value = g_strdup_printf("%u", refcount);
if (virFileSetXAttr(path, ref_name, value) < 0)
return -1;
snprintf(flag, 3, "-%c", cmd);
- if (virAsprintfQuiet(&profile, "%s/%s",
- APPARMOR_DIR "/libvirt", profile_name) < 0) {
- vah_error(NULL, 0, _("profile name exceeds maximum length"));
- return -1;
- }
+ profile = g_strdup_printf("%s/%s", APPARMOR_DIR "/libvirt", profile_name);
if (!virFileExists(profile)) {
vah_error(NULL, 0, _("profile does not exist"));
return rc;
}
- if (append && virFileExists(include_file)) {
- if (virAsprintfQuiet(&pcontent, "%s%s", existing, included_files) == -1) {
- vah_error(NULL, 0, _("could not allocate memory for profile"));
- goto cleanup;
- }
- } else {
- if (virAsprintfQuiet(&pcontent, "%s%s", warning, included_files) == -1) {
- vah_error(NULL, 0, _("could not allocate memory for profile"));
- goto cleanup;
- }
- }
+ if (append && virFileExists(include_file))
+ pcontent = g_strdup_printf("%s%s", existing, included_files);
+ else
+ pcontent = g_strdup_printf("%s%s", warning, included_files);
plen = strlen(pcontent);
if (plen > MAX_FILE_LEN) {
driver_name = virDomainVirtTypeToString(virtType);
}
- if (virAsprintfQuiet(&template, "%s/TEMPLATE.%s", APPARMOR_DIR "/libvirt",
- driver_name) < 0) {
- vah_error(NULL, 0, _("template name exceeds maximum length"));
- goto end;
- }
+ template = g_strdup_printf("%s/TEMPLATE.%s", APPARMOR_DIR "/libvirt", driver_name);
if (!virFileExists(template)) {
vah_error(NULL, 0, _("template does not exist"));
}
/* '\nprofile <profile_name>\0' */
- if (virAsprintfQuiet(&replace_name, "\nprofile %s", profile_name) == -1) {
- vah_error(NULL, 0, _("could not allocate memory for profile name"));
- goto clean_tcontent;
- }
+ replace_name = g_strdup_printf("\nprofile %s", profile_name);
/* '\n<profile_files>\n}\0' */
- if ((virtType != VIR_DOMAIN_VIRT_LXC) &&
- virAsprintfQuiet(&replace_files, "\n%s\n}", profile_files) == -1) {
- vah_error(NULL, 0, _("could not allocate memory for profile files"));
- VIR_FREE(replace_name);
- goto clean_tcontent;
- }
+ if (virtType != VIR_DOMAIN_VIRT_LXC)
+ replace_files = g_strdup_printf("\n%s\n}", profile_files);
plen = tlen + strlen(replace_name) - strlen(template_name) + 1;
vah_error(NULL, 0, _("could not find realpath"));
goto cleanup;
}
- if (virAsprintfQuiet(&tmp, "%s%s", pathreal, pathtmp) < 0)
- goto cleanup;
+ tmp = g_strdup_printf("%s%s", pathreal, pathtmp);
}
perms_new = g_strdup(perms);
if (type == VIR_DOMAIN_CHR_TYPE_PIPE) {
/* add the pipe input */
- if (virAsprintfQuiet(&pipe_in, "%s.in", path) == -1) {
- vah_error(NULL, 0, _("could not allocate memory"));
- goto cleanup;
- }
+ pipe_in = g_strdup_printf("%s.in", path);
if (vah_add_file(buf, pipe_in, perms) != 0)
goto clean_pipe_in;
/* add the pipe output */
- if (virAsprintfQuiet(&pipe_out, "%s.out", path) == -1) {
- vah_error(NULL, 0, _("could not allocate memory"));
- goto clean_pipe_in;
- }
+ pipe_out = g_strdup_printf("%s.out", path);
if (vah_add_file(buf, pipe_out, perms) != 0)
goto clean_pipe_out;
/* verify uuid is same as what we were given on the command line */
virUUIDFormat(ctl->def->uuid, uuidstr);
- if (virAsprintfQuiet(&uuid, "%s%s", AA_PREFIX, uuidstr) == -1) {
- vah_error(ctl, 0, _("could not allocate memory"));
- return rc;
- }
+ uuid = g_strdup_printf("%s%s", AA_PREFIX, uuidstr);
if (STRNEQ(uuid, ctl->uuid)) {
vah_error(ctl, 0, _("given uuid does not match XML uuid"));
if (vahParseArgv(ctl, argc, argv) != 0)
vah_error(ctl, 1, _("could not parse arguments"));
- if (virAsprintfQuiet(&profile, "%s/%s",
- APPARMOR_DIR "/libvirt", ctl->uuid) < 0)
- vah_error(ctl, 0, _("could not allocate memory"));
-
- if (virAsprintfQuiet(&include_file, "%s/%s.files",
- APPARMOR_DIR "/libvirt", ctl->uuid) < 0)
- vah_error(ctl, 0, _("could not allocate memory"));
+ profile = g_strdup_printf("%s/%s", APPARMOR_DIR "/libvirt", ctl->uuid);
+ include_file = g_strdup_printf("%s/%s.files", APPARMOR_DIR "/libvirt", ctl->uuid);
if (ctl->cmd == 'a') {
rc = parserLoad(ctl->uuid);
/* create the profile from TEMPLATE */
if (ctl->cmd == 'c') {
char *tmp = NULL;
- if (virAsprintfQuiet(&tmp, " #include <libvirt/%s.files>\n",
- ctl->uuid) == -1) {
- vah_error(ctl, 0, _("could not allocate memory"));
- goto cleanup;
- }
+ tmp = g_strdup_printf(" #include <libvirt/%s.files>\n", ctl->uuid);
if (ctl->dryrun) {
vah_info(profile);