Commit 1e05c8b6 authored by Elliott Hughes's avatar Elliott Hughes Committed by Android Git Automerger
Browse files

am 561ad8c1: resolved conflicts for merge of c9692899 to lmp-mr1-dev-plus-aosp

* commit '561ad8c1':
  Switch netd over to <utils/file.h>.
parents fa186364 561ad8c1
......@@ -37,6 +37,7 @@ LOCAL_SHARED_LIBRARIES := \
libnetutils \
libnl \
libsysutils \
libutils \
LOCAL_STATIC_LIBRARIES := \
libpcap \
......
......@@ -21,6 +21,7 @@
#define LOG_TAG "InterfaceController"
#include <cutils/log.h>
#include <logwrap/logwrap.h>
#include <utils/file.h>
#include "InterfaceController.h"
#include "RouteController.h"
......@@ -55,7 +56,7 @@ int InterfaceController::writeIPv6ProcPath(const char *interface, const char *se
return -1;
}
asprintf(&path, "%s/%s/%s", ipv6_proc_path, interface, setting);
int success = writeFile(path, value, strlen(value));
bool success = android::WriteStringToFile(value, path);
free(path);
return success;
}
......@@ -148,7 +149,7 @@ int InterfaceController::setMtu(const char *interface, const char *mtu)
return -1;
}
asprintf(&path, "%s/%s/mtu", sys_net_path, interface);
int success = writeFile(path, mtu, strlen(mtu));
bool success = android::WriteStringToFile(mtu, path);
free(path);
return success;
}
......
......@@ -113,43 +113,6 @@ int execIptablesSilently(IptablesTarget target, ...) {
return res;
}
int writeFile(const char *path, const char *value, int size) {
int fd = open(path, O_WRONLY | O_CLOEXEC);
if (fd < 0) {
ALOGE("Failed to open %s: %s", path, strerror(errno));
return -1;
}
if (write(fd, value, size) != size) {
ALOGE("Failed to write %s: %s", path, strerror(errno));
close(fd);
return -1;
}
close(fd);
return 0;
}
int readFile(const char *path, char *buf, int *sizep)
{
int fd = open(path, O_RDONLY | O_CLOEXEC);
int size;
if (fd < 0) {
ALOGE("Failed to open %s: %s", path, strerror(errno));
return -1;
}
size = read(fd, buf, *sizep);
if (size < 0) {
ALOGE("Failed to write %s: %s", path, strerror(errno));
close(fd);
return -1;
}
*sizep = size;
close(fd);
return 0;
}
/*
* Check an interface name for plausibility. This should e.g. help against
* directory traversal.
......
......@@ -35,8 +35,6 @@ enum IptablesTarget { V4, V6, V4V6 };
int execIptables(IptablesTarget target, ...);
int execIptablesSilently(IptablesTarget target, ...);
int writeFile(const char *path, const char *value, int size);
int readFile(const char *path, char *buf, int *sizep);
bool isIfaceName(const char *name);
int parsePrefix(const char *prefix, uint8_t *family, void *address, int size, uint8_t *prefixlen);
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment