summaryrefslogtreecommitdiffstats
path: root/toolbox
diff options
context:
space:
mode:
Diffstat (limited to 'toolbox')
-rw-r--r--toolbox/Android.mk1
-rw-r--r--toolbox/date.c38
-rw-r--r--toolbox/syren.c8
-rw-r--r--toolbox/top.c28
4 files changed, 57 insertions, 18 deletions
diff --git a/toolbox/Android.mk b/toolbox/Android.mk
index 3deb3e7..5383b83 100644
--- a/toolbox/Android.mk
+++ b/toolbox/Android.mk
@@ -95,6 +95,7 @@ LOCAL_SRC_FILES := \
LOCAL_C_INCLUDES := bionic/libc/bionic
LOCAL_CFLAGS += \
+ -std=gnu99 \
-Wno-unused-parameter \
-include bsd-compatibility.h \
diff --git a/toolbox/date.c b/toolbox/date.c
index d6c9052..aa3b72e 100644
--- a/toolbox/date.c
+++ b/toolbox/date.c
@@ -1,10 +1,13 @@
+#include <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
#include <string.h>
-#include <errno.h>
#include <time.h>
+#include <unistd.h>
+
#include <linux/android_alarm.h>
#include <linux/rtc.h>
#include <sys/ioctl.h>
@@ -108,6 +111,33 @@ static void settime(char *s) {
settime_rtc_tm(&tm);
}
+static char *parse_time(const char *str, struct timeval *ts) {
+ char *s;
+ long fs = 0; /* fractional seconds */
+
+ ts->tv_sec = strtoumax(str, &s, 10);
+
+ if (*s == '.') {
+ s++;
+ int count = 0;
+
+ /* read up to 6 digits (microseconds) */
+ while (*s && isdigit(*s)) {
+ if (++count < 7) {
+ fs = fs*10 + (*s - '0');
+ }
+ s++;
+ }
+
+ for (; count < 6; count++) {
+ fs *= 10;
+ }
+ }
+
+ ts->tv_usec = fs;
+ return s;
+}
+
int date_main(int argc, char *argv[])
{
int c;
@@ -181,7 +211,7 @@ int date_main(int argc, char *argv[])
//strptime(argv[optind], NULL, &tm);
//tv.tv_sec = mktime(&tm);
//tv.tv_usec = 0;
- strtotimeval(argv[optind], &tv);
+ parse_time(argv[optind], &tv);
printf("time %s -> %lu.%lu\n", argv[optind], tv.tv_sec, tv.tv_usec);
res = settime_alarm_timeval(&tv);
if (res < 0)
diff --git a/toolbox/syren.c b/toolbox/syren.c
index 06e329e..47c2460 100644
--- a/toolbox/syren.c
+++ b/toolbox/syren.c
@@ -123,7 +123,11 @@ syren_main(int argc, char **argv)
r = find_reg(argv[2]);
if (r == NULL) {
- strcpy(name, argv[2]);
+ if(strlen(argv[2]) >= sizeof(name)){
+ fprintf(stderr, "REGNAME too long\n");
+ return 0;
+ }
+ strlcpy(name, argv[2], sizeof(name));
char *addr_str = strchr(argv[2], ':');
if (addr_str == NULL)
return usage();
@@ -131,7 +135,7 @@ syren_main(int argc, char **argv)
sio.page = strtoul(argv[2], 0, 0);
sio.addr = strtoul(addr_str, 0, 0);
} else {
- strcpy(name, r->name);
+ strlcpy(name, r->name, sizeof(name));
sio.page = r->page;
sio.addr = r->addr;
}
diff --git a/toolbox/top.c b/toolbox/top.c
index 7642522..7382f1f 100644
--- a/toolbox/top.c
+++ b/toolbox/top.c
@@ -9,7 +9,7 @@
* 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
+ * the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google, Inc. nor the names of its contributors
* may be used to endorse or promote products derived from this
@@ -22,7 +22,7 @@
* 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
+ * 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
@@ -108,16 +108,20 @@ static int proc_thr_cmp(const void *a, const void *b);
static int numcmp(long long a, long long b);
static void usage(char *cmd);
-int top_main(int argc, char *argv[]) {
- int i;
+static void exit_top(int signal) {
+ exit(EXIT_FAILURE);
+}
+int top_main(int argc, char *argv[]) {
num_used_procs = num_free_procs = 0;
+ signal(SIGPIPE, exit_top);
+
max_procs = 0;
delay = 3;
iterations = -1;
proc_cmp = &proc_cpu_cmp;
- for (i = 1; i < argc; i++) {
+ for (int i = 1; i < argc; i++) {
if (!strcmp(argv[i], "-m")) {
if (i + 1 >= argc) {
fprintf(stderr, "Option -m expects an argument.\n");
@@ -249,9 +253,9 @@ static void read_procs(void) {
continue;
pid = atoi(pid_dir->d_name);
-
+
struct proc_info cur_proc;
-
+
if (!threads) {
proc = alloc_proc();
@@ -275,7 +279,7 @@ static void read_procs(void) {
sprintf(filename, "/proc/%d/status", pid);
read_status(filename, &cur_proc);
-
+
proc = NULL;
}
@@ -310,7 +314,7 @@ static void read_procs(void) {
}
closedir(task_dir);
-
+
if (!threads)
add_proc(proc_num++, proc);
}
@@ -339,7 +343,7 @@ static int read_stat(char *filename, struct proc_info *proc) {
*open_paren = *close_paren = '\0';
strncpy(proc->tname, open_paren + 1, THREAD_NAME_LEN);
proc->tname[THREAD_NAME_LEN-1] = 0;
-
+
/* Scan rest of string. */
sscanf(close_paren + 1, " %c %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d "
"%lu %lu %*d %*d %*d %*d %*d %*d %*d %lu %ld "
@@ -452,7 +456,7 @@ static void print_procs(void) {
new_cpu.sirqtime - old_cpu.sirqtime,
total_delta_time);
printf("\n");
- if (!threads)
+ if (!threads)
printf("%5s %2s %4s %1s %5s %7s %7s %3s %-8s %s\n", "PID", "PR", "CPU%", "S", "#THR", "VSS", "RSS", "PCY", "UID", "Name");
else
printf("%5s %5s %2s %4s %1s %7s %7s %3s %-8s %-15s %s\n", "PID", "TID", "PR", "CPU%", "S", "VSS", "RSS", "PCY", "UID", "Thread", "Proc");
@@ -476,7 +480,7 @@ static void print_procs(void) {
snprintf(group_buf, 20, "%d", proc->gid);
group_str = group_buf;
}
- if (!threads)
+ if (!threads)
printf("%5d %2d %3ld%% %c %5d %6ldK %6ldK %3s %-8.8s %s\n", proc->pid, proc->prs, proc->delta_time * 100 / total_delta_time, proc->state, proc->num_threads,
proc->vss / 1024, proc->rss * getpagesize() / 1024, proc->policy, user_str, proc->name[0] != 0 ? proc->name : proc->tname);
else