Merge changes I46586cba,I6c500ab5,I2f7d9934

* changes:
  Add mknod utility to system/core/toolbox
  Getevent: make sure the monotonic timestamp is displayed; warning cleanup.
  toolbox: Add nohup command
This commit is contained in:
Colin Cross 2014-06-11 18:14:39 +00:00 committed by Gerrit Code Review
commit f2521e76ff
4 changed files with 133 additions and 4 deletions

View File

@ -33,12 +33,14 @@ TOOLS := \
lsof \
md5 \
mkdir \
mknod \
mkswap \
mount \
mv \
nandread \
netstat \
newfs_msdos \
nohup \
notify \
printenv \
ps \

View File

@ -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;

95
toolbox/mknod.c Normal file
View File

@ -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;
}

26
toolbox/nohup.c Normal file
View File

@ -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;
}