summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Kondik <steve@cyngn.com>2016-03-12 18:45:46 -0800
committerSteve Kondik <steve@cyngn.com>2016-03-12 18:45:46 -0800
commit583922233ea19ef7ec5a74f408806f4419fad996 (patch)
tree3c1c97b70ffcb48283127fce998013131e446f78
parent3cc2ca8b255cbc06a2977d44a7f53162de542908 (diff)
parent81fba043fafba2576ba3ce7a087347b79e162260 (diff)
downloadsystem_core-583922233ea19ef7ec5a74f408806f4419fad996.zip
system_core-583922233ea19ef7ec5a74f408806f4419fad996.tar.gz
system_core-583922233ea19ef7ec5a74f408806f4419fad996.tar.bz2
Merge branch 'dr15' into cm-13.0
-rw-r--r--adb/adb.cpp2
-rw-r--r--adb/commandline.cpp6
-rw-r--r--libcutils/sched_policy.c6
-rw-r--r--liblog/Android.mk4
-rw-r--r--logcat/logcat.cpp2
-rw-r--r--logcat/tests/logcat_test.cpp134
-rw-r--r--rootdir/init.rc13
-rw-r--r--rootdir/init.trace.rc2
-rw-r--r--sdcard/sdcard.c45
9 files changed, 176 insertions, 38 deletions
diff --git a/adb/adb.cpp b/adb/adb.cpp
index f64b19f..c09aee3 100644
--- a/adb/adb.cpp
+++ b/adb/adb.cpp
@@ -919,7 +919,7 @@ int handle_host_request(char *service, transport_type ttype, char* serial, int r
if(!strncmp(service,"get-state",strlen("get-state"))) {
transport = acquire_one_transport(CS_ANY, ttype, serial, NULL);
SendOkay(reply_fd);
- SendProtocolString(reply_fd, transport->connection_state_name());
+ SendProtocolString(reply_fd, transport ? transport->connection_state_name() : "unknown");
return 0;
}
#endif // ADB_HOST
diff --git a/adb/commandline.cpp b/adb/commandline.cpp
index d38588f..26eea2f 100644
--- a/adb/commandline.cpp
+++ b/adb/commandline.cpp
@@ -756,8 +756,10 @@ static int logcat(transport_type transport, const char* serial, int argc, const
static int mkdirs(const char *path)
{
+ std::string holder(path);
+
int ret;
- char *x = (char *)path + 1;
+ char *x = &holder[1];
for(;;) {
x = adb_dirstart(x);
@@ -774,7 +776,7 @@ static int mkdirs(const char *path)
}
static int backup(int argc, const char** argv) {
- const char* filename = "./backup.ab";
+ const char* filename = "backup.ab";
/* find, extract, and use any -f argument */
for (int i = 1; i < argc; i++) {
diff --git a/libcutils/sched_policy.c b/libcutils/sched_policy.c
index 83222f4..70dc8c4 100644
--- a/libcutils/sched_policy.c
+++ b/libcutils/sched_policy.c
@@ -61,6 +61,7 @@ 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 system_bg_cpuset_fd = -1;
static int bg_cpuset_fd = -1;
static int fg_cpuset_fd = -1;
@@ -126,6 +127,8 @@ static void __initialize(void) {
fg_cpuset_fd = open(filename, O_WRONLY | O_CLOEXEC);
filename = "/dev/cpuset/background/tasks";
bg_cpuset_fd = open(filename, O_WRONLY | O_CLOEXEC);
+ filename = "/dev/cpuset/system-background/tasks";
+ system_bg_cpuset_fd = open(filename, O_WRONLY | O_CLOEXEC);
}
#endif
@@ -260,6 +263,9 @@ int set_cpuset_policy(int tid, SchedPolicy policy)
case SP_AUDIO_SYS:
fd = fg_cpuset_fd;
break;
+ case SP_SYSTEM:
+ fd = system_bg_cpuset_fd;
+ break;
default:
fd = -1;
break;
diff --git a/liblog/Android.mk b/liblog/Android.mk
index 6714498..115dd79 100644
--- a/liblog/Android.mk
+++ b/liblog/Android.mk
@@ -25,13 +25,11 @@ include $(CLEAR_VARS)
liblog_cflags := -DLIBLOG_LOG_TAG=1005
ifneq ($(TARGET_USES_LOGD),false)
-liblog_sources := logd_write.c
+liblog_sources := logd_write.c log_event_write.c
else
liblog_sources := logd_write_kern.c
endif
-liblog_sources += log_event_write.c
-
# some files must not be compiled when building against Mingw
# they correspond to features not used by our host development tools
# which are also hard or even impossible to port to native Win32
diff --git a/logcat/logcat.cpp b/logcat/logcat.cpp
index 07d0a5c..47f0136 100644
--- a/logcat/logcat.cpp
+++ b/logcat/logcat.cpp
@@ -654,7 +654,7 @@ int main(int argc, char **argv)
break;
case 'f':
- if ((tail_time == log_time::EPOCH) && (tail_lines != 0)) {
+ if ((tail_time == log_time::EPOCH) && (tail_lines == 0)) {
tail_time = lastLogTime(optarg);
}
// redirect output to a file
diff --git a/logcat/tests/logcat_test.cpp b/logcat/tests/logcat_test.cpp
index de2db67..9455d87 100644
--- a/logcat/tests/logcat_test.cpp
+++ b/logcat/tests/logcat_test.cpp
@@ -15,10 +15,12 @@
*/
#include <ctype.h>
+#include <dirent.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/types.h>
#include <gtest/gtest.h>
#include <log/log.h>
@@ -284,7 +286,7 @@ TEST(logcat, get_size) {
while (fgets(buffer, sizeof(buffer), fp)) {
int size, consumed, max, payload;
- char size_mult[2], consumed_mult[2];
+ char size_mult[3], consumed_mult[3];
long full_size, full_consumed;
size = consumed = max = payload = 0;
@@ -489,12 +491,12 @@ TEST(logcat, logrotate) {
static const char comm[] = "logcat -b radio -b events -b system -b main"
" -d -f %s/log.txt -n 7 -r 1";
char command[sizeof(buf) + sizeof(comm)];
- sprintf(command, comm, buf);
+ snprintf(command, sizeof(command), comm, buf);
int ret;
EXPECT_FALSE((ret = system(command)));
if (!ret) {
- sprintf(command, "ls -s %s 2>/dev/null", buf);
+ snprintf(command, sizeof(command), "ls -s %s 2>/dev/null", buf);
FILE *fp;
EXPECT_TRUE(NULL != (fp = popen(command, "r")));
@@ -503,16 +505,12 @@ TEST(logcat, logrotate) {
int count = 0;
while (fgets(buffer, sizeof(buffer), fp)) {
- static const char match_1[] = "4 log.txt";
- static const char match_2[] = "8 log.txt";
- static const char match_3[] = "12 log.txt";
- static const char match_4[] = "16 log.txt";
static const char total[] = "total ";
+ int num;
+ char c;
- if (!strncmp(buffer, match_1, sizeof(match_1) - 1)
- || !strncmp(buffer, match_2, sizeof(match_2) - 1)
- || !strncmp(buffer, match_3, sizeof(match_3) - 1)
- || !strncmp(buffer, match_4, sizeof(match_4) - 1)) {
+ if ((2 == sscanf(buffer, "%d log.tx%c", &num, &c)) &&
+ (num <= 24)) {
++count;
} else if (strncmp(buffer, total, sizeof(total) - 1)) {
fprintf(stderr, "WARNING: Parse error: %s", buffer);
@@ -522,7 +520,7 @@ TEST(logcat, logrotate) {
EXPECT_TRUE(count == 7 || count == 8);
}
}
- sprintf(command, "rm -rf %s", buf);
+ snprintf(command, sizeof(command), "rm -rf %s", buf);
EXPECT_FALSE(system(command));
}
@@ -534,12 +532,12 @@ TEST(logcat, logrotate_suffix) {
static const char logcat_cmd[] = "logcat -b radio -b events -b system -b main"
" -d -f %s/log.txt -n 10 -r 1";
char command[sizeof(tmp_out_dir) + sizeof(logcat_cmd)];
- sprintf(command, logcat_cmd, tmp_out_dir);
+ snprintf(command, sizeof(command), logcat_cmd, tmp_out_dir);
int ret;
EXPECT_FALSE((ret = system(command)));
if (!ret) {
- sprintf(command, "ls %s 2>/dev/null", tmp_out_dir);
+ snprintf(command, sizeof(command), "ls %s 2>/dev/null", tmp_out_dir);
FILE *fp;
EXPECT_TRUE(NULL != (fp = popen(command, "r")));
@@ -575,7 +573,113 @@ TEST(logcat, logrotate_suffix) {
pclose(fp);
EXPECT_EQ(11, log_file_count);
}
- sprintf(command, "rm -rf %s", tmp_out_dir);
+ snprintf(command, sizeof(command), "rm -rf %s", tmp_out_dir);
+ EXPECT_FALSE(system(command));
+}
+
+TEST(logcat, logrotate_continue) {
+ static const char tmp_out_dir_form[] = "/data/local/tmp/logcat.logrotate.XXXXXX";
+ char tmp_out_dir[sizeof(tmp_out_dir_form)];
+ ASSERT_TRUE(NULL != mkdtemp(strcpy(tmp_out_dir, tmp_out_dir_form)));
+
+ static const char log_filename[] = "log.txt";
+ static const char logcat_cmd[] = "logcat -b all -d -f %s/%s -n 256 -r 1024";
+ static const char cleanup_cmd[] = "rm -rf %s";
+ char command[sizeof(tmp_out_dir) + sizeof(logcat_cmd) + sizeof(log_filename)];
+ snprintf(command, sizeof(command), logcat_cmd, tmp_out_dir, log_filename);
+
+ int ret;
+ EXPECT_FALSE((ret = system(command)));
+ if (ret) {
+ snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir);
+ EXPECT_FALSE(system(command));
+ return;
+ }
+ FILE *fp;
+ snprintf(command, sizeof(command), "%s/%s", tmp_out_dir, log_filename);
+ EXPECT_TRUE(NULL != ((fp = fopen(command, "r"))));
+ if (!fp) {
+ snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir);
+ EXPECT_FALSE(system(command));
+ return;
+ }
+ char *line = NULL;
+ char *last_line = NULL; // this line is allowed to stutter, one-line overlap
+ char *second_last_line = NULL;
+ size_t len = 0;
+ while (getline(&line, &len, fp) != -1) {
+ free(second_last_line);
+ second_last_line = last_line;
+ last_line = line;
+ line = NULL;
+ }
+ fclose(fp);
+ free(line);
+ if (second_last_line == NULL) {
+ fprintf(stderr, "No second to last line, using last, test may fail\n");
+ second_last_line = last_line;
+ last_line = NULL;
+ }
+ free(last_line);
+ EXPECT_TRUE(NULL != second_last_line);
+ if (!second_last_line) {
+ snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir);
+ EXPECT_FALSE(system(command));
+ return;
+ }
+ // re-run the command, it should only add a few lines more content if it
+ // continues where it left off.
+ snprintf(command, sizeof(command), logcat_cmd, tmp_out_dir, log_filename);
+ EXPECT_FALSE((ret = system(command)));
+ if (ret) {
+ snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir);
+ EXPECT_FALSE(system(command));
+ return;
+ }
+ DIR *dir;
+ EXPECT_TRUE(NULL != (dir = opendir(tmp_out_dir)));
+ if (!dir) {
+ snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir);
+ EXPECT_FALSE(system(command));
+ return;
+ }
+ struct dirent *entry;
+ unsigned count = 0;
+ while ((entry = readdir(dir))) {
+ if (strncmp(entry->d_name, log_filename, sizeof(log_filename) - 1)) {
+ continue;
+ }
+ snprintf(command, sizeof(command), "%s/%s", tmp_out_dir, entry->d_name);
+ EXPECT_TRUE(NULL != ((fp = fopen(command, "r"))));
+ if (!fp) {
+ fprintf(stderr, "%s ?\n", command);
+ continue;
+ }
+ line = NULL;
+ size_t number = 0;
+ while (getline(&line, &len, fp) != -1) {
+ ++number;
+ if (!strcmp(line, second_last_line)) {
+ EXPECT_TRUE(++count <= 1);
+ fprintf(stderr, "%s(%zu):\n", entry->d_name, number);
+ }
+ }
+ fclose(fp);
+ free(line);
+ unlink(command);
+ }
+ closedir(dir);
+ if (count > 1) {
+ char *brk = strpbrk(second_last_line, "\r\n");
+ if (!brk) {
+ brk = second_last_line + strlen(second_last_line);
+ }
+ fprintf(stderr, "\"%.*s\" occured %u times\n",
+ (int)(brk - second_last_line), second_last_line, count);
+ }
+ free(second_last_line);
+
+ snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir);
EXPECT_FALSE(system(command));
}
diff --git a/rootdir/init.rc b/rootdir/init.rc
index 5c6b606..78adacc 100644
--- a/rootdir/init.rc
+++ b/rootdir/init.rc
@@ -21,6 +21,8 @@ on early-init
# Set the security context of /adb_keys if present.
restorecon /adb_keys
+ mount debugfs /sys/kernel/debug /sys/kernel/debug mode=755
+
start ueventd
on init
@@ -169,13 +171,19 @@ on init
chown system system /dev/cpuset/foreground
chown system system /dev/cpuset/foreground/boost
chown system system /dev/cpuset/background
+ chown system system /dev/cpuset/system-background
chown system system /dev/cpuset/tasks
chown system system /dev/cpuset/foreground/tasks
chown system system /dev/cpuset/foreground/boost/tasks
chown system system /dev/cpuset/background/tasks
+ chown system system /dev/cpuset/system-background/tasks
+
+ # set system-background to 0775 so SurfaceFlinger can touch it
+ chmod 0775 /dev/cpuset/system-background
chmod 0664 /dev/cpuset/foreground/tasks
chmod 0664 /dev/cpuset/foreground/boost/tasks
chmod 0664 /dev/cpuset/background/tasks
+ chmod 0664 /dev/cpuset/system-background/tasks
chmod 0664 /dev/cpuset/tasks
@@ -653,7 +661,6 @@ service surfaceflinger /system/bin/surfaceflinger
user system
group graphics drmrpc
onrestart restart zygote
- writepid /dev/cpuset/system-background/tasks
service drm /system/bin/drmserver
class main
@@ -759,10 +766,10 @@ on property:persist.logd.logpersistd=logcatd
# all exec/services are called with umask(077), so no gain beyond 0700
mkdir /data/misc/logd 0700 logd log
# logd for write to /data/misc/logd, log group for read from pstore (-L)
- exec - logd log -- /system/bin/logcat -L -b all -v threadtime -v usec -v printable -D -f /data/misc/logd/logcat -r 64 -n 256
+ exec - logd log -- /system/bin/logcat -L -b all -v threadtime -v usec -v printable -D -f /data/misc/logd/logcat -r 1024 -n 256
start logcatd
-service logcatd /system/bin/logcat -b all -v threadtime -v usec -v printable -D -f /data/misc/logd/logcat -r 64 -n 256
+service logcatd /system/bin/logcat -b all -v threadtime -v usec -v printable -D -f /data/misc/logd/logcat -r 1024 -n 256
class late_start
disabled
# logd for write to /data/misc/logd, log group for read from log daemon
diff --git a/rootdir/init.trace.rc b/rootdir/init.trace.rc
index 50944e6..4933156 100644
--- a/rootdir/init.trace.rc
+++ b/rootdir/init.trace.rc
@@ -12,6 +12,7 @@ on boot
chown root shell /sys/kernel/debug/tracing/options/print-tgid
chown root shell /sys/kernel/debug/tracing/events/sched/sched_switch/enable
chown root shell /sys/kernel/debug/tracing/events/sched/sched_wakeup/enable
+ chown root shell /sys/kernel/debug/tracing/events/sched/sched_blocked_reason/enable
chown root shell /sys/kernel/debug/tracing/events/power/cpu_frequency/enable
chown root shell /sys/kernel/debug/tracing/events/power/cpu_idle/enable
chown root shell /sys/kernel/debug/tracing/events/power/clock_set_rate/enable
@@ -24,6 +25,7 @@ on boot
chmod 0664 /sys/kernel/debug/tracing/options/print-tgid
chmod 0664 /sys/kernel/debug/tracing/events/sched/sched_switch/enable
chmod 0664 /sys/kernel/debug/tracing/events/sched/sched_wakeup/enable
+ chmod 0664 /sys/kernel/debug/tracing/events/sched/sched_blocked_reason/enable
chmod 0664 /sys/kernel/debug/tracing/events/power/cpu_frequency/enable
chmod 0664 /sys/kernel/debug/tracing/events/power/cpu_idle/enable
chmod 0664 /sys/kernel/debug/tracing/events/power/clock_set_rate/enable
diff --git a/sdcard/sdcard.c b/sdcard/sdcard.c
index 13009aa..33b1509 100644
--- a/sdcard/sdcard.c
+++ b/sdcard/sdcard.c
@@ -507,6 +507,16 @@ static void derive_permissions_locked(struct fuse* fuse, struct node *parent,
}
}
+static void derive_permissions_recursive_locked(struct fuse* fuse, struct node *parent) {
+ struct node *node;
+ for (node = parent->child; node; node = node->next) {
+ derive_permissions_locked(fuse, parent, node);
+ if (node->child) {
+ derive_permissions_recursive_locked(fuse, node);
+ }
+ }
+}
+
/* Kernel has already enforced everything we returned through
* derive_permissions_locked(), so this is used to lock down access
* even further, such as enforcing that apps hold sdcard_rw. */
@@ -1145,6 +1155,8 @@ static int handle_rename(struct fuse* fuse, struct fuse_handler* handler,
res = rename_node_locked(child_node, new_name, new_actual_name);
if (!res) {
remove_node_from_parent_locked(child_node);
+ derive_permissions_locked(fuse, new_parent_node, child_node);
+ derive_permissions_recursive_locked(fuse, child_node);
add_node_to_parent_locked(child_node, new_parent_node);
}
goto done;
@@ -1203,11 +1215,11 @@ static int handle_open(struct fuse* fuse, struct fuse_handler* handler,
out.fh = ptr_to_id(h);
out.open_flags = 0;
- #ifdef FUSE_SHORTCIRCUIT
- out.lower_fd = h->fd;
- #else
- out.padding = 0;
- #endif
+#if defined(FUSE_STACKED_IO) || defined(FUSE_SHORTCIRCUIT)
+ out.lower_fd = h->fd;
+#else
+ out.padding = 0;
+#endif
fuse_reply(fuse, hdr->unique, &out, sizeof(out));
return NO_STATUS;
@@ -1373,11 +1385,11 @@ static int handle_opendir(struct fuse* fuse, struct fuse_handler* handler,
out.fh = ptr_to_id(h);
out.open_flags = 0;
- #ifdef FUSE_SHORTCIRCUIT
- out.lower_fd = -1;
- #else
- out.padding = 0;
- #endif
+#if defined(FUSE_STACKED_IO) || defined(FUSE_SHORTCIRCUIT)
+ out.lower_fd = -1;
+#else
+ out.padding = 0;
+#endif
fuse_reply(fuse, hdr->unique, &out, sizeof(out));
return NO_STATUS;
@@ -1461,9 +1473,12 @@ static int handle_init(struct fuse* fuse, struct fuse_handler* handler,
out.max_readahead = req->max_readahead;
out.flags = FUSE_ATOMIC_O_TRUNC | FUSE_BIG_WRITES;
- #ifdef FUSE_SHORTCIRCUIT
- out.flags |= FUSE_SHORTCIRCUIT;
- #endif
+#ifdef FUSE_SHORTCIRCUIT
+ out.flags |= FUSE_SHORTCIRCUIT;
+#endif
+#ifdef FUSE_STACKED_IO
+ out.flags |= FUSE_STACKED_IO;
+#endif
out.max_background = 32;
out.congestion_threshold = 32;
@@ -1680,6 +1695,10 @@ static int read_package_list(struct fuse_global* global) {
TRACE("read_package_list: found %zu packages\n",
hashmapSize(global->package_to_appid));
fclose(file);
+
+ /* Regenerate ownership details using newly loaded mapping */
+ derive_permissions_recursive_locked(global->fuse_default, &global->root);
+
pthread_mutex_unlock(&global->lock);
return 0;
}