Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/debianutils


Ignore:
Timestamp:
Jan 1, 2014, 12:47:38 AM (10 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.21.1
Location:
branches/3.2/mindi-busybox/debianutils
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mindi-busybox/debianutils/mktemp.c

    r2725 r3232  
    3232 */
    3333
     34//usage:#define mktemp_trivial_usage
     35//usage:       "[-dt] [-p DIR] [TEMPLATE]"
     36//usage:#define mktemp_full_usage "\n\n"
     37//usage:       "Create a temporary file with name based on TEMPLATE and print its name.\n"
     38//usage:       "TEMPLATE must end with XXXXXX (e.g. [/dir/]nameXXXXXX).\n"
     39//usage:       "Without TEMPLATE, -t tmp.XXXXXX is assumed.\n"
     40//usage:     "\n    -d  Make directory, not file"
     41//usage:     "\n    -q  Fail silently on errors"
     42//usage:     "\n    -t  Prepend base directory name to TEMPLATE"
     43//usage:     "\n    -p DIR  Use DIR as a base directory (implies -t)"
     44//usage:     "\n    -u  Do not create anything; print a name"
     45//usage:     "\n"
     46//usage:     "\nBase directory is: -p DIR, else $TMPDIR, else /tmp"
     47//usage:
     48//usage:#define mktemp_example_usage
     49//usage:       "$ mktemp /tmp/temp.XXXXXX\n"
     50//usage:       "/tmp/temp.mWiLjM\n"
     51//usage:       "$ ls -la /tmp/temp.mWiLjM\n"
     52//usage:       "-rw-------    1 andersen andersen        0 Apr 25 17:10 /tmp/temp.mWiLjM\n"
    3453
    3554#include "libbb.h"
     
    4160    char *chp;
    4261    unsigned opts;
     62    enum {
     63        OPT_d = 1 << 0,
     64        OPT_q = 1 << 1,
     65        OPT_t = 1 << 2,
     66        OPT_p = 1 << 3,
     67        OPT_u = 1 << 4,
     68    };
    4369
    4470    path = getenv("TMPDIR");
     
    4672        path = "/tmp";
    4773
    48     /* -q and -t are ignored */
    4974    opt_complementary = "?1"; /* 1 argument max */
    50     opts = getopt32(argv, "dqtp:", &path);
     75    opts = getopt32(argv, "dqtp:u", &path);
    5176
    52     chp = argv[optind] ? argv[optind] : xstrdup("tmp.XXXXXX");
    53     if (!strchr(chp, '/') || (opts & 8))
     77    chp = argv[optind];
     78    if (!chp) {
     79        /* GNU coreutils 8.4:
     80         * bare "mktemp" -> "mktemp -t tmp.XXXXXX"
     81         */
     82        chp = xstrdup("tmp.XXXXXX");
     83        opts |= OPT_t;
     84    }
     85#if 0
     86    /* Don't allow directory separator in template */
     87    if ((opts & OPT_t) && bb_basename(chp) != chp) {
     88        errno = EINVAL;
     89        goto error;
     90    }
     91#endif
     92    if (opts & (OPT_t|OPT_p))
    5493        chp = concat_path_file(path, chp);
    5594
    56     if (opts & 1) { /* -d */
     95    if (opts & OPT_u) {
     96        chp = mktemp(chp);
     97        if (chp[0] == '\0')
     98            goto error;
     99    } else if (opts & OPT_d) {
    57100        if (mkdtemp(chp) == NULL)
    58             return EXIT_FAILURE;
     101            goto error;
    59102    } else {
    60103        if (mkstemp(chp) < 0)
    61             return EXIT_FAILURE;
     104            goto error;
    62105    }
    63 
    64106    puts(chp);
    65 
    66107    return EXIT_SUCCESS;
     108 error:
     109    if (opts & OPT_q)
     110        return EXIT_FAILURE;
     111    /* don't use chp as it gets mangled in case of error */
     112    bb_perror_nomsg_and_die();
    67113}
  • branches/3.2/mindi-busybox/debianutils/pipe_progress.c

    r2725 r3232  
    77 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    88 */
     9
     10//usage:#define pipe_progress_trivial_usage NOUSAGE_STR
     11//usage:#define pipe_progress_full_usage ""
     12
    913#include "libbb.h"
    1014
  • branches/3.2/mindi-busybox/debianutils/run_parts.c

    r2725 r3232  
    55 * Copyright (C) 2007 Bernhard Reutner-Fischer
    66 *
    7  * Based on a older version that was in busybox which was 1k big..
     7 * Based on a older version that was in busybox which was 1k big.
    88 *   Copyright (C) 2001 by Emanuele Aina <emanuele.aina@tiscali.it>
    99 *
     
    1111 *   Copyright (C) 1996 Jeff Noxon <jeff@router.patch.net>,
    1212 *   Copyright (C) 1996-1999 Guy Maor <maor@debian.org>
    13  *
    1413 *
    1514 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
     
    2019
    2120/* This piece of code is heavily based on the original version of run-parts,
    22  * taken from debian-utils. I've only removed the long options and a the
     21 * taken from debian-utils. I've only removed the long options and the
    2322 * report mode. As the original run-parts support only long options, I've
    2423 * broken compatibility because the BusyBox policy doesn't allow them.
     
    3029 * -u MASK      umask. Set the umask of the program executed to MASK.
    3130 */
     31
     32//usage:#define run_parts_trivial_usage
     33//usage:       "[-t"IF_FEATURE_RUN_PARTS_FANCY("l")"] [-a ARG]... [-u MASK] DIRECTORY"
     34//usage:#define run_parts_full_usage "\n\n"
     35//usage:       "Run a bunch of scripts in DIRECTORY\n"
     36//usage:     "\n    -t  Dry run"
     37//usage:    IF_FEATURE_RUN_PARTS_FANCY(
     38//usage:     "\n    -l  Print names of matching files even if they are not executable"
     39//usage:    )
     40//usage:     "\n    -a ARG  Pass ARG as argument to programs"
     41//usage:     "\n    -u MASK Set umask to MASK before running programs"
     42//usage:
     43//usage:#define run_parts_example_usage
     44//usage:       "$ run-parts -a start /etc/init.d\n"
     45//usage:       "$ run-parts -a stop=now /etc/init.d\n\n"
     46//usage:       "Let's assume you have a script foo/dosomething:\n"
     47//usage:       "#!/bin/sh\n"
     48//usage:       "for i in $*; do eval $i; done; unset i\n"
     49//usage:       "case \"$1\" in\n"
     50//usage:       "start*) echo starting something;;\n"
     51//usage:       "stop*) set -x; shutdown -h $stop;;\n"
     52//usage:       "esac\n\n"
     53//usage:       "Running this yields:\n"
     54//usage:       "$run-parts -a stop=+4m foo/\n"
     55//usage:       "+ shutdown -h +4m"
    3256
    3357#include "libbb.h"
     
    4266#define cur   (G.cur  )
    4367#define cmd   (G.cmd  )
     68#define INIT_G() do { } while (0)
    4469
    4570enum { NUM_CMD = (COMMON_BUFSIZE - sizeof(G)) / sizeof(cmd[0]) - 1 };
     
    119144    int ret;
    120145
     146    INIT_G();
     147
    121148#if ENABLE_FEATURE_RUN_PARTS_LONG_OPTIONS
    122149    applet_long_options = runparts_longopts;
  • branches/3.2/mindi-busybox/debianutils/start_stop_daemon.c

    r2725 r3232  
    3232with /proc/$PID/exe or argv[0] (comm can't be matched, it never contains path)]
    3333        -x,--exec EXECUTABLE    Look for processes that were started with this
    34                                 command in /proc/$PID/cmdline.
     34                                command in /proc/$PID/exe and /proc/$PID/cmdline
     35                                (/proc/$PID/cmdline is a bbox extension)
    3536                                Unlike -n, we match against the full path:
    3637                                "ntpd" != "./ntpd" != "/path/to/ntpd"
     
    5657        -v,--verbose            Verbose
    5758*/
     59
     60//usage:#define start_stop_daemon_trivial_usage
     61//usage:       "[OPTIONS] [-S|-K] ... [-- ARGS...]"
     62//usage:#define start_stop_daemon_full_usage "\n\n"
     63//usage:       "Search for matching processes, and then\n"
     64//usage:       "-K: stop all matching processes.\n"
     65//usage:       "-S: start a process unless a matching process is found.\n"
     66//usage:    IF_FEATURE_START_STOP_DAEMON_LONG_OPTIONS(
     67//usage:     "\nProcess matching:"
     68//usage:     "\n    -u,--user USERNAME|UID  Match only this user's processes"
     69//usage:     "\n    -n,--name NAME      Match processes with NAME"
     70//usage:     "\n                in comm field in /proc/PID/stat"
     71//usage:     "\n    -x,--exec EXECUTABLE    Match processes with this command"
     72//usage:     "\n                in /proc/PID/{exe,cmdline}"
     73//usage:     "\n    -p,--pidfile FILE   Match a process with PID from the file"
     74//usage:     "\n    All specified conditions must match"
     75//usage:     "\n-S only:"
     76//usage:     "\n    -x,--exec EXECUTABLE    Program to run"
     77//usage:     "\n    -a,--startas NAME   Zeroth argument"
     78//usage:     "\n    -b,--background     Background"
     79//usage:    IF_FEATURE_START_STOP_DAEMON_FANCY(
     80//usage:     "\n    -N,--nicelevel N    Change nice level"
     81//usage:    )
     82//usage:     "\n    -c,--chuid USER[:[GRP]] Change to user/group"
     83//usage:     "\n    -m,--make-pidfile   Write PID to the pidfile specified by -p"
     84//usage:     "\n-K only:"
     85//usage:     "\n    -s,--signal SIG     Signal to send"
     86//usage:     "\n    -t,--test       Match only, exit with 0 if a process is found"
     87//usage:     "\nOther:"
     88//usage:    IF_FEATURE_START_STOP_DAEMON_FANCY(
     89//usage:     "\n    -o,--oknodo     Exit with status 0 if nothing is done"
     90//usage:     "\n    -v,--verbose        Verbose"
     91//usage:    )
     92//usage:     "\n    -q,--quiet      Quiet"
     93//usage:    )
     94//usage:    IF_NOT_FEATURE_START_STOP_DAEMON_LONG_OPTIONS(
     95//usage:     "\nProcess matching:"
     96//usage:     "\n    -u USERNAME|UID Match only this user's processes"
     97//usage:     "\n    -n NAME     Match processes with NAME"
     98//usage:     "\n            in comm field in /proc/PID/stat"
     99//usage:     "\n    -x EXECUTABLE   Match processes with this command"
     100//usage:     "\n            command in /proc/PID/cmdline"
     101//usage:     "\n    -p FILE     Match a process with PID from the file"
     102//usage:     "\n    All specified conditions must match"
     103//usage:     "\n-S only:"
     104//usage:     "\n    -x EXECUTABLE   Program to run"
     105//usage:     "\n    -a NAME     Zeroth argument"
     106//usage:     "\n    -b      Background"
     107//usage:    IF_FEATURE_START_STOP_DAEMON_FANCY(
     108//usage:     "\n    -N N        Change nice level"
     109//usage:    )
     110//usage:     "\n    -c USER[:[GRP]] Change to user/group"
     111//usage:     "\n    -m      Write PID to the pidfile specified by -p"
     112//usage:     "\n-K only:"
     113//usage:     "\n    -s SIG      Signal to send"
     114//usage:     "\n    -t      Match only, exit with 0 if a process is found"
     115//usage:     "\nOther:"
     116//usage:    IF_FEATURE_START_STOP_DAEMON_FANCY(
     117//usage:     "\n    -o      Exit with status 0 if nothing is done"
     118//usage:     "\n    -v      Verbose"
     119//usage:    )
     120//usage:     "\n    -q      Quiet"
     121//usage:    )
    58122
    59123#include <sys/resource.h>
     
    136200    ssize_t bytes;
    137201    char buf[sizeof("/proc/%u/cmdline") + sizeof(int)*3];
    138 
    139     sprintf(buf, "/proc/%u/cmdline", (unsigned)pid);
     202    char *procname, *exelink;
     203    int match;
     204
     205    procname = buf + sprintf(buf, "/proc/%u/exe", (unsigned)pid) - 3;
     206
     207    exelink = xmalloc_readlink(buf);
     208    match = (exelink && strcmp(execname, exelink) == 0);
     209    free(exelink);
     210    if (match)
     211        return match;
     212
     213    strcpy(procname, "cmdline");
    140214    bytes = open_read_close(buf, G.execname_cmpbuf, G.execname_sizeof);
    141215    if (bytes > 0) {
     
    275349    }
    276350    for (p = G.found_procs; p; p = p->next) {
    277         if (TEST || kill(p->pid, signal_nr) == 0) {
     351        if (kill(p->pid, TEST ? 0 : signal_nr) == 0) {
    278352            killed++;
    279353        } else {
     354            bb_perror_msg("warning: killing process %u", (unsigned)p->pid);
    280355            p->pid = 0;
    281             bb_perror_msg("warning: killing process %u", (unsigned)p->pid);
     356            if (TEST) {
     357                /* Example: -K --test --pidfile PIDFILE detected
     358                 * that PIDFILE's pid doesn't exist */
     359                killed = -1;
     360                goto ret;
     361            }
    282362        }
    283363    }
     
    406486    if (opt & OPT_BACKGROUND) {
    407487#if BB_MMU
    408         bb_daemonize(DAEMON_DEVNULL_STDIO + DAEMON_CLOSE_EXTRA_FDS);
     488        bb_daemonize(DAEMON_DEVNULL_STDIO + DAEMON_CLOSE_EXTRA_FDS + DAEMON_DOUBLE_FORK);
    409489        /* DAEMON_DEVNULL_STDIO is superfluous -
    410490         * it's always done by bb_daemonize() */
     
    434514        struct bb_uidgid_t ugid = { -1, -1 };
    435515        parse_chown_usergroup_or_die(&ugid, chuid);
    436         if (ugid.gid != (gid_t) -1) xsetgid(ugid.gid);
    437         if (ugid.uid != (uid_t) -1) xsetuid(ugid.uid);
     516        if (ugid.uid != (uid_t) -1) {
     517            struct passwd *pw = xgetpwuid(ugid.uid);
     518            if (ugid.gid != (gid_t) -1)
     519                pw->pw_gid = ugid.gid;
     520            /* initgroups, setgid, setuid: */
     521            change_identity(pw);
     522        } else if (ugid.gid != (gid_t) -1) {
     523            xsetgid(ugid.gid);
     524            setgroups(1, &ugid.gid);
     525        }
    438526    }
    439527#if ENABLE_FEATURE_START_STOP_DAEMON_FANCY
  • branches/3.2/mindi-busybox/debianutils/which.c

    r2725 r3232  
    1010 * Based on which from debianutils
    1111 */
     12
     13//usage:#define which_trivial_usage
     14//usage:       "[COMMAND]..."
     15//usage:#define which_full_usage "\n\n"
     16//usage:       "Locate a COMMAND"
     17//usage:
     18//usage:#define which_example_usage
     19//usage:       "$ which login\n"
     20//usage:       "/bin/login\n"
    1221
    1322#include "libbb.h"
Note: See TracChangeset for help on using the changeset viewer.