summaryrefslogtreecommitdiffstats
path: root/toolbox
diff options
context:
space:
mode:
Diffstat (limited to 'toolbox')
-rw-r--r--toolbox/Android.mk4
-rw-r--r--toolbox/getevent.c14
-rw-r--r--toolbox/ioctl.c12
-rw-r--r--toolbox/mknod.c95
-rw-r--r--toolbox/nohup.c26
-rw-r--r--toolbox/ps.c23
6 files changed, 155 insertions, 19 deletions
diff --git a/toolbox/Android.mk b/toolbox/Android.mk
index 5383b83..26bb17b 100644
--- a/toolbox/Android.mk
+++ b/toolbox/Android.mk
@@ -68,7 +68,9 @@ TOOLS := \
swapon \
swapoff \
mkswap \
- readlink
+ readlink \
+ mknod \
+ nohup
ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
TOOLS += r
diff --git a/toolbox/getevent.c b/toolbox/getevent.c
index ed381f5..c979c99 100644
--- a/toolbox/getevent.c
+++ b/toolbox/getevent.c
@@ -295,6 +295,7 @@ static int open_device(const char *device, int print_flags)
{
int version;
int fd;
+ int clkid = CLOCK_MONOTONIC;
struct pollfd *new_ufds;
char **new_device_names;
char name[80];
@@ -335,6 +336,11 @@ static int open_device(const char *device, int print_flags)
idstr[0] = '\0';
}
+ if (ioctl(fd, EVIOCSCLOCKID, &clkid) != 0) {
+ fprintf(stderr, "Can't enable monotonic clock reporting: %s\n", strerror(errno));
+ // a non-fatal error
+ }
+
new_ufds = realloc(ufds, sizeof(ufds[0]) * (nfds + 1));
if(new_ufds == NULL) {
fprintf(stderr, "out of memory\n");
@@ -470,9 +476,9 @@ static int scan_dir(const char *dirname, int print_flags)
return 0;
}
-static void usage(int argc, char *argv[])
+static void usage(char *name)
{
- fprintf(stderr, "Usage: %s [-t] [-n] [-s switchmask] [-S] [-v [mask]] [-d] [-p] [-i] [-l] [-q] [-c count] [-r] [device]\n", argv[0]);
+ fprintf(stderr, "Usage: %s [-t] [-n] [-s switchmask] [-S] [-v [mask]] [-d] [-p] [-i] [-l] [-q] [-c count] [-r] [device]\n", name);
fprintf(stderr, " -t: show time stamps\n");
fprintf(stderr, " -n: don't print newlines\n");
fprintf(stderr, " -s: print switch states for given bits\n");
@@ -570,7 +576,7 @@ int getevent_main(int argc, char *argv[])
fprintf(stderr, "%s: invalid option -%c\n",
argv[0], optopt);
case 'h':
- usage(argc, argv);
+ usage(argv[0]);
exit(1);
}
} while (1);
@@ -582,7 +588,7 @@ int getevent_main(int argc, char *argv[])
optind++;
}
if (optind != argc) {
- usage(argc, argv);
+ usage(argv[0]);
exit(1);
}
nfds = 1;
diff --git a/toolbox/ioctl.c b/toolbox/ioctl.c
index fb555d2..fd24885 100644
--- a/toolbox/ioctl.c
+++ b/toolbox/ioctl.c
@@ -63,10 +63,14 @@ int ioctl_main(int argc, char *argv[])
exit(1);
}
- fd = open(argv[optind], O_RDWR | O_SYNC);
- if (fd < 0) {
- fprintf(stderr, "cannot open %s\n", argv[optind]);
- return 1;
+ if (!strcmp(argv[optind], "-")) {
+ fd = STDIN_FILENO;
+ } else {
+ fd = open(argv[optind], read_only ? O_RDONLY : (O_RDWR | O_SYNC));
+ if (fd < 0) {
+ fprintf(stderr, "cannot open %s\n", argv[optind]);
+ return 1;
+ }
}
optind++;
diff --git a/toolbox/mknod.c b/toolbox/mknod.c
new file mode 100644
index 0000000..0fedece
--- /dev/null
+++ b/toolbox/mknod.c
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2014, 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.
+ * * Neither the name of Google, Inc. nor the names of its contributors
+ * may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/stat.h>
+
+static int print_usage() {
+ fprintf(stderr, "mknod <path> [b|c|u|p] <major> <minor>\n");
+ return EXIT_FAILURE;
+}
+
+int mknod_main(int argc, char **argv) {
+ char *path = NULL;
+ int major = 0;
+ int minor = 0;
+ int args = 0;
+ mode_t mode = 0660;
+
+ /* Check correct argument count is 3 or 5 */
+ if (argc != 3 && argc != 5) {
+ fprintf(stderr, "Incorrect argument count\n");
+ return print_usage();
+ }
+
+ path = argv[1];
+
+ const char node_type = *argv[2];
+ switch (node_type) {
+ case 'b':
+ mode |= S_IFBLK;
+ args = 5;
+ break;
+ case 'c':
+ case 'u':
+ mode |= S_IFCHR;
+ args = 5;
+ break;
+ case 'p':
+ mode |= S_IFIFO;
+ args = 3;
+ break;
+ default:
+ fprintf(stderr, "Invalid node type '%c'\n", node_type);
+ return print_usage();
+ }
+
+ if (argc != args) {
+ if (args == 5) {
+ fprintf(stderr, "Node type '%c' requires <major> and <minor>\n", node_type);
+ } else {
+ fprintf(stderr, "Node type '%c' does not require <major> and <minor>\n", node_type);
+ }
+ return print_usage();
+ }
+
+ if (args == 5) {
+ major = atoi(argv[3]);
+ minor = atoi(argv[4]);
+ }
+
+ if (mknod(path, mode, makedev(major, minor))) {
+ perror("Unable to create node");
+ return EXIT_FAILURE;
+ }
+ return 0;
+}
diff --git a/toolbox/nohup.c b/toolbox/nohup.c
new file mode 100644
index 0000000..363999d
--- /dev/null
+++ b/toolbox/nohup.c
@@ -0,0 +1,26 @@
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+int nohup_main(int argc, char *argv[])
+{
+ if (argc < 2) {
+ fprintf(stderr, "Usage: %s [-n] program args...\n", argv[0]);
+ return EXIT_FAILURE;
+ }
+ signal(SIGHUP, SIG_IGN);
+ argv++;
+ if (strcmp(argv[0], "-n") == 0) {
+ argv++;
+ signal(SIGINT, SIG_IGN);
+ signal(SIGSTOP, SIG_IGN);
+ signal(SIGTTIN, SIG_IGN);
+ signal(SIGTTOU, SIG_IGN);
+ signal(SIGQUIT, SIG_IGN);
+ signal(SIGTERM, SIG_IGN);
+ }
+ execvp(argv[0], argv);
+ perror(argv[0]);
+ return EXIT_FAILURE;
+}
diff --git a/toolbox/ps.c b/toolbox/ps.c
index 7c35ccb..de141fc 100644
--- a/toolbox/ps.c
+++ b/toolbox/ps.c
@@ -28,6 +28,7 @@ static char *nexttok(char **strp)
#define SHOW_POLICY 4
#define SHOW_CPU 8
#define SHOW_MACLABEL 16
+#define SHOW_NUMERIC_UID 32
static int display_flags = 0;
@@ -45,7 +46,7 @@ static int ps_line(int pid, int tid, char *namefilter)
unsigned utime, stime;
int prio, nice, rtprio, sched, psr;
struct passwd *pw;
-
+
sprintf(statline, "/proc/%d", pid);
stat(statline, &stats);
@@ -67,7 +68,7 @@ static int ps_line(int pid, int tid, char *namefilter)
}
cmdline[r] = 0;
}
-
+
fd = open(statline, O_RDONLY);
if(fd == 0) return -1;
r = read(fd, statline, 1023);
@@ -89,7 +90,7 @@ static int ps_line(int pid, int tid, char *namefilter)
nexttok(&ptr); // pgrp
nexttok(&ptr); // sid
tty = atoi(nexttok(&ptr));
-
+
nexttok(&ptr); // tpgid
nexttok(&ptr); // flags
nexttok(&ptr); // minflt
@@ -129,21 +130,21 @@ static int ps_line(int pid, int tid, char *namefilter)
psr = atoi(nexttok(&ptr)); // processor
rtprio = atoi(nexttok(&ptr)); // rt_priority
sched = atoi(nexttok(&ptr)); // scheduling policy
-
+
tty = atoi(nexttok(&ptr));
-
+
if(tid != 0) {
ppid = pid;
pid = tid;
}
pw = getpwuid(stats.st_uid);
- if(pw == 0) {
+ if(pw == 0 || (display_flags & SHOW_NUMERIC_UID)) {
sprintf(user,"%d",(int)stats.st_uid);
} else {
strcpy(user,pw->pw_name);
}
-
+
if(!namefilter || !strncmp(name, namefilter, strlen(namefilter))) {
if (display_flags & SHOW_MACLABEL) {
fd = open(macline, O_RDONLY);
@@ -189,7 +190,7 @@ void ps_threads(int pid, char *namefilter)
sprintf(tmp,"/proc/%d/task",pid);
d = opendir(tmp);
if(d == 0) return;
-
+
while((de = readdir(d)) != 0){
if(isdigit(de->d_name[0])){
int tid = atoi(de->d_name);
@@ -197,7 +198,7 @@ void ps_threads(int pid, char *namefilter)
ps_line(pid, tid, namefilter);
}
}
- closedir(d);
+ closedir(d);
}
int ps_main(int argc, char **argv)
@@ -207,13 +208,15 @@ int ps_main(int argc, char **argv)
char *namefilter = 0;
int pidfilter = 0;
int threads = 0;
-
+
d = opendir("/proc");
if(d == 0) return -1;
while(argc > 1){
if(!strcmp(argv[1],"-t")) {
threads = 1;
+ } else if(!strcmp(argv[1],"-n")) {
+ display_flags |= SHOW_NUMERIC_UID;
} else if(!strcmp(argv[1],"-x")) {
display_flags |= SHOW_TIME;
} else if(!strcmp(argv[1], "-Z")) {