mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-29 17:33:09 +00:00
don't ignore write failure
* src/network_driver.c (networkEnableIpForwarding): This function would always return 1 (success). Now it returns 0 upon write or close failure, being careful to preserve any errno from a write failure. Add comments.
This commit is contained in:
parent
d82071710e
commit
3548e9aae8
@ -1,3 +1,11 @@
|
|||||||
|
Tue Jan 20 20:28:07 +0100 2009 Jim Meyering <meyering@redhat.com>
|
||||||
|
|
||||||
|
don't ignore write failure
|
||||||
|
* src/network_driver.c (networkEnableIpForwarding): This function
|
||||||
|
would always return 1 (success). Now it returns 0 upon write or
|
||||||
|
close failure, being careful to preserve any errno from a write failure.
|
||||||
|
Add comments.
|
||||||
|
|
||||||
Tue Jan 20 19:26:53 GMT 2009 Daniel P. Berrange <berrange@redhat.com>
|
Tue Jan 20 19:26:53 GMT 2009 Daniel P. Berrange <berrange@redhat.com>
|
||||||
|
|
||||||
* qemud/qemud.c, qemud/qemud.h: Dynamic spawn/cleanup threads
|
* qemud/qemud.c, qemud/qemud.h: Dynamic spawn/cleanup threads
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* driver.c: core driver methods for managing qemu guests
|
* driver.c: core driver methods for managing qemu guests
|
||||||
*
|
*
|
||||||
* Copyright (C) 2006, 2007, 2008 Red Hat, Inc.
|
* Copyright (C) 2006-2009 Red Hat, Inc.
|
||||||
* Copyright (C) 2006 Daniel P. Berrange
|
* Copyright (C) 2006 Daniel P. Berrange
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
@ -682,20 +682,29 @@ networkRemoveIptablesRules(struct network_driver *driver,
|
|||||||
iptablesSaveRules(driver->iptables);
|
iptablesSaveRules(driver->iptables);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Enable IP Forwarding.
|
||||||
|
Return 0 for success, nonzero for failure.
|
||||||
|
Be careful to preserve any errno value upon failure. */
|
||||||
static int
|
static int
|
||||||
networkEnableIpForwarding(void)
|
networkEnableIpForwarding(void)
|
||||||
{
|
{
|
||||||
#define PROC_IP_FORWARD "/proc/sys/net/ipv4/ip_forward"
|
#define PROC_IP_FORWARD "/proc/sys/net/ipv4/ip_forward"
|
||||||
|
|
||||||
int fd, ret;
|
int fd;
|
||||||
|
|
||||||
if ((fd = open(PROC_IP_FORWARD, O_WRONLY|O_TRUNC)) == -1)
|
if ((fd = open(PROC_IP_FORWARD, O_WRONLY|O_TRUNC)) == -1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (safewrite(fd, "1\n", 2) < 0)
|
if (safewrite(fd, "1\n", 2) < 0) {
|
||||||
ret = 0;
|
int saved_errno = errno;
|
||||||
|
close (fd);
|
||||||
|
errno = saved_errno;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
close (fd);
|
/* Use errno from failed close only if there was no write error. */
|
||||||
|
if (close (fd) != 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
@ -1317,4 +1326,3 @@ int networkRegister(void) {
|
|||||||
virRegisterStateDriver(&networkStateDriver);
|
virRegisterStateDriver(&networkStateDriver);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user