mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 19:32:19 +00:00
network: fix return value of hostsFileWrite
The lone caller to hostsFileWrite (and the callers for at least 3 levels up the return stack) assume that the return value will be < 0 on failure. However, hostsFileWrite returns 0 on success, and a positive errno on failure. This patch changes hostsFileWrite to return -errno on failure.
This commit is contained in:
parent
a372c405b4
commit
f7bd72fa26
@ -159,19 +159,19 @@ hostsfileWrite(const char *path,
|
|||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
if (virAsprintf(&tmp, "%s.new", path) < 0)
|
if (virAsprintf(&tmp, "%s.new", path) < 0)
|
||||||
return ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
if (!(f = fopen(tmp, "w"))) {
|
if (!(f = fopen(tmp, "w"))) {
|
||||||
istmp = false;
|
istmp = false;
|
||||||
if (!(f = fopen(path, "w"))) {
|
if (!(f = fopen(path, "w"))) {
|
||||||
rc = errno;
|
rc = -errno;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < nhosts; i++) {
|
for (i = 0; i < nhosts; i++) {
|
||||||
if (fputs(hosts[i].host, f) == EOF || fputc('\n', f) == EOF) {
|
if (fputs(hosts[i].host, f) == EOF || fputc('\n', f) == EOF) {
|
||||||
rc = errno;
|
rc = -errno;
|
||||||
VIR_FORCE_FCLOSE(f);
|
VIR_FORCE_FCLOSE(f);
|
||||||
|
|
||||||
if (istmp)
|
if (istmp)
|
||||||
@ -182,19 +182,19 @@ hostsfileWrite(const char *path,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_FCLOSE(f) == EOF) {
|
if (VIR_FCLOSE(f) == EOF) {
|
||||||
rc = errno;
|
rc = -errno;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (istmp) {
|
if (istmp) {
|
||||||
if (rename(tmp, path) < 0) {
|
if (rename(tmp, path) < 0) {
|
||||||
rc = errno;
|
rc = -errno;
|
||||||
unlink(tmp);
|
unlink(tmp);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unlink(tmp) < 0) {
|
if (unlink(tmp) < 0) {
|
||||||
rc = errno;
|
rc = -errno;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user