diff options
| author | Elliott Hughes <enh@google.com> | 2015-02-03 14:31:35 -0800 |
|---|---|---|
| committer | Elliott Hughes <enh@google.com> | 2015-02-03 14:31:35 -0800 |
| commit | 561ad8c1a4fd519a6ae632ea1d414f90e62da95f (patch) | |
| tree | 7c799c2ced07f7a13622ba93800ff7e92a056052 /server/TetherController.cpp | |
| parent | 69766c22edb99338c3b703aeadbaa286f6b78334 (diff) | |
| parent | c9692899c936d2d45f9c52f94b9847bd9de86bae (diff) | |
resolved conflicts for merge of c9692899 to lmp-mr1-dev-plus-aosp
Change-Id: I8f4c9ae0d13d30e69b7a197eafdfcb9b2b9050c0
Diffstat (limited to 'server/TetherController.cpp')
| -rw-r--r-- | server/TetherController.cpp | 27 |
1 files changed, 6 insertions, 21 deletions
diff --git a/server/TetherController.cpp b/server/TetherController.cpp index a91c7444..c9a93fd6 100644 --- a/server/TetherController.cpp +++ b/server/TetherController.cpp @@ -30,6 +30,7 @@ #define LOG_TAG "TetherController" #include <cutils/log.h> #include <cutils/properties.h> +#include <utils/file.h> #include "Fwmark.h" #include "NetdConstants.h" @@ -66,38 +67,22 @@ int TetherController::setIpFwdEnabled(bool enable) { return 0; } - int fd = open("/proc/sys/net/ipv4/ip_forward", O_WRONLY | O_CLOEXEC); - if (fd < 0) { - ALOGE("Failed to open ip_forward (%s)", strerror(errno)); - return -1; - } - - if (write(fd, (enable ? "1" : "0"), 1) != 1) { + if (!android::WriteStringToFile(enable ? "1" : "0", "/proc/sys/net/ipv4/ip_forward")) { ALOGE("Failed to write ip_forward (%s)", strerror(errno)); - close(fd); return -1; } - close(fd); + return 0; } bool TetherController::getIpFwdEnabled() { - int fd = open("/proc/sys/net/ipv4/ip_forward", O_RDONLY | O_CLOEXEC); - - if (fd < 0) { - ALOGE("Failed to open ip_forward (%s)", strerror(errno)); - return false; - } - - char enabled; - if (read(fd, &enabled, 1) != 1) { + std::string enabled; + if (!android::ReadFileToString("/proc/sys/net/ipv4/ip_forward", &enabled)) { ALOGE("Failed to read ip_forward (%s)", strerror(errno)); - close(fd); return -1; } - close(fd); - return (enabled == '1' ? true : false); + return (enabled == "1" ? true : false); } #define TETHER_START_CONST_ARG 8 |
