merge in mnc-release history after reset to mnc-dev
diff --git a/adb/adb_auth_host.cpp b/adb/adb_auth_host.cpp
index 61a3777..510dcc2 100644
--- a/adb/adb_auth_host.cpp
+++ b/adb/adb_auth_host.cpp
@@ -173,7 +173,7 @@
         return 0;
     }
 
-    outfile = fopen(path, "w");
+    outfile = fopen(path, "we");
     if (!outfile) {
         D("Failed to open '%s'\n", path);
         return 0;
@@ -239,7 +239,7 @@
 
     old_mask = umask(077);
 
-    f = fopen(file, "w");
+    f = fopen(file, "we");
     if (!f) {
         D("Failed to open '%s'\n", file);
         umask(old_mask);
@@ -273,7 +273,7 @@
 {
     D("read_key '%s'\n", file);
 
-    FILE* fp = fopen(file, "r");
+    FILE* fp = fopen(file, "re");
     if (!fp) {
         D("Failed to open '%s': %s\n", file, strerror(errno));
         return 0;
diff --git a/include/cutils/sched_policy.h b/include/cutils/sched_policy.h
index 6a8d570..ba84ce3 100644
--- a/include/cutils/sched_policy.h
+++ b/include/cutils/sched_policy.h
@@ -34,8 +34,6 @@
     SP_SYSTEM_DEFAULT = SP_FOREGROUND,
 } SchedPolicy;
 
-extern int set_cpuset_policy(int tid, SchedPolicy policy);
-
 /* Assign thread tid to the cgroup associated with the specified policy.
  * If the thread is a thread group leader, that is it's gettid() == getpid(),
  * then the other threads in the same thread group are _not_ affected.
diff --git a/libbacktrace/BacktracePtrace.cpp b/libbacktrace/BacktracePtrace.cpp
index fd8b713..e10cce1 100644
--- a/libbacktrace/BacktracePtrace.cpp
+++ b/libbacktrace/BacktracePtrace.cpp
@@ -37,6 +37,8 @@
   errno = 0;
   *out_value = ptrace(PTRACE_PEEKTEXT, tid, reinterpret_cast<void*>(addr), nullptr);
   if (*out_value == static_cast<word_t>(-1) && errno) {
+    BACK_LOGW("invalid pointer %p reading from tid %d, ptrace() strerror(errno)=%s",
+              reinterpret_cast<void*>(addr), tid, strerror(errno));
     return false;
   }
   return true;
diff --git a/libcutils/Android.mk b/libcutils/Android.mk
index 0963076..9dc15d1 100644
--- a/libcutils/Android.mk
+++ b/libcutils/Android.mk
@@ -125,9 +125,6 @@
 
 LOCAL_C_INCLUDES := $(libcutils_c_includes)
 LOCAL_STATIC_LIBRARIES := liblog
-ifneq ($(ENABLE_CPUSETS),)
-LOCAL_CFLAGS += -DUSE_CPUSETS
-endif
 LOCAL_CFLAGS += -Werror -std=gnu90
 include $(BUILD_STATIC_LIBRARY)
 
@@ -137,9 +134,6 @@
 # liblog symbols present in libcutils.
 LOCAL_WHOLE_STATIC_LIBRARIES := libcutils liblog
 LOCAL_SHARED_LIBRARIES := liblog
-ifneq ($(ENABLE_CPUSETS),)
-LOCAL_CFLAGS += -DUSE_CPUSETS
-endif
 LOCAL_CFLAGS += -Werror
 LOCAL_C_INCLUDES := $(libcutils_c_includes)
 include $(BUILD_SHARED_LIBRARY)
diff --git a/libcutils/sched_policy.c b/libcutils/sched_policy.c
index a7ff85e..dfc8777 100644
--- a/libcutils/sched_policy.c
+++ b/libcutils/sched_policy.c
@@ -1,16 +1,16 @@
 /*
 ** Copyright 2007, The Android Open Source Project
 **
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
+** Licensed under the Apache License, Version 2.0 (the "License"); 
+** you may not use this file except in compliance with the License. 
+** You may obtain a copy of the License at 
 **
-**     http://www.apache.org/licenses/LICENSE-2.0
+**     http://www.apache.org/licenses/LICENSE-2.0 
 **
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
+** Unless required by applicable law or agreed to in writing, software 
+** distributed under the License is distributed on an "AS IS" BASIS, 
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+** See the License for the specific language governing permissions and 
 ** limitations under the License.
 */
 
@@ -59,16 +59,27 @@
 static int bg_cgroup_fd = -1;
 static int fg_cgroup_fd = -1;
 
-// File descriptors open to /dev/cpuset/../tasks, setup by initialize, or -1 on error
-static int bg_cpuset_fd = -1;
-static int fg_cpuset_fd = -1;
-
 /* Add tid to the scheduling group defined by the policy */
-static int add_tid_to_cgroup(int tid, int fd)
+static int add_tid_to_cgroup(int tid, SchedPolicy policy)
 {
+    int fd;
+
+    switch (policy) {
+    case SP_BACKGROUND:
+        fd = bg_cgroup_fd;
+        break;
+    case SP_FOREGROUND:
+    case SP_AUDIO_APP:
+    case SP_AUDIO_SYS:
+        fd = fg_cgroup_fd;
+        break;
+    default:
+        fd = -1;
+        break;
+    }
+
     if (fd < 0) {
-        SLOGE("add_tid_to_cgroup failed; fd=%d\n", fd);
-        errno = EINVAL;
+        SLOGE("add_tid_to_cgroup failed; policy=%d\n", policy);
         return -1;
     }
 
@@ -89,9 +100,8 @@
          */
         if (errno == ESRCH)
                 return 0;
-        SLOGW("add_tid_to_cgroup failed to write '%s' (%s); fd=%d\n",
-              ptr, strerror(errno), fd);
-        errno = EINVAL;
+        SLOGW("add_tid_to_cgroup failed to write '%s' (%s); policy=%d\n",
+              ptr, strerror(errno), policy);
         return -1;
     }
 
@@ -117,17 +127,6 @@
     } else {
         __sys_supports_schedgroups = 0;
     }
-
-#ifdef USE_CPUSETS
-    if (!access("/dev/cpuset/tasks", F_OK)) {
-
-        filename = "/dev/cpuset/foreground/tasks";
-        fg_cpuset_fd = open(filename, O_WRONLY | O_CLOEXEC);
-        filename = "/dev/cpuset/background/tasks";
-        bg_cpuset_fd = open(filename, O_WRONLY | O_CLOEXEC);
-    }
-#endif
-
 }
 
 /*
@@ -237,45 +236,6 @@
     return 0;
 }
 
-int set_cpuset_policy(int tid, SchedPolicy policy)
-{
-    // in the absence of cpusets, use the old sched policy
-#ifndef USE_CPUSETS
-    return set_sched_policy(tid, policy);
-#else
-    if (tid == 0) {
-        tid = gettid();
-    }
-    policy = _policy(policy);
-    pthread_once(&the_once, __initialize);
-
-    int fd;
-    switch (policy) {
-    case SP_BACKGROUND:
-        fd = bg_cpuset_fd;
-        break;
-    case SP_FOREGROUND:
-    case SP_AUDIO_APP:
-    case SP_AUDIO_SYS:
-        fd = fg_cpuset_fd;
-        break;
-    default:
-        fd = -1;
-        break;
-    }
-
-    if (add_tid_to_cgroup(tid, fd) != 0) {
-        if (errno != ESRCH && errno != ENOENT)
-            return -errno;
-    }
-
-    // we do both setting of cpuset and setting of cgroup
-    // ensures that backgrounded apps are actually deprioritized
-    // including on core 0
-    return set_sched_policy(tid, policy);
-#endif
-}
-
 int set_sched_policy(int tid, SchedPolicy policy)
 {
     if (tid == 0) {
@@ -326,23 +286,7 @@
 #endif
 
     if (__sys_supports_schedgroups) {
-        int fd;
-        switch (policy) {
-        case SP_BACKGROUND:
-            fd = bg_cgroup_fd;
-            break;
-        case SP_FOREGROUND:
-        case SP_AUDIO_APP:
-        case SP_AUDIO_SYS:
-            fd = fg_cgroup_fd;
-            break;
-        default:
-            fd = -1;
-            break;
-        }
-
-
-        if (add_tid_to_cgroup(tid, fd) != 0) {
+        if (add_tid_to_cgroup(tid, policy)) {
             if (errno != ESRCH && errno != ENOENT)
                 return -errno;
         }
@@ -352,7 +296,7 @@
         param.sched_priority = 0;
         sched_setscheduler(tid,
                            (policy == SP_BACKGROUND) ?
-                           SCHED_BATCH : SCHED_NORMAL,
+                            SCHED_BATCH : SCHED_NORMAL,
                            &param);
     }
 
@@ -393,3 +337,4 @@
     else
         return "error";
 }
+
diff --git a/rootdir/init.rc b/rootdir/init.rc
index acca097..2fbac23 100644
--- a/rootdir/init.rc
+++ b/rootdir/init.rc
@@ -125,28 +125,6 @@
     write /dev/cpuctl/bg_non_interactive/cpu.rt_runtime_us 700000
     write /dev/cpuctl/bg_non_interactive/cpu.rt_period_us 1000000
 
-    # sets up initial cpusets for ActivityManager
-    mkdir /dev/cpuset
-    mount cpuset none /dev/cpuset
-    mkdir /dev/cpuset/foreground
-    mkdir /dev/cpuset/background
-    # this ensures that the cpusets are present and usable, but the device's
-    # init.rc must actually set the correct cpus
-    write /dev/cpuset/foreground/cpus 0
-    write /dev/cpuset/background/cpus 0
-    write /dev/cpuset/foreground/mems 0
-    write /dev/cpuset/background/mems 0
-    chown system system /dev/cpuset
-    chown system system /dev/cpuset/foreground
-    chown system system /dev/cpuset/background
-    chown system system /dev/cpuset/tasks
-    chown system system /dev/cpuset/foreground/tasks
-    chown system system /dev/cpuset/background/tasks
-    chmod 0644 /dev/cpuset/foreground/tasks
-    chmod 0644 /dev/cpuset/background/tasks
-    chmod 0644 /dev/cpuset/tasks
-
-
     # qtaguid will limit access to specific data based on group memberships.
     #   net_bw_acct grants impersonation of socket owners.
     #   net_bw_stats grants access to other apps' detailed tagged-socket stats.