Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f2521e76 authored by Colin Cross's avatar Colin Cross Committed by Gerrit Code Review
Browse files

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
parents 304d31f0 032d4e29
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -33,12 +33,14 @@ TOOLS := \
	lsof \
	md5 \
	mkdir \
	mknod \
	mkswap \
	mount \
	mv \
	nandread \
	netstat \
	newfs_msdos \
	nohup \
	notify \
	printenv \
	ps \
+10 −4
Original line number Diff line number Diff line
@@ -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;

toolbox/mknod.c

0 → 100644
+95 −0
Original line number Diff line number Diff line
/*
 * 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;
}

toolbox/nohup.c

0 → 100644
+26 −0
Original line number Diff line number Diff line
#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;
}