Replace 'goto clean' with 'goto cleanup' in apparmor code

Some of the apparmor code files did not follow the normal
goto label naming pratices

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrange 2013-04-29 18:38:21 +01:00
parent c6c1e0074b
commit 0454a7cd3d
2 changed files with 50 additions and 50 deletions

View File

@ -94,7 +94,7 @@ profile_status(const char *str, const int check_enforcing)
virReportSystemError(errno, virReportSystemError(errno,
_("Failed to read AppArmor profiles list " _("Failed to read AppArmor profiles list "
"\'%s\'"), APPARMOR_PROFILES_PATH); "\'%s\'"), APPARMOR_PROFILES_PATH);
goto clean; goto cleanup;
} }
if (strstr(content, tmp) != NULL) if (strstr(content, tmp) != NULL)
@ -105,7 +105,7 @@ profile_status(const char *str, const int check_enforcing)
} }
VIR_FREE(content); VIR_FREE(content);
clean: cleanup:
VIR_FREE(tmp); VIR_FREE(tmp);
VIR_FREE(etmp); VIR_FREE(etmp);
@ -294,12 +294,12 @@ reload_profile(virSecurityManagerPtr mgr,
_("cannot update AppArmor profile " _("cannot update AppArmor profile "
"\'%s\'"), "\'%s\'"),
secdef->imagelabel); secdef->imagelabel);
goto clean; goto cleanup;
} }
} }
rc = 0; rc = 0;
clean: cleanup:
VIR_FREE(profile_name); VIR_FREE(profile_name);
return rc; return rc;
@ -372,11 +372,11 @@ AppArmorSecurityManagerProbe(const char *virtDriver)
if (!virFileExists(template)) { if (!virFileExists(template)) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("template \'%s\' does not exist"), template); _("template \'%s\' does not exist"), template);
goto clean; goto cleanup;
} }
rc = SECURITY_DRIVER_ENABLE; rc = SECURITY_DRIVER_ENABLE;
clean: cleanup:
VIR_FREE(template); VIR_FREE(template);
return rc; return rc;
@ -449,7 +449,7 @@ AppArmorGenSecurityLabel(virSecurityManagerPtr mgr ATTRIBUTE_UNUSED,
secdef->label = strndup(profile_name, strlen(profile_name)); secdef->label = strndup(profile_name, strlen(profile_name));
if (!secdef->label) { if (!secdef->label) {
virReportOOMError(); virReportOOMError();
goto clean; goto cleanup;
} }
/* set imagelabel the same as label (but we won't use it) */ /* set imagelabel the same as label (but we won't use it) */
@ -474,14 +474,14 @@ AppArmorGenSecurityLabel(virSecurityManagerPtr mgr ATTRIBUTE_UNUSED,
} }
rc = 0; rc = 0;
goto clean; goto cleanup;
err: err:
VIR_FREE(secdef->label); VIR_FREE(secdef->label);
VIR_FREE(secdef->imagelabel); VIR_FREE(secdef->imagelabel);
VIR_FREE(secdef->model); VIR_FREE(secdef->model);
clean: cleanup:
VIR_FREE(profile_name); VIR_FREE(profile_name);
return rc; return rc;
@ -526,17 +526,17 @@ AppArmorGetSecurityProcessLabel(virSecurityManagerPtr mgr ATTRIBUTE_UNUSED,
VIR_SECURITY_LABEL_BUFLEN) == NULL) { VIR_SECURITY_LABEL_BUFLEN) == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("error copying profile name")); "%s", _("error copying profile name"));
goto clean; goto cleanup;
} }
if ((sec->enforcing = profile_status(profile_name, 1)) < 0) { if ((sec->enforcing = profile_status(profile_name, 1)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("error calling profile_status()")); "%s", _("error calling profile_status()"));
goto clean; goto cleanup;
} }
rc = 0; rc = 0;
clean: cleanup:
VIR_FREE(profile_name); VIR_FREE(profile_name);
return rc; return rc;
@ -609,17 +609,17 @@ AppArmorSetSecurityProcessLabel(virSecurityManagerPtr mgr ATTRIBUTE_UNUSED,
"hypervisor driver is \'%s\'."), "hypervisor driver is \'%s\'."),
secdef->model, SECURITY_APPARMOR_NAME); secdef->model, SECURITY_APPARMOR_NAME);
if (use_apparmor() > 0) if (use_apparmor() > 0)
goto clean; goto cleanup;
} }
if (aa_change_profile(profile_name) < 0) { if (aa_change_profile(profile_name) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("error calling aa_change_profile()")); _("error calling aa_change_profile()"));
goto clean; goto cleanup;
} }
rc = 0; rc = 0;
clean: cleanup:
VIR_FREE(profile_name); VIR_FREE(profile_name);
return rc; return rc;
@ -736,13 +736,13 @@ AppArmorSetSecurityImageLabel(virSecurityManagerPtr mgr,
_("cannot update AppArmor profile " _("cannot update AppArmor profile "
"\'%s\'"), "\'%s\'"),
secdef->imagelabel); secdef->imagelabel);
goto clean; goto cleanup;
} }
} }
} }
rc = 0; rc = 0;
clean: cleanup:
VIR_FREE(profile_name); VIR_FREE(profile_name);
return rc; return rc;

View File

@ -277,46 +277,46 @@ update_include_file(const char *include_file, const char *included_files,
if (append && virFileExists(include_file)) { if (append && virFileExists(include_file)) {
if (virAsprintf(&pcontent, "%s%s", existing, included_files) == -1) { if (virAsprintf(&pcontent, "%s%s", existing, included_files) == -1) {
vah_error(NULL, 0, _("could not allocate memory for profile")); vah_error(NULL, 0, _("could not allocate memory for profile"));
goto clean; goto cleanup;
} }
} else { } else {
if (virAsprintf(&pcontent, "%s%s", warning, included_files) == -1) { if (virAsprintf(&pcontent, "%s%s", warning, included_files) == -1) {
vah_error(NULL, 0, _("could not allocate memory for profile")); vah_error(NULL, 0, _("could not allocate memory for profile"));
goto clean; goto cleanup;
} }
} }
plen = strlen(pcontent); plen = strlen(pcontent);
if (plen > MAX_FILE_LEN) { if (plen > MAX_FILE_LEN) {
vah_error(NULL, 0, _("invalid length for new profile")); vah_error(NULL, 0, _("invalid length for new profile"));
goto clean; goto cleanup;
} }
/* only update the disk profile if it is different */ /* only update the disk profile if it is different */
if (flen > 0 && flen == plen && STREQLEN(existing, pcontent, plen)) { if (flen > 0 && flen == plen && STREQLEN(existing, pcontent, plen)) {
rc = 0; rc = 0;
goto clean; goto cleanup;
} }
/* write the file */ /* write the file */
if ((fd = open(include_file, O_CREAT | O_TRUNC | O_WRONLY, 0644)) == -1) { if ((fd = open(include_file, O_CREAT | O_TRUNC | O_WRONLY, 0644)) == -1) {
vah_error(NULL, 0, _("failed to create include file")); vah_error(NULL, 0, _("failed to create include file"));
goto clean; goto cleanup;
} }
if (safewrite(fd, pcontent, plen) < 0) { /* don't write the '\0' */ if (safewrite(fd, pcontent, plen) < 0) { /* don't write the '\0' */
VIR_FORCE_CLOSE(fd); VIR_FORCE_CLOSE(fd);
vah_error(NULL, 0, _("failed to write to profile")); vah_error(NULL, 0, _("failed to write to profile"));
goto clean; goto cleanup;
} }
if (VIR_CLOSE(fd) != 0) { if (VIR_CLOSE(fd) != 0) {
vah_error(NULL, 0, _("failed to close or write to profile")); vah_error(NULL, 0, _("failed to close or write to profile"));
goto clean; goto cleanup;
} }
rc = 0; rc = 0;
clean: cleanup:
VIR_FREE(pcontent); VIR_FREE(pcontent);
VIR_FREE(existing); VIR_FREE(existing);
@ -785,7 +785,7 @@ vah_add_file(virBufferPtr buf, const char *path, const char *perms)
vah_error(NULL, 0, path); vah_error(NULL, 0, path);
vah_error(NULL, 0, _("skipped restricted file")); vah_error(NULL, 0, _("skipped restricted file"));
} }
goto clean; goto cleanup;
} }
virBufferAsprintf(buf, " \"%s\" %s,\n", tmp, perms); virBufferAsprintf(buf, " \"%s\" %s,\n", tmp, perms);
@ -794,7 +794,7 @@ vah_add_file(virBufferPtr buf, const char *path, const char *perms)
virBufferAsprintf(buf, " deny \"%s\" w,\n", tmp); virBufferAsprintf(buf, " deny \"%s\" w,\n", tmp);
} }
clean: cleanup:
VIR_FREE(tmp); VIR_FREE(tmp);
return rc; return rc;
@ -814,7 +814,7 @@ vah_add_file_chardev(virBufferPtr buf,
/* add the pipe input */ /* add the pipe input */
if (virAsprintf(&pipe_in, "%s.in", path) == -1) { if (virAsprintf(&pipe_in, "%s.in", path) == -1) {
vah_error(NULL, 0, _("could not allocate memory")); vah_error(NULL, 0, _("could not allocate memory"));
goto clean; goto cleanup;
} }
if (vah_add_file(buf, pipe_in, perms) != 0) if (vah_add_file(buf, pipe_in, perms) != 0)
@ -837,11 +837,11 @@ vah_add_file_chardev(virBufferPtr buf,
} else { } else {
/* add the file */ /* add the file */
if (vah_add_file(buf, path, perms) != 0) if (vah_add_file(buf, path, perms) != 0)
goto clean; goto cleanup;
rc = 0; rc = 0;
} }
clean: cleanup:
return rc; return rc;
} }
@ -903,7 +903,7 @@ get_files(vahControl * ctl)
if (STRNEQ(uuid, ctl->uuid)) { if (STRNEQ(uuid, ctl->uuid)) {
vah_error(ctl, 0, _("given uuid does not match XML uuid")); vah_error(ctl, 0, _("given uuid does not match XML uuid"));
goto clean; goto cleanup;
} }
for (i = 0; i < ctl->def->ndisks; i++) { for (i = 0; i < ctl->def->ndisks; i++) {
@ -925,7 +925,7 @@ get_files(vahControl * ctl)
* careful than just ignoring them. * careful than just ignoring them.
*/ */
if (virDomainDiskDefForeachPath(disk, true, add_file_path, &buf) < 0) if (virDomainDiskDefForeachPath(disk, true, add_file_path, &buf) < 0)
goto clean; goto cleanup;
} }
for (i = 0; i < ctl->def->nserials; i++) for (i = 0; i < ctl->def->nserials; i++)
@ -939,7 +939,7 @@ get_files(vahControl * ctl)
ctl->def->serials[i]->source.data.file.path, ctl->def->serials[i]->source.data.file.path,
"rw", "rw",
ctl->def->serials[i]->source.type) != 0) ctl->def->serials[i]->source.type) != 0)
goto clean; goto cleanup;
for (i = 0; i < ctl->def->nconsoles; i++) for (i = 0; i < ctl->def->nconsoles; i++)
if (ctl->def->consoles[i] && if (ctl->def->consoles[i] &&
@ -950,7 +950,7 @@ get_files(vahControl * ctl)
ctl->def->consoles[i]->source.data.file.path) ctl->def->consoles[i]->source.data.file.path)
if (vah_add_file(&buf, if (vah_add_file(&buf,
ctl->def->consoles[i]->source.data.file.path, "rw") != 0) ctl->def->consoles[i]->source.data.file.path, "rw") != 0)
goto clean; goto cleanup;
for (i = 0 ; i < ctl->def->nparallels; i++) for (i = 0 ; i < ctl->def->nparallels; i++)
if (ctl->def->parallels[i] && if (ctl->def->parallels[i] &&
@ -963,7 +963,7 @@ get_files(vahControl * ctl)
ctl->def->parallels[i]->source.data.file.path, ctl->def->parallels[i]->source.data.file.path,
"rw", "rw",
ctl->def->parallels[i]->source.type) != 0) ctl->def->parallels[i]->source.type) != 0)
goto clean; goto cleanup;
for (i = 0 ; i < ctl->def->nchannels; i++) for (i = 0 ; i < ctl->def->nchannels; i++)
if (ctl->def->channels[i] && if (ctl->def->channels[i] &&
@ -976,36 +976,36 @@ get_files(vahControl * ctl)
ctl->def->channels[i]->source.data.file.path, ctl->def->channels[i]->source.data.file.path,
"rw", "rw",
ctl->def->channels[i]->source.type) != 0) ctl->def->channels[i]->source.type) != 0)
goto clean; goto cleanup;
if (ctl->def->os.kernel) if (ctl->def->os.kernel)
if (vah_add_file(&buf, ctl->def->os.kernel, "r") != 0) if (vah_add_file(&buf, ctl->def->os.kernel, "r") != 0)
goto clean; goto cleanup;
if (ctl->def->os.initrd) if (ctl->def->os.initrd)
if (vah_add_file(&buf, ctl->def->os.initrd, "r") != 0) if (vah_add_file(&buf, ctl->def->os.initrd, "r") != 0)
goto clean; goto cleanup;
if (ctl->def->os.dtb) if (ctl->def->os.dtb)
if (vah_add_file(&buf, ctl->def->os.dtb, "r") != 0) if (vah_add_file(&buf, ctl->def->os.dtb, "r") != 0)
goto clean; goto cleanup;
if (ctl->def->os.loader && ctl->def->os.loader) if (ctl->def->os.loader && ctl->def->os.loader)
if (vah_add_file(&buf, ctl->def->os.loader, "r") != 0) if (vah_add_file(&buf, ctl->def->os.loader, "r") != 0)
goto clean; goto cleanup;
for (i = 0; i < ctl->def->ngraphics; i++) { for (i = 0; i < ctl->def->ngraphics; i++) {
if (ctl->def->graphics[i]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC && if (ctl->def->graphics[i]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC &&
ctl->def->graphics[i]->data.vnc.socket && ctl->def->graphics[i]->data.vnc.socket &&
vah_add_file(&buf, ctl->def->graphics[i]->data.vnc.socket, "rw")) vah_add_file(&buf, ctl->def->graphics[i]->data.vnc.socket, "rw"))
goto clean; goto cleanup;
} }
if (ctl->def->ngraphics == 1 && if (ctl->def->ngraphics == 1 &&
ctl->def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL) ctl->def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL)
if (vah_add_file(&buf, ctl->def->graphics[0]->data.sdl.xauth, if (vah_add_file(&buf, ctl->def->graphics[0]->data.sdl.xauth,
"r") != 0) "r") != 0)
goto clean; goto cleanup;
for (i = 0; i < ctl->def->nhostdevs; i++) for (i = 0; i < ctl->def->nhostdevs; i++)
if (ctl->def->hostdevs[i]) { if (ctl->def->hostdevs[i]) {
@ -1023,7 +1023,7 @@ get_files(vahControl * ctl)
rc = virUSBDeviceFileIterate(usb, file_iterate_hostdev_cb, &buf); rc = virUSBDeviceFileIterate(usb, file_iterate_hostdev_cb, &buf);
virUSBDeviceFree(usb); virUSBDeviceFree(usb);
if (rc != 0) if (rc != 0)
goto clean; goto cleanup;
break; break;
} }
@ -1051,18 +1051,18 @@ get_files(vahControl * ctl)
if (ctl->newfile) if (ctl->newfile)
if (vah_add_file(&buf, ctl->newfile, "rw") != 0) if (vah_add_file(&buf, ctl->newfile, "rw") != 0)
goto clean; goto cleanup;
if (virBufferError(&buf)) { if (virBufferError(&buf)) {
virBufferFreeAndReset(&buf); virBufferFreeAndReset(&buf);
vah_error(NULL, 0, _("failed to allocate file buffer")); vah_error(NULL, 0, _("failed to allocate file buffer"));
goto clean; goto cleanup;
} }
rc = 0; rc = 0;
ctl->files = virBufferContentAndReset(&buf); ctl->files = virBufferContentAndReset(&buf);
clean: cleanup:
VIR_FREE(uuid); VIR_FREE(uuid);
return rc; return rc;
} }
@ -1232,7 +1232,7 @@ main(int argc, char **argv)
if (ctl->append && ctl->newfile) { if (ctl->append && ctl->newfile) {
if (vah_add_file(&buf, ctl->newfile, "rw") != 0) if (vah_add_file(&buf, ctl->newfile, "rw") != 0)
goto clean; goto cleanup;
} else { } else {
virBufferAsprintf(&buf, " \"%s/log/libvirt/**/%s.log\" w,\n", virBufferAsprintf(&buf, " \"%s/log/libvirt/**/%s.log\" w,\n",
LOCALSTATEDIR, ctl->def->name); LOCALSTATEDIR, ctl->def->name);
@ -1265,7 +1265,7 @@ main(int argc, char **argv)
} else if ((rc = update_include_file(include_file, } else if ((rc = update_include_file(include_file,
included_files, included_files,
ctl->append)) != 0) ctl->append)) != 0)
goto clean; goto cleanup;
/* create the profile from TEMPLATE */ /* create the profile from TEMPLATE */
@ -1274,7 +1274,7 @@ main(int argc, char **argv)
if (virAsprintf(&tmp, " #include <libvirt/%s.files>\n", if (virAsprintf(&tmp, " #include <libvirt/%s.files>\n",
ctl->uuid) == -1) { ctl->uuid) == -1) {
vah_error(ctl, 0, _("could not allocate memory")); vah_error(ctl, 0, _("could not allocate memory"));
goto clean; goto cleanup;
} }
if (ctl->dryrun) { if (ctl->dryrun) {
@ -1302,7 +1302,7 @@ main(int argc, char **argv)
unlink(profile); unlink(profile);
} }
} }
clean: cleanup:
VIR_FREE(included_files); VIR_FREE(included_files);
} }