diff --git a/toolbox/Android.mk b/toolbox/Android.mk index 77df4d43a..c53f17da5 100644 --- a/toolbox/Android.mk +++ b/toolbox/Android.mk @@ -33,12 +33,14 @@ TOOLS := \ lsof \ md5 \ mkdir \ + mknod \ mkswap \ mount \ mv \ nandread \ netstat \ newfs_msdos \ + nohup \ notify \ printenv \ ps \ diff --git a/toolbox/getevent.c b/toolbox/getevent.c index c2256ff8d..da83ec38d 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"); @@ -568,7 +574,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); @@ -580,7 +586,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/mknod.c b/toolbox/mknod.c new file mode 100644 index 000000000..0fedece91 --- /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 +#include +#include +#include + +static int print_usage() { + fprintf(stderr, "mknod [b|c|u|p] \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 and \n", node_type); + } else { + fprintf(stderr, "Node type '%c' does not require and \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 000000000..363999d0b --- /dev/null +++ b/toolbox/nohup.c @@ -0,0 +1,26 @@ +#include +#include +#include +#include + +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; +}