aboutsummaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
authorAli B <abittin@gmail.com>2020-12-07 10:57:01 +0100
committerGerrit Code Review <gerrit@box1>2020-12-07 10:57:01 +0100
commit202efb89dab30af5311f7f6b5717ad6006e90364 (patch)
treefeab266c11c0d0bce876a8975393d21884c0da04 /libc
parent408227d12df4dd2f3235d43a3dd0c271443d975a (diff)
parenta88e6adaca4b6d385aa98ca5ea819264d2fd4a95 (diff)
Merge "Make hosts cache respect toggle-able adblock file" into r11.0r11.0
Diffstat (limited to 'libc')
-rw-r--r--libc/dns/net/gethostsfile.c16
-rw-r--r--libc/dns/net/gethostsfile.h4
-rw-r--r--libc/dns/net/hosts_cache.c11
3 files changed, 29 insertions, 2 deletions
diff --git a/libc/dns/net/gethostsfile.c b/libc/dns/net/gethostsfile.c
new file mode 100644
index 000000000..ee5618ba3
--- /dev/null
+++ b/libc/dns/net/gethostsfile.c
@@ -0,0 +1,16 @@
+#include <string.h>
+#include <netdb.h>
+#include <sys/system_properties.h>
+
+#include "gethostsfile.h"
+
+const char *gethostsfile() {
+ char hosts_setting[128];
+ int prop_len = __system_property_get(AICP_HOSTS_SETTING_PROP,
+ hosts_setting);
+ if (prop_len > 0 && strncmp(hosts_setting, "true", 4) == 0) {
+ return AICP_PATH_ADBLOCK_HOSTS;
+ } else {
+ return _PATH_HOSTS;
+ }
+}
diff --git a/libc/dns/net/gethostsfile.h b/libc/dns/net/gethostsfile.h
new file mode 100644
index 000000000..214d25798
--- /dev/null
+++ b/libc/dns/net/gethostsfile.h
@@ -0,0 +1,4 @@
+#define AICP_PATH_ADBLOCK_HOSTS "/system/etc/hosts.aicp_adblock"
+#define AICP_HOSTS_SETTING_PROP "persist.aicp.hosts_block"
+
+const char* gethostsfile();
diff --git a/libc/dns/net/hosts_cache.c b/libc/dns/net/hosts_cache.c
index 5038986be..ee21ed8ce 100644
--- a/libc/dns/net/hosts_cache.c
+++ b/libc/dns/net/hosts_cache.c
@@ -36,6 +36,8 @@
#include "hostent.h"
#include "resolv_private.h"
+#include "gethostsfile.h"
+
#define MAX_ADDRLEN (INET6_ADDRSTRLEN - (1 + 5))
#define MAX_HOSTLEN MAXHOSTNAMELEN
@@ -66,6 +68,7 @@ struct hcfile
int h_fd;
struct stat h_st;
char *h_data;
+ const char *h_path;
uint32_t c_alloc;
uint32_t c_len;
@@ -218,8 +221,10 @@ static int _hcfilemmap(void)
char *h_addr;
const char *p, *pend;
uint32_t c_alloc;
+ const char *h_path;
- h_fd = open(_PATH_HOSTS, O_RDONLY);
+ h_path = gethostsfile();
+ h_fd = open(h_path, O_RDONLY);
if (h_fd < 0)
return -1;
if (flock(h_fd, LOCK_EX) != 0) {
@@ -230,7 +235,8 @@ static int _hcfilemmap(void)
if (hcfile.h_data) {
memset(&st, 0, sizeof(st));
if (fstat(h_fd, &st) == 0) {
- if (st.st_size == hcfile.h_st.st_size &&
+ if (strcmp(h_path, hcfile.h_path) == 0 &&
+ st.st_size == hcfile.h_st.st_size &&
st.st_mtime == hcfile.h_st.st_mtime) {
flock(h_fd, LOCK_UN);
close(h_fd);
@@ -258,6 +264,7 @@ static int _hcfilemmap(void)
hcfile.h_fd = h_fd;
hcfile.h_st = st;
hcfile.h_data = h_addr;
+ hcfile.h_path = h_path;
c_alloc = 0;
/*