diff options
| author | Elliott Hughes <enh@google.com> | 2015-02-02 18:08:59 -0800 |
|---|---|---|
| committer | Elliott Hughes <enh@google.com> | 2015-02-03 14:11:06 -0800 |
| commit | d161406141619f84d94b2ecee618569cbbabcb30 (patch) | |
| tree | c7069216a8649aec197e9236514102ab8eb44e59 /server/TetherController.cpp | |
| parent | 6c08cd6aa7aee66b973ee4861237ad36560e0239 (diff) | |
Switch netd over to <utils/file.h>.
Change-Id: Id79961cc4feee1c307dad06d64e3f4ffe060c4da
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 |
