summaryrefslogtreecommitdiffstats
path: root/cmds
diff options
context:
space:
mode:
authorNick Kralevich <nnk@google.com>2015-03-19 19:11:11 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-03-19 19:11:11 +0000
commit4796bc3b27186de67f1af732be87e20ab1757198 (patch)
tree8b85d8696e00915de1ea0d3f5e896a94aad66604 /cmds
parent1a309eba79067bd3d1f73406fdcbc44a385a0c4d (diff)
parent4b9d0b9b676afec086bf579015b2f74623b357fd (diff)
downloadframeworks_native-4796bc3b27186de67f1af732be87e20ab1757198.zip
frameworks_native-4796bc3b27186de67f1af732be87e20ab1757198.tar.gz
frameworks_native-4796bc3b27186de67f1af732be87e20ab1757198.tar.bz2
am 4b9d0b9b: am f3201498: Merge "dumpstate: add O_CLOEXEC"
* commit '4b9d0b9b676afec086bf579015b2f74623b357fd': dumpstate: add O_CLOEXEC
Diffstat (limited to 'cmds')
-rw-r--r--cmds/dumpstate/dumpstate.c7
-rw-r--r--cmds/dumpstate/utils.c15
2 files changed, 11 insertions, 11 deletions
diff --git a/cmds/dumpstate/dumpstate.c b/cmds/dumpstate/dumpstate.c
index 0cad9d8..8922d54 100644
--- a/cmds/dumpstate/dumpstate.c
+++ b/cmds/dumpstate/dumpstate.c
@@ -438,7 +438,7 @@ int main(int argc, char *argv[]) {
/* set as high priority, and protect from OOM killer */
setpriority(PRIO_PROCESS, 0, -20);
- FILE *oom_adj = fopen("/proc/self/oom_adj", "w");
+ FILE *oom_adj = fopen("/proc/self/oom_adj", "we");
if (oom_adj) {
fputs("-17", oom_adj);
fclose(oom_adj);
@@ -471,15 +471,14 @@ int main(int argc, char *argv[]) {
/* open the vibrator before dropping root */
FILE *vibrator = 0;
if (do_vibrate) {
- vibrator = fopen("/sys/class/timed_output/vibrator/enable", "w");
+ vibrator = fopen("/sys/class/timed_output/vibrator/enable", "we");
if (vibrator) {
- fcntl(fileno(vibrator), F_SETFD, FD_CLOEXEC);
vibrate(vibrator, 150);
}
}
/* read /proc/cmdline before dropping root */
- FILE *cmdline = fopen("/proc/cmdline", "r");
+ FILE *cmdline = fopen("/proc/cmdline", "re");
if (cmdline != NULL) {
fgets(cmdline_buf, sizeof(cmdline_buf), cmdline);
fclose(cmdline);
diff --git a/cmds/dumpstate/utils.c b/cmds/dumpstate/utils.c
index 48f59e1..3d9a2b5 100644
--- a/cmds/dumpstate/utils.c
+++ b/cmds/dumpstate/utils.c
@@ -104,7 +104,7 @@ static void __for_each_pid(void (*helper)(int, const char *, void *), const char
sprintf(cmdpath,"/proc/%d/cmdline", pid);
memset(cmdline, 0, sizeof(cmdline));
- if ((fd = TEMP_FAILURE_RETRY(open(cmdpath, O_RDONLY))) < 0) {
+ if ((fd = TEMP_FAILURE_RETRY(open(cmdpath, O_RDONLY | O_CLOEXEC))) < 0) {
strcpy(cmdline, "N/A");
} else {
read(fd, cmdline, sizeof(cmdline) - 1);
@@ -155,7 +155,7 @@ static void for_each_tid_helper(int pid, const char *cmdline, void *arg) {
sprintf(commpath,"/proc/%d/comm", tid);
memset(comm, 0, sizeof(comm));
- if ((fd = TEMP_FAILURE_RETRY(open(commpath, O_RDONLY))) < 0) {
+ if ((fd = TEMP_FAILURE_RETRY(open(commpath, O_RDONLY | O_CLOEXEC))) < 0) {
strcpy(comm, "N/A");
} else {
char *c;
@@ -186,7 +186,7 @@ void show_wchan(int pid, int tid, const char *name) {
memset(buffer, 0, sizeof(buffer));
sprintf(path, "/proc/%d/wchan", tid);
- if ((fd = TEMP_FAILURE_RETRY(open(path, O_RDONLY))) < 0) {
+ if ((fd = TEMP_FAILURE_RETRY(open(path, O_RDONLY | O_CLOEXEC))) < 0) {
printf("Failed to open '%s' (%s)\n", path, strerror(errno));
return;
}
@@ -483,6 +483,7 @@ void redirect_to_socket(FILE *redirect, const char *service) {
fprintf(stderr, "android_get_control_socket(%s): %s\n", service, strerror(errno));
exit(1);
}
+ fcntl(s, F_SETFD, FD_CLOEXEC);
if (listen(s, 4) < 0) {
fprintf(stderr, "listen(control socket): %s\n", strerror(errno));
exit(1);
@@ -519,7 +520,7 @@ void redirect_to_file(FILE *redirect, char *path) {
}
}
- int fd = TEMP_FAILURE_RETRY(open(path, O_WRONLY | O_CREAT | O_TRUNC,
+ int fd = TEMP_FAILURE_RETRY(open(path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH));
if (fd < 0) {
fprintf(stderr, "%s: %s\n", path, strerror(errno));
@@ -575,7 +576,7 @@ const char *dump_traces() {
}
/* create a new, empty traces.txt file to receive stack dumps */
- int fd = TEMP_FAILURE_RETRY(open(traces_path, O_CREAT | O_WRONLY | O_TRUNC | O_NOFOLLOW,
+ int fd = TEMP_FAILURE_RETRY(open(traces_path, O_CREAT | O_WRONLY | O_TRUNC | O_NOFOLLOW | O_CLOEXEC,
0666)); /* -rw-rw-rw- */
if (fd < 0) {
fprintf(stderr, "%s: %s\n", traces_path, strerror(errno));
@@ -626,7 +627,7 @@ const char *dump_traces() {
if (!strncmp(data, "/system/bin/app_process", strlen("/system/bin/app_process"))) {
/* skip zygote -- it won't dump its stack anyway */
snprintf(path, sizeof(path), "/proc/%d/cmdline", pid);
- int cfd = TEMP_FAILURE_RETRY(open(path, O_RDONLY));
+ int cfd = TEMP_FAILURE_RETRY(open(path, O_RDONLY | O_CLOEXEC));
len = read(cfd, data, sizeof(data) - 1);
close(cfd);
if (len <= 0) {
@@ -711,7 +712,7 @@ error_close_fd:
void dump_route_tables() {
const char* const RT_TABLES_PATH = "/data/misc/net/rt_tables";
dump_file("RT_TABLES", RT_TABLES_PATH);
- FILE* fp = fopen(RT_TABLES_PATH, "r");
+ FILE* fp = fopen(RT_TABLES_PATH, "re");
if (!fp) {
printf("*** %s: %s\n", RT_TABLES_PATH, strerror(errno));
return;