androresolvd-1.3/0000755000000000000000000000000011740761730010753 5ustar androresolvd-1.3/system_properties.c0000644000000000000000000001725511740756236014736 0ustar /* * Copyright (C) 2008 The Android Open Source Project * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #include #include #include #include #include #include #include #include #include #include #define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ #include #include static const char property_service_name[] = PROP_SERVICE_NAME; static unsigned dummy_props = 0; prop_area *__system_property_area__ = (void*) &dummy_props; /* Detected PROP_NAME_MAX. Note, that android-x86.org uses a changed constant, see * http://android-x86.git.sourceforge.net/git/gitweb.cgi?p=android-x86/x86_bionic.git;a=commitdiff;h=380a68a2b52f41bfdb0d2662b0e21281505037d5 */ #define PROP_NAME_LIMIT 256 static int prop_name_max = PROP_NAME_MAX; int __system_properties_init(void) { prop_area *pa; int fd; unsigned sz; char *env; if(__system_property_area__ != ((void*) &dummy_props)) { return 0; } env = getenv("ANDROID_PROPERTY_WORKSPACE"); if (!env) { return -1; } fd = atoi(env); env = strchr(env, ','); if (!env) { return -1; } sz = atoi(env + 1); pa = mmap(0, sz, PROT_READ, MAP_SHARED, fd, 0); if(pa == MAP_FAILED) { return -1; } if((pa->magic != PROP_AREA_MAGIC) || (pa->version != PROP_AREA_VERSION)) { munmap(pa, sz); return -1; } __system_property_area__ = pa; if (0 < pa->count) { /* * Yes - this is C. I like it, but it may have bugs :) * Search the longest value in the /system/build.prop * and /system/default.prop files with a name that starts * with "ro." in order to search this read-only property to * determine PROP_NAME_MAX later on. */ int prop; int minlen = 8; char name[PROP_NAME_LIMIT]; char value[PROP_VALUE_MAX]; for (prop = 0; prop < 2; prop++) { FILE* f = fopen(prop ? PROP_PATH_SYSTEM_BUILD : PROP_PATH_SYSTEM_DEFAULT, "r"); if (f) { char s[32 + PROP_NAME_LIMIT + PROP_VALUE_MAX]; while (fgets(s, sizeof(s), f)) { char* p = s; while (sizeof(s) > p - s && (' ' == *p || '\t' == *p)) p++; if (sizeof(s) > p - s && 0 == strncmp(p, "ro.", 3)) { char* n = p; while (sizeof(s) > p - s && 0 != *p && '=' != *p && ' ' != *p && '\t' != *p) p++; if (sizeof(s) > p - s && 0 != *p) { char* nend = p; while (sizeof(s) > p - s && 0 != *p && '=' != *p) p++; if (sizeof(s) > p - s && '=' == *p) { char *v; *nend = 0; p++; while (sizeof(s) > p - s && (' ' == *p || '\t' == *p)) p++; v = p; while (sizeof(s) > p - s && (' ' <= *p)) p++; if (sizeof(s) > p - s) { char *vend = p; *vend = 0; if (sizeof(name) > nend - n && sizeof(value) > vend - v && minlen < vend - v) { minlen = vend - v; strcpy(name, n); strcpy(value, v); } } } } } } fclose(f); } } if (8 < minlen) { const prop_info *pi = __system_property_find(name); if (0 != pi) { int m = PROP_NAME_MAX; while(m <= PROP_NAME_LIMIT) { if (0 == strcmp(pi->value + (m - PROP_NAME_MAX), value)) { prop_name_max = m; break; } m++; } } } } return 0; } const prop_info *__system_property_find_nth(unsigned n) { prop_area *pa = __system_property_area__; if(n >= pa->count) { return 0; } else { return TOC_TO_INFO(pa, pa->toc[n]); } } const prop_info *__system_property_find(const char *name) { prop_area *pa = __system_property_area__; unsigned count = pa->count; unsigned *toc = pa->toc; unsigned len = strlen(name); prop_info *pi; while(count--) { unsigned entry = *toc++; if(TOC_NAME_LEN(entry) != len) continue; pi = TOC_TO_INFO(pa, entry); if(memcmp(name, pi->name, len)) continue; return pi; } return 0; } int __system_property_read(const prop_info *pi, char *name, char *value) { unsigned serial, len; for(;;) { serial = *(unsigned*)((char*)pi + prop_name_max); while(SERIAL_DIRTY(serial)) { __futex_wait((volatile void *)((char*)pi + prop_name_max), serial, 0); serial = *(unsigned*)((char*)pi + prop_name_max); } len = SERIAL_VALUE_LEN(serial); memcpy(value, (char*)pi + prop_name_max + sizeof(pi->serial), len + 1); if(serial == *(unsigned*)((char*)pi + prop_name_max)) { if(name != 0) { strcpy(name, pi->name); } return len; } } } int __system_property_get(const char *name, char *value) { const prop_info *pi = __system_property_find(name); if(pi != 0) { return __system_property_read(pi, 0, value); } else { value[0] = 0; return 0; } } int __system_property_wait(const prop_info *pi) { unsigned n; if(pi == 0) { prop_area *pa = __system_property_area__; n = pa->serial; do { __futex_wait(&pa->serial, n, 0); } while(n == pa->serial); } else { n = pi->serial; do { __futex_wait((volatile void *)&pi->serial, n, 0); } while(n == pi->serial); } return 0; } androresolvd-1.3/Makefile0000644000000000000000000000051311740761717012417 0ustar DEBUG=0 ifeq ($(DEBUG),0) CFLAGS=-s else CFLAGS=-ggdb endif CFLAGS+=-I. -Wall SBINDIR=$(DESTDIR)/usr/sbin androresolvd: system_properties.o androresolvd.c install: androresolvd mkdir -p $(SBINDIR) install -m 755 androresolvd $(SBINDIR) clean: rm -vf *.o rm -vf androresolvd rm -vf nohup.out rm -vf *~ rm -vf debian/*~ androresolvd-1.3/debian/0000755000000000000000000000000011740761737012204 5ustar androresolvd-1.3/debian/rules0000755000000000000000000000067211732410022013244 0ustar #!/usr/bin/make -f # -*- makefile -*- # Sample debian/rules that uses debhelper. # This file was originally written by Joey Hess and Craig Small. # As a special exception, when this file is copied by dh-make into a # dh-make output file, you may use that output file without restriction. # This special exception was added by Craig Small in version 0.37 of dh-make. # Uncomment this to turn on verbose mode. #export DH_VERBOSE=1 %: dh $@ androresolvd-1.3/debian/compat0000644000000000000000000000000211732410022013355 0ustar 7 androresolvd-1.3/debian/postrm0000644000000000000000000000164711732410022013436 0ustar #!/bin/sh # postrm script for androresolvd # # see: dh_installdeb(1) set -e # summary of how this script can be called: # * `remove' # * `purge' # * `upgrade' # * `failed-upgrade' # * `abort-install' # * `abort-install' # * `abort-upgrade' # * `disappear' # # for details, see http://www.debian.org/doc/debian-policy/ or # the debian-policy package case "$1" in purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) ;; *) echo "postrm called with unknown argument \`$1'" >&2 exit 1 ;; esac # dh_installdeb will replace this with shell code automatically # generated by other debhelper scripts. #DEBHELPER# exit 0 androresolvd-1.3/debian/prerm0000644000000000000000000000156211732410022013233 0ustar #!/bin/sh # prerm script for androresolvd # # see: dh_installdeb(1) set -e # summary of how this script can be called: # * `remove' # * `upgrade' # * `failed-upgrade' # * `remove' `in-favour' # * `deconfigure' `in-favour' # `removing' # # for details, see http://www.debian.org/doc/debian-policy/ or # the debian-policy package case "$1" in remove|upgrade|deconfigure) ;; failed-upgrade) ;; *) echo "prerm called with unknown argument \`$1'" >&2 exit 1 ;; esac # dh_installdeb will replace this with shell code automatically # generated by other debhelper scripts. #DEBHELPER# exit 0 androresolvd-1.3/debian/copyright0000644000000000000000000000361411732410022014116 0ustar This work was packaged for Debian by: Sven-Ola Tuecke on Fri, 28 Jan 2011 14:18:49 +0100 Copyright: License: Redistribution and use in source and binary forms, with or without modification, are permitted under the terms of the BSD License. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. On Debian systems, the complete text of the BSD License can be found in "/usr/share/common-licenses/BSD". The Debian packaging is: Copyright (C) 2011 Sven-Ola Tuecke # Please chose a license for your packaging work. If the program you package # uses a mainstream license, using the same license is the safest choice. # Please avoid to pick license terms that are more restrictive than the # packaged work, as it may make Debian's contributions unacceptable upstream. # If you just want it to be GPL version 3, leave the following lines in. and is licensed under the GPL version 3, see "/usr/share/common-licenses/GPL-3". # Please also look if there are files or directories which have a # different copyright/license attached and list them here. androresolvd-1.3/debian/postinst0000644000000000000000000000240211734524115013776 0ustar #!/bin/sh # postinst script for androresolvd # # see: dh_installdeb(1) set -e # summary of how this script can be called: # * `configure' # * `abort-upgrade' # * `abort-remove' `in-favour' # # * `abort-remove' # * `abort-deconfigure' `in-favour' # `removing' # # for details, see http://www.debian.org/doc/debian-policy/ or # the debian-policy package case "$1" in configure) if [ -f /run/resolvconf/interface/original.resolvconf ];then # Ubuntu Precise: these are leftover files that add # additional old/outdated nameserver entries. rm -f /run/resolvconf/interface/original.resolvconf :> /etc/resolvconf/resolv.conf.d/original fi ;; abort-upgrade|abort-remove|abort-deconfigure) ;; *) echo "postinst called with unknown argument \`$1'" >&2 exit 1 ;; esac # dh_installdeb will replace this with shell code automatically # generated by other debhelper scripts. #DEBHELPER# exit 0 androresolvd-1.3/debian/changelog0000644000000000000000000000434111740753306014051 0ustar androresolvd (1.3-0) unstable; urgency=low * Changed deprectated signal() to sigaction() -- Sven-Ola Tuecke Tue, 10 Apr 2012 06:43:50 +0001 androresolvd (1.2-5) unstable; urgency=low * Build error triggered SEGV on armel -- Sven-Ola Tuecke Mon, 09 Apr 2012 19:04:00 +0001 androresolvd (1.2-4) unstable; urgency=low * Changed stategy to detect PROP_NAME_MAX: read /system/build.prop, search longest ro. setting and compare this to memory structures * Added -d switch for debug-run -- Sven-Ola Tuecke Fri, 06 Apr 2012 15:33:37 +0001 androresolvd (1.2-3) unstable; urgency=low * Remove /run/resolvconf/interface/original.resolvconf in postinst to prevent old nameserver entries from showing up in the future -- Sven-Ola Tuecke Wed, 28 Mar 2012 07:26:32 +0001 androresolvd (1.2-2) unstable; urgency=low * Hardening PROP_NAME_MAX detection -- Sven-Ola Tuecke Mon, 26 Mar 2012 09:53:00 +0000 androresolvd (1.2-1) unstable; urgency=low * Replaced fix PROP_NAME_MAX with algorithm, because android-x86.org binaries and intel-x86 emulator binaries uses different values, hence we need to detect if PROP_NAME_MAX is (32 or 128) during runtime. -- Sven-Ola Tuecke Mon, 26 Mar 2012 07:06:20 +0000 androresolvd (1.1-2) unstable; urgency=low * Added android-x86.org fix (PROP_NAME_MAX 128) -- Sven-Ola Tuecke Mon, 21 Mar 2012 18:33:45 +0000 androresolvd (1.1-1) unstable; urgency=low * Switched to resolvconf hook -- Sven-Ola Tuecke Mon, 05 Mar 2012 12:52:30 +0000 androresolvd (1.0-5) unstable; urgency=low * Again fixed failing installation -- Sven-Ola Tuecke Thu, 03 Mar 2011 11:08:21 +0000 androresolvd (1.0-4) unstable; urgency=low * Fixed failing installation -- Sven-Ola Tuecke Wed, 02 Mar 2011 05:58:17 +0000 androresolvd (1.0-3) unstable; urgency=low * Fixed hanging /etc/init.d/androresolvd stop -- Sven-Ola Tuecke Tue, 01 Mar 2011 18:18:14 +0100 androresolvd (1.0-2) unstable; urgency=low * Initial release -- Sven-Ola Tuecke Fri, 28 Jan 2011 14:18:49 +0100 androresolvd-1.3/debian/init.d0000644000000000000000000000130611740757002013302 0ustar #!/bin/sh ### BEGIN INIT INFO # Provides: androresolvd # Required-Start: $network $local_fs # Required-Stop: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Updates /etc/resolv.conf from Android system props ### END INIT INFO # Author: Sven-Ola Tuecke PATH=/sbin:/usr/sbin:/bin:/usr/bin DAEMON=/usr/sbin/androresolvd # Exit if the package is not installed [ -x $DAEMON ] || exit 0 case "$1" in start) $DAEMON # No error if damon fails to start exit 0 ;; stop) PID=$(pidof $DAEMON) case $PID in "");;*) kill -INT $PID ;;esac ;; restart) $0 stop $0 start ;; *) echo "Usage: $0 {start|stop|restart}" >&2 exit 3 ;; esac androresolvd-1.3/debian/control0000644000000000000000000000142611732410022013565 0ustar Source: androresolvd Section: unknown Priority: extra Maintainer: Sven-Ola Tuecke Build-Depends: debhelper Standards-Version: 3.8.4 Package: androresolvd Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends}, resolvconf Description: Daemon to transfer Android DNS property to resolv.conf Small user space daemon to get the Android DNS server setting and maintain the resolver config on a regulary basis. Note, that this daemon has to be started by some running android programs, in order to have the ANDROID_PROPERTY_WORKSPACE environment variable and the /dev/ashmem file descriptor (usually #9) that is inherited from the calling process. Another note: cannot be started from a login shell, because "bash --login" closes all inherited file descriptors. androresolvd-1.3/sys/0000755000000000000000000000000011734004276011567 5ustar androresolvd-1.3/sys/system_properties.h0000644000000000000000000000633011734001654015537 0ustar /* * Copyright (C) 2008 The Android Open Source Project * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef _INCLUDE_SYS_SYSTEM_PROPERTIES_H #define _INCLUDE_SYS_SYSTEM_PROPERTIES_H #include __BEGIN_DECLS typedef struct prop_info prop_info; #define PROP_NAME_MAX 32 #define PROP_VALUE_MAX 92 /* Look up a system property by name, copying its value and a ** \0 terminator to the provided pointer. The total bytes ** copied will be no greater than PROP_VALUE_MAX. Returns ** the string length of the value. A property that is not ** defined is identical to a property with a length 0 value. */ int __system_property_get(const char *name, char *value); /* Return a pointer to the system property named name, if it ** exists, or NULL if there is no such property. Use ** __system_property_read() to obtain the string value from ** the returned prop_info pointer. ** ** It is safe to cache the prop_info pointer to avoid future ** lookups. These returned pointers will remain valid for ** the lifetime of the system. */ const prop_info *__system_property_find(const char *name); /* Read the value of a system property. Returns the length ** of the value. Copies the value and \0 terminator into ** the provided value pointer. Total length (including ** terminator) will be no greater that PROP_VALUE_MAX. ** ** If name is nonzero, up to PROP_NAME_MAX bytes will be ** copied into the provided name pointer. The name will ** be \0 terminated. */ int __system_property_read(const prop_info *pi, char *name, char *value); /* Return a prop_info for the nth system property, or NULL if ** there is no nth property. Use __system_property_read() to ** read the value of this property. ** ** This method is for inspecting and debugging the property ** system. Please use __system_property_find() instead. ** ** Order of results may change from call to call. This is ** not a bug. */ const prop_info *__system_property_find_nth(unsigned n); __END_DECLS #endif androresolvd-1.3/sys/_system_properties.h0000644000000000000000000000674611520522632015706 0ustar /* * Copyright (C) 2008 The Android Open Source Project * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef _INCLUDE_SYS__SYSTEM_PROPERTIES_H #define _INCLUDE_SYS__SYSTEM_PROPERTIES_H #ifndef _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ #error you should #include instead #else #include typedef struct prop_area prop_area; typedef struct prop_msg prop_msg; #define PROP_AREA_MAGIC 0x504f5250 #define PROP_AREA_VERSION 0x45434f76 #define PROP_SERVICE_NAME "property_service" /* #define PROP_MAX_ENTRIES 247 */ /* 247 -> 32620 bytes (<32768) */ #define TOC_NAME_LEN(toc) ((toc) >> 24) #define TOC_TO_INFO(area, toc) ((prop_info*) (((char*) area) + ((toc) & 0xFFFFFF))) struct prop_area { unsigned volatile count; unsigned volatile serial; unsigned magic; unsigned version; unsigned reserved[4]; unsigned toc[1]; }; #define SERIAL_VALUE_LEN(serial) ((serial) >> 24) #define SERIAL_DIRTY(serial) ((serial) & 1) struct prop_info { char name[PROP_NAME_MAX]; unsigned volatile serial; char value[PROP_VALUE_MAX]; }; struct prop_msg { unsigned cmd; char name[PROP_NAME_MAX]; char value[PROP_VALUE_MAX]; }; #define PROP_MSG_SETPROP 1 /* ** Rules: ** ** - there is only one writer, but many readers ** - prop_area.count will never decrease in value ** - once allocated, a prop_info's name will not change ** - once allocated, a prop_info's offset will not change ** - reading a value requires the following steps ** 1. serial = pi->serial ** 2. if SERIAL_DIRTY(serial), wait*, then goto 1 ** 3. memcpy(local, pi->value, SERIAL_VALUE_LEN(serial) + 1) ** 4. if pi->serial != serial, goto 2 ** ** - writing a value requires the following steps ** 1. pi->serial = pi->serial | 1 ** 2. memcpy(pi->value, local_value, value_len) ** 3. pi->serial = (value_len << 24) | ((pi->serial + 1) & 0xffffff) ** ** Improvements: ** - maintain the toc sorted by pi->name to allow lookup ** by binary search ** */ #define PROP_PATH_RAMDISK_DEFAULT "/default.prop" #define PROP_PATH_SYSTEM_BUILD "/system/build.prop" #define PROP_PATH_SYSTEM_DEFAULT "/system/default.prop" #define PROP_PATH_LOCAL_OVERRIDE "/data/local.prop" #endif #endif androresolvd-1.3/sys/atomics.h0000644000000000000000000000353711520522632013401 0ustar /* * Copyright (C) 2008 The Android Open Source Project * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef _SYS_ATOMICS_H #define _SYS_ATOMICS_H #include #include __BEGIN_DECLS extern int __atomic_cmpxchg(int old, int _new, volatile int *ptr); extern int __atomic_swap(int _new, volatile int *ptr); extern int __atomic_dec(volatile int *ptr); extern int __atomic_inc(volatile int *ptr); int __futex_wait(volatile void *ftx, int val, const struct timespec *timeout); int __futex_wake(volatile void *ftx, int count); __END_DECLS #endif /* _SYS_ATOMICS_H */ androresolvd-1.3/androresolvd.c0000644000000000000000000001264211740756236013633 0ustar /* * Copyright (C) 2012 Sven-Ola, All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* * Small user space daemon to get the Android DNS server setting and * maintain the resolver config on a regulary basis. Note, that this * daemon has to be started by some running android programs, in order * to have the ANDROID_PROPERTY_WORKSPACE environment variable and * the /dev/ashmem file descriptor (usually #9) that is inherited from * the calling process. Another note: cannot be started from a login * shell, because "bash --login" closes all inherited file descriptors. */ #include #include #include #include #include #include #include "sys/system_properties.h" /* For futex syscall */ #include #include #include #include /* * This syscall is required by Android's properties handling in system_properties.c */ int __futex_wait(volatile void *ftx, int val, const struct timespec *timeout) { return syscall(SYS_futex, ftx, FUTEX_WAIT, val, (void *)timeout, NULL, NULL); } #define DNS1_PROP "net.dns1" #define DNS2_PROP "net.dns2" #define SBIN_RESOLV_CONF "/sbin/resolvconf" static int debug = 0; static int update_resolvconf(int add, const char* iface, const char* dns1, const char* dns2) { FILE* f = 0; char s[256]; snprintf(s, sizeof(s), "%s %s %s", SBIN_RESOLV_CONF, add ? "-a" : "-d", iface); if (0 != (f = popen(s, "w"))) { if (debug) printf("piping to \"%s\":\n", s); if (dns1 && *dns1) { if (debug) printf("nameserver %s\n", dns1); fprintf(f, "nameserver %s\n", dns1); } if (dns2 && *dns2) { if (debug) printf("nameserver %s\n", dns2); fprintf(f, "nameserver %s\n", dns2); } if (0 <= fclose(f)) return 0; perror("pclose"); } else { perror(s); } return -1; } static void daemonize(void) { int i; pid_t pid, sid; /* already a daemon */ if (getppid() == 1) return; /* Fork off the parent process */ pid = fork(); if (pid < 0) { perror("cannot fork"); exit(EXIT_FAILURE); } /* If we got a good PID, then we can exit the parent process. */ if (pid > 0) exit(EXIT_SUCCESS); /* At this point we are executing as the child process */ /* Change the file mode mask */ umask(0); /* Create a new SID for the child process */ sid = setsid(); if (sid < 0) exit(EXIT_FAILURE); /* Change the current working directory. This prevents the current directory from being locked; hence not being able to remove it. */ if ((chdir("/")) < 0) exit(EXIT_FAILURE); /* Close all file descriptors, otherwise e.g. "adb shell" hangs during exit */ for(i = 0; i < getdtablesize(); i++) { close(i); } } int __system_properties_init(void); static void sig_handler(int signum) { switch(signum) { case SIGINT: case SIGTERM: update_resolvconf(0 == 1, "android", 0, 0); exit(0); break; } } int main(int argc, char* argv[]) { int ret; debug = (1 < argc && 0 == strcmp("-d", argv[1])); if (0 == (ret = __system_properties_init())) { char dns1[PROP_VALUE_MAX]; char dns2[PROP_VALUE_MAX]; if (0 == __system_property_get(DNS1_PROP, dns1)) dns1[0] = 0; if (0 == __system_property_get(DNS2_PROP, dns2)) dns2[0] = 0; if (0 == (ret = update_resolvconf(0 == 0, "android", dns1, dns2))) { struct sigaction sa; if (!debug) daemonize(); memset(&sa, sizeof(sa), 0); sa.sa_handler = sig_handler; sa.sa_flags = SA_RESETHAND; sigemptyset(&sa.sa_mask); if (-1 == sigaction(SIGINT, &sa, NULL) || -1 == sigaction(SIGTERM, &sa, NULL)) { perror("sigaction"); exit(EXIT_FAILURE); } while(1) { char new_dns1[PROP_VALUE_MAX]; char new_dns2[PROP_VALUE_MAX]; sleep(2); if (0 == __system_property_get(DNS1_PROP, new_dns1)) new_dns1[0] = 0; if (0 == __system_property_get(DNS2_PROP, new_dns2)) new_dns2[0] = 0; if (0 != strcmp(dns1, new_dns1) || 0 != strcmp(dns2, new_dns2)) { strcpy(dns1, new_dns1); strcpy(dns2, new_dns2); update_resolvconf(0 == 0, "android", dns1, dns2); } } } else { perror("run "SBIN_RESOLV_CONF" failed"); } } else { fprintf(stderr, "Cannot access system properties via ANDROID_PROPERTY_WORKSPACE environment setting.\n"); } return ret; }