break;
case VIR_DOMAIN_CHR_TYPE_PIPE:
- if (virFileExists(dev->data.file.path)) {
- if (virSecurityDACSetOwnership(dev->data.file.path, priv->user, priv->group) < 0)
- goto done;
- } else {
- if ((virAsprintf(&in, "%s.in", dev->data.file.path) < 0) ||
- (virAsprintf(&out, "%s.out", dev->data.file.path) < 0)) {
- virReportOOMError();
- goto done;
- }
+ if ((virAsprintf(&in, "%s.in", dev->data.file.path) < 0) ||
+ (virAsprintf(&out, "%s.out", dev->data.file.path) < 0)) {
+ virReportOOMError();
+ goto done;
+ }
+ if (virFileExists(in) && virFileExists(out)) {
if ((virSecurityDACSetOwnership(in, priv->user, priv->group) < 0) ||
- (virSecurityDACSetOwnership(out, priv->user, priv->group) < 0))
+ (virSecurityDACSetOwnership(out, priv->user, priv->group) < 0)) {
goto done;
+ }
+ } else if (virSecurityDACSetOwnership(dev->data.file.path,
+ priv->user, priv->group) < 0) {
+ goto done;
}
ret = 0;
break;
virReportOOMError();
goto done;
}
- if ((virSecurityDACRestoreSecurityFileLabel(out) < 0) ||
- (virSecurityDACRestoreSecurityFileLabel(in) < 0))
+ if (virFileExists(in) && virFileExists(out)) {
+ if ((virSecurityDACRestoreSecurityFileLabel(out) < 0) ||
+ (virSecurityDACRestoreSecurityFileLabel(in) < 0)) {
goto done;
+ }
+ } else if (virSecurityDACRestoreSecurityFileLabel(dev->data.file.path) < 0) {
+ goto done;
+ }
ret = 0;
break;
break;
case VIR_DOMAIN_CHR_TYPE_PIPE:
- if (virFileExists(dev->data.file.path)) {
- if (SELinuxSetFilecon(dev->data.file.path, secdef->imagelabel) < 0)
- goto done;
- } else {
- if ((virAsprintf(&in, "%s.in", dev->data.file.path) < 0) ||
- (virAsprintf(&out, "%s.out", dev->data.file.path) < 0)) {
- virReportOOMError();
- goto done;
- }
+ if ((virAsprintf(&in, "%s.in", dev->data.file.path) < 0) ||
+ (virAsprintf(&out, "%s.out", dev->data.file.path) < 0)) {
+ virReportOOMError();
+ goto done;
+ }
+ if (virFileExists(in) && virFileExists(out)) {
if ((SELinuxSetFilecon(in, secdef->imagelabel) < 0) ||
- (SELinuxSetFilecon(out, secdef->imagelabel) < 0))
+ (SELinuxSetFilecon(out, secdef->imagelabel) < 0)) {
goto done;
+ }
+ } else if (SELinuxSetFilecon(dev->data.file.path, secdef->imagelabel) < 0) {
+ goto done;
}
ret = 0;
break;
virReportOOMError();
goto done;
}
- if ((SELinuxRestoreSecurityFileLabel(out) < 0) ||
- (SELinuxRestoreSecurityFileLabel(in) < 0))
+ if (virFileExists(in) && virFileExists(out)) {
+ if ((SELinuxRestoreSecurityFileLabel(out) < 0) ||
+ (SELinuxRestoreSecurityFileLabel(in) < 0)) {
+ goto done;
+ }
+ } else if (SELinuxRestoreSecurityFileLabel(dev->data.file.path) < 0) {
goto done;
+ }
ret = 0;
break;