source: clfs-embedded/patches/busybox-1.13.3-branch_update-1.patch @ 118c546

Last change on this file since 118c546 was 118c546, checked in by Jim Gifford <clfs@…>, 15 years ago

Updated Busybox

  • Property mode set to 100644
File size: 15.2 KB
  • coreutils/tail.c

    Submitted By: Jim Gifford (jim at cross-lfs dot org)
    Date: 03-28-2009
    Initial Package Version: 1.13.3
    Origin: Upstream
    Upstream Status: Applied
    Description: This is a branch update for busybox-1.13.3, and should be
                 rechecked periodically.
    
    diff -Naur busybox-1.13.3.orig/coreutils/tail.c busybox-1.13.3/coreutils/tail.c
    old new  
    104104        if (argv[1] && (argv[1][0] == '+' || argv[1][0] == '-')
    105105         && isdigit(argv[1][1])
    106106        ) {
    107                 count = eat_num(&argv[1][1]);
     107                count = eat_num(argv[1]);
    108108                argv++;
    109109                argc--;
    110110        }
  • busybox-1.13.3

    diff -Naur busybox-1.13.3.orig/shell/ash.c busybox-1.13.3/shell/ash.c
    old new  
    3030 */
    3131
    3232/*
    33  * The follow should be set to reflect the type of system you have:
     33 * The following should be set to reflect the type of system you have:
    3434 *      JOBS -> 1 if you have Berkeley job control, 0 otherwise.
    3535 *      define SYSV if you are running under System V.
    3636 *      define DEBUG=1 to compile in debugging ('set -o debug' to turn on)
     
    4040 * a quit signal will generate a core dump.
    4141 */
    4242#define DEBUG 0
     43/* Tweak debug output verbosity here */
     44#define DEBUG_TIME 0
     45#define DEBUG_PID 1
     46#define DEBUG_SIG 1
     47
    4348#define PROFILE 0
    4449
    4550#define IFS_BROKEN
     
    4752#define JOBS ENABLE_ASH_JOB_CONTROL
    4853
    4954#if DEBUG
    50 #ifndef _GNU_SOURCE
    51 #define _GNU_SOURCE
    52 #endif
     55# ifndef _GNU_SOURCE
     56#  define _GNU_SOURCE
     57# endif
    5358#endif
    5459
    5560#include "busybox.h" /* for applet_names */
     
    5762#include <setjmp.h>
    5863#include <fnmatch.h>
    5964#if JOBS || ENABLE_ASH_READ_NCHARS
    60 #include <termios.h>
     65# include <termios.h>
    6166#endif
    6267
    6368#ifndef PIPE_BUF
    64 #define PIPE_BUF 4096           /* amount of buffering in a pipe */
     69# define PIPE_BUF 4096           /* amount of buffering in a pipe */
    6570#endif
    6671
    6772#if defined(__uClinux__)
    68 #error "Do not even bother, ash will not run on uClinux"
     73# error "Do not even bother, ash will not run on uClinux"
    6974#endif
    7075
    7176
     
    7681#define CMDTABLESIZE 31         /* should be prime */
    7782
    7883
    79 /* ============ Misc helpers */
    80 
    81 #define xbarrier() do { __asm__ __volatile__ ("": : :"memory"); } while (0)
    82 
    83 /* C99 say: "char" declaration may be signed or unsigned default */
    84 #define signed_char2int(sc) ((int)((signed char)sc))
    85 
    86 
    8784/* ============ Shell options */
    8885
    8986static const char *const optletters_optnames[] = {
     
    245242} while (0)
    246243
    247244
     245/* ============ DEBUG */
     246#if DEBUG
     247static void trace_printf(const char *fmt, ...);
     248static void trace_vprintf(const char *fmt, va_list va);
     249# define TRACE(param)    trace_printf param
     250# define TRACEV(param)   trace_vprintf param
     251# define close(f) do { \
     252        int dfd = (f); \
     253        if (close(dfd) < 0) \
     254                bb_error_msg("bug on %d: closing %d(%x)", \
     255                        __LINE__, dfd, dfd); \
     256} while (0)
     257#else
     258# define TRACE(param)
     259# define TRACEV(param)
     260#endif
     261
     262
    248263/* ============ Utility functions */
     264#define xbarrier() do { __asm__ __volatile__ ("": : :"memory"); } while (0)
     265
     266/* C99 say: "char" declaration may be signed or unsigned by default */
     267#define signed_char2int(sc) ((int)(signed char)(sc))
     268
    249269static int isdigit_str9(const char *str)
    250270{
    251271        int maxlen = 9 + 1; /* max 9 digits: 999999999 */
     
    284304        exception = e;
    285305        longjmp(exception_handler->loc, 1);
    286306}
     307#if DEBUG
     308#define raise_exception(e) do { \
     309        TRACE(("raising exception %d on line %d\n", (e), __LINE__)); \
     310        raise_exception(e); \
     311} while (0)
     312#endif
    287313
    288314/*
    289315 * Called from trap.c when a SIGINT is received.  (If the user specifies
     
    316342        raise_exception(i);
    317343        /* NOTREACHED */
    318344}
     345#if DEBUG
     346#define raise_interrupt() do { \
     347        TRACE(("raising interrupt on line %d\n", __LINE__)); \
     348        raise_interrupt(); \
     349} while (0)
     350#endif
    319351
    320352#if ENABLE_ASH_OPTIMIZE_FOR_SIZE
    321353static void
     
    334366                raise_interrupt();
    335367}
    336368#define FORCE_INT_ON force_int_on()
    337 #else
     369
     370#else /* !ASH_OPTIMIZE_FOR_SIZE */
     371
    338372#define INT_ON do { \
    339373        xbarrier(); \
    340374        if (--suppressint == 0 && intpending) \
     
    346380        if (intpending) \
    347381                raise_interrupt(); \
    348382} while (0)
    349 #endif /* ASH_OPTIMIZE_FOR_SIZE */
     383#endif /* !ASH_OPTIMIZE_FOR_SIZE */
    350384
    351385#define SAVE_INT(v) ((v) = suppressint)
    352386
     
    376410onsig(int signo)
    377411{
    378412        gotsig[signo - 1] = 1;
    379         pendingsig = signo;
    380413
    381414        if (/* exsig || */ (signo == SIGINT && !trap[SIGINT])) {
    382415                if (!suppressint) {
     
    384417                        raise_interrupt(); /* does not return */
    385418                }
    386419                intpending = 1;
     420        } else {
     421                pendingsig = signo;
    387422        }
    388423}
    389424
     
    684719
    685720        if (debug != 1)
    686721                return;
     722        if (DEBUG_TIME)
     723                fprintf(tracefile, "%u ", (int) time(NULL));
     724        if (DEBUG_PID)
     725                fprintf(tracefile, "[%u] ", (int) getpid());
     726        if (DEBUG_SIG)
     727                fprintf(tracefile, "pending s:%d i:%d(supp:%d) ", pendingsig, intpending, suppressint);
    687728        va_start(va, fmt);
    688729        vfprintf(tracefile, fmt, va);
    689730        va_end(va);
     
    694735{
    695736        if (debug != 1)
    696737                return;
     738        if (DEBUG_TIME)
     739                fprintf(tracefile, "%u ", (int) time(NULL));
     740        if (DEBUG_PID)
     741                fprintf(tracefile, "[%u] ", (int) getpid());
     742        if (DEBUG_SIG)
     743                fprintf(tracefile, "pending s:%d i:%d(supp:%d) ", pendingsig, intpending, suppressint);
    697744        vfprintf(tracefile, fmt, va);
    698745}
    699746
     
    9981045        shtree(n, 1, NULL, stdout);
    9991046}
    10001047
    1001 #define TRACE(param)    trace_printf param
    1002 #define TRACEV(param)   trace_vprintf param
    1003 
    1004 #else
    1005 
    1006 #define TRACE(param)
    1007 #define TRACEV(param)
    1008 
    10091048#endif /* DEBUG */
    10101049
    10111050
     
    37793818         * NB: _not_ safe_waitpid, we need to detect EINTR */
    37803819        pid = waitpid(-1, &status,
    37813820                        (doing_jobctl ? (wait_flags | WUNTRACED) : wait_flags));
    3782         TRACE(("wait returns pid=%d, status=0x%x\n", pid, status));
     3821        TRACE(("wait returns pid=%d, status=0x%x, errno=%d(%s)\n", pid, status, errno, strerror(errno)));
    37833822
    37843823        if (pid <= 0) {
    37853824                /* If we were doing blocking wait and (probably) got EINTR,
     
    50315070                if (newfd < 0) {
    50325071                        /* NTOFD/NFROMFD: copy redir->ndup.dupfd to fd */
    50335072                        if (redir->ndup.dupfd < 0) { /* "fd>&-" */
    5034                                 close(fd);
     5073                                /* Don't want to trigger debugging */
     5074                                if (fd != -1)
     5075                                        close(fd);
    50355076                        } else {
    50365077                                copyfd(redir->ndup.dupfd, fd | COPYFD_EXACT);
    50375078                        }
     
    50845125                                /*close(fd);*/
    50855126                                copyfd(copy, fd | COPYFD_EXACT);
    50865127                        }
    5087                         close(copy);
     5128                        close(copy & ~COPYFD_RESTORE);
    50885129                }
    50895130        }
    50905131        redirlist = rp->next;
     
    78717912        pendingsig = 0;
    78727913        xbarrier();
    78737914
     7915        TRACE(("dotrap entered\n"));
    78747916        for (i = 1, q = gotsig; i < NSIG; i++, q++) {
    78757917                if (!*q)
    78767918                        continue;
    7877                 *q = '\0';
    78787919
    78797920                p = trap[i];
     7921                /* non-trapped SIGINT is handled separately by raise_interrupt,
     7922                 * don't upset it by resetting gotsig[SIGINT-1] */
     7923                if (i == SIGINT && !p)
     7924                        continue;
     7925
     7926                TRACE(("sig %d is active, will run handler '%s'\n", i, p));
     7927                *q = '\0';
    78807928                if (!p)
    78817929                        continue;
    78827930                skip = evalstring(p, SKIPEVAL);
    78837931                exitstatus = savestatus;
    7884                 if (skip)
     7932                if (skip) {
     7933                        TRACE(("dotrap returns %d\n", skip));
    78857934                        return skip;
     7935                }
    78867936        }
    78877937
     7938        TRACE(("dotrap returns 0\n"));
    78887939        return 0;
    78897940}
    78907941
     
    79067957static void
    79077958evaltree(union node *n, int flags)
    79087959{
    7909 
    79107960        struct jmploc *volatile savehandler = exception_handler;
    79117961        struct jmploc jmploc;
    79127962        int checkexit = 0;
    79137963        void (*evalfn)(union node *, int);
    79147964        int status;
     7965        int int_level;
     7966
     7967        SAVE_INT(int_level);
    79157968
    79167969        if (n == NULL) {
    79177970                TRACE(("evaltree(NULL) called\n"));
    79187971                goto out1;
    79197972        }
    7920         TRACE(("pid %d, evaltree(%p: %d, %d) called\n",
    7921                         getpid(), n, n->type, flags));
     7973        TRACE(("evaltree(%p: %d, %d) called\n", n, n->type, flags));
    79227974
    79237975        exception_handler = &jmploc;
    79247976        {
    79257977                int err = setjmp(jmploc.loc);
    79267978                if (err) {
    79277979                        /* if it was a signal, check for trap handlers */
    7928                         if (exception == EXSIG)
     7980                        if (exception == EXSIG) {
     7981                                TRACE(("exception %d (EXSIG) in evaltree, err=%d\n", exception, err));
    79297982                                goto out;
     7983                        }
    79307984                        /* continue on the way out */
     7985                        TRACE(("exception %d in evaltree, propagating err=%d\n", exception, err));
    79317986                        exception_handler = savehandler;
    79327987                        longjmp(exception_handler->loc, err);
    79337988                }
     
    80108065                if (exitstatus == 0) {
    80118066                        n = n->nif.ifpart;
    80128067                        goto evaln;
    8013                 } else if (n->nif.elsepart) {
     8068                }
     8069                if (n->nif.elsepart) {
    80148070                        n = n->nif.elsepart;
    80158071                        goto evaln;
    80168072                }
     
    80368092 exexit:
    80378093                raise_exception(EXEXIT);
    80388094        }
     8095
     8096        RESTORE_INT(int_level);
     8097        TRACE(("leaving evaltree (no interrupts)\n"));
    80398098}
    80408099
    80418100#if !defined(__alpha__) || (defined(__GNUC__) && __GNUC__ >= 3)
     
    82818340                if (prevfd >= 0)
    82828341                        close(prevfd);
    82838342                prevfd = pip[0];
    8284                 close(pip[1]);
     8343                /* Don't want to trigger debugging */
     8344                if (pip[1] != -1)
     8345                        close(pip[1]);
    82858346        }
    82868347        if (n->npipe.pipe_backgnd == 0) {
    82878348                exitstatus = waitforjob(jp);
     
    89138974                        if (forkshell(jp, cmd, FORK_FG) != 0) {
    89148975                                exitstatus = waitforjob(jp);
    89158976                                INT_ON;
     8977                                TRACE(("forked child exited with %d\n", exitstatus));
    89168978                                break;
    89178979                        }
    89188980                        FORCE_INT_ON;
     
    1364013702        exception_handler = &jmploc;
    1364113703#if DEBUG
    1364213704        opentrace();
    13643         trace_puts("Shell args: ");
     13705        TRACE(("Shell args: "));
    1364413706        trace_puts_args(argv);
    1364513707#endif
    1364613708        rootpid = getpid();
     
    1369213754        }
    1369313755 state3:
    1369413756        state = 4;
    13695         if (minusc)
     13757        if (minusc) {
     13758                /* evalstring pushes parsefile stack.
     13759                 * Ensure we don't falsely claim that 0 (stdin)
     13760                 * is one of stacked source fds */
     13761                if (!sflag)
     13762                        g_parsefile->fd = -1;
    1369613763                evalstring(minusc, 0);
     13764        }
    1369713765
    1369813766        if (sflag || minusc == NULL) {
    1369913767#if ENABLE_FEATURE_EDITING_SAVEHISTORY
     
    1372013788        /* NOTREACHED */
    1372113789}
    1372213790
    13723 #if DEBUG
    13724 const char *applet_name = "debug stuff usage";
    13725 int main(int argc, char **argv)
    13726 {
    13727         return ash_main(argc, argv);
    13728 }
    13729 #endif
    13730 
    1373113791
    1373213792/*-
    1373313793 * Copyright (c) 1989, 1991, 1993, 1994
  • busybox-1.13.3

    diff -Naur busybox-1.13.3.orig/shell/hush.c busybox-1.13.3/shell/hush.c
    old new  
    458458        smallint fake_mode;
    459459        /* these three support $?, $#, and $1 */
    460460        smalluint last_return_code;
    461         char **global_argv;
     461        /* is global_argv and global_argv[1..n] malloced? (note: not [0]) */
     462        smalluint global_args_malloced;
     463        /* how many non-NULL argv's we have. NB: $# + 1 */
    462464        int global_argc;
     465        char **global_argv;
    463466#if ENABLE_HUSH_LOOPS
    464467        unsigned depth_break_continue;
    465468        unsigned depth_of_loop;
     
    633636        return dst;
    634637}
    635638
    636 static char **add_strings_to_strings(char **strings, char **add)
     639static char **add_strings_to_strings(char **strings, char **add, int need_to_dup)
    637640{
    638641        int i;
    639642        unsigned count1;
     
    658661        v[count1 + count2] = NULL;
    659662        i = count2;
    660663        while (--i >= 0)
    661                 v[count1 + i] = add[i];
     664                v[count1 + i] = (need_to_dup ? xstrdup(add[i]) : add[i]);
    662665        return v;
    663666}
    664667
     
    667670        char *v[2];
    668671        v[0] = add;
    669672        v[1] = NULL;
    670         return add_strings_to_strings(strings, v);
     673        return add_strings_to_strings(strings, v, /*dup:*/ 0);
    671674}
    672675
    673676static void putenv_all(char **strings)
     
    12131216 * Otherwise, just finish current list[] and start new */
    12141217static int o_save_ptr(o_string *o, int n)
    12151218{
    1216         if (o->o_glob)
    1217                 return o_glob(o, n); /* o_save_ptr_helper is inside */
     1219        if (o->o_glob) { /* if globbing is requested */
     1220                /* If o->has_empty_slot, list[n] was already globbed
     1221                 * (if it was requested back then when it was filled)
     1222                 * so don't do that again! */
     1223                if (!o->has_empty_slot)
     1224                        return o_glob(o, n); /* o_save_ptr_helper is inside */
     1225        }
    12181226        return o_save_ptr_helper(o, n);
    12191227}
    12201228
     
    42794287                switch (opt) {
    42804288                case 'c':
    42814289                        G.global_argv = argv + optind;
     4290                        if (!argv[optind]) {
     4291                                /* -c 'script' (no params): prevent empty $0 */
     4292                                *--G.global_argv = argv[0];
     4293                                optind--;
     4294                        } /* else -c 'script' PAR0 PAR1: $0 is PAR0 */
    42824295                        G.global_argc = argc - optind;
    42834296                        opt = parse_and_run_string(optarg, 0 /* parse_flag */);
    42844297                        goto final_return;
     
    46394652        return set_local_var(string, 0);
    46404653}
    46414654
    4642 /* built-in 'set [VAR=value]' handler */
     4655/* built-in 'set' handler
     4656 * SUSv3 says:
     4657 * set [-abCefmnuvx] [-h] [-o option] [argument...]
     4658 * set [+abCefmnuvx] [+h] [+o option] [argument...]
     4659 * set -- [argument...]
     4660 * set -o
     4661 * set +o
     4662 * Implementations shall support the options in both their hyphen and
     4663 * plus-sign forms. These options can also be specified as options to sh.
     4664 * Examples:
     4665 * Write out all variables and their values: set
     4666 * Set $1, $2, and $3 and set "$#" to 3: set c a b
     4667 * Turn on the -x and -v options: set -xv
     4668 * Unset all positional parameters: set --
     4669 * Set $1 to the value of x, even if it begins with '-' or '+': set -- "$x"
     4670 * Set the positional parameters to the expansion of x, even if x expands
     4671 * with a leading '-' or '+': set -- $x
     4672 *
     4673 * So far, we only support "set -- [argument...]" by ignoring all options
     4674 * (also, "-o option" will be mishandled by taking "option" as parameter #1).
     4675 */
    46434676static int builtin_set(char **argv)
    46444677{
    4645         char *temp = argv[1];
    46464678        struct variable *e;
     4679        char **pp;
     4680        char *arg = *++argv;
    46474681
    4648         if (temp == NULL)
     4682        if (arg == NULL) {
    46494683                for (e = G.top_var; e; e = e->next)
    46504684                        puts(e->varstr);
    4651         else
    4652                 set_local_var(xstrdup(temp), 0);
     4685        } else {
     4686                /* NB: G.global_argv[0] ($0) is never freed/changed */
     4687
     4688                if (G.global_args_malloced) {
     4689                        pp = G.global_argv;
     4690                        while (*++pp)
     4691                                free(*pp);
     4692                        G.global_argv[1] = NULL;
     4693                } else {
     4694                        G.global_args_malloced = 1;
     4695                        pp = xzalloc(sizeof(pp[0]) * 2);
     4696                        pp[0] = G.global_argv[0]; /* retain $0 */
     4697                        G.global_argv = pp;
     4698                }
     4699                do  {
     4700                        if (arg[0] == '+')
     4701                                continue;
     4702                        if (arg[0] != '-')
     4703                                break;
     4704                        if (arg[1] == '-' && arg[2] == '\0') {
     4705                                argv++;
     4706                                break;
     4707                        }
     4708                } while ((arg = *++argv) != NULL);
     4709                /* Now argv[0] is 1st argument */
     4710
     4711                /* This realloc's G.global_argv */
     4712                G.global_argv = pp = add_strings_to_strings(G.global_argv, argv, /*dup:*/ 1);
     4713                G.global_argc = 1;
     4714                while (*++pp)
     4715                        G.global_argc++;
     4716        }
    46534717
    46544718        return EXIT_SUCCESS;
    46554719}
     
    46614725                n = atoi(argv[1]);
    46624726        }
    46634727        if (n >= 0 && n < G.global_argc) {
    4664                 G.global_argv[n] = G.global_argv[0];
     4728                if (G.global_args_malloced) {
     4729                        int m = 1;
     4730                        while (m <= n)
     4731                                free(G.global_argv[m++]);
     4732                }
    46654733                G.global_argc -= n;
    4666                 G.global_argv += n;
     4734                memmove(&G.global_argv[1], &G.global_argv[n+1],
     4735                                G.global_argc * sizeof(G.global_argv[0]));
    46674736                return EXIT_SUCCESS;
    46684737        }
    46694738        return EXIT_FAILURE;
  • shell/hush_test/hush-parsing/starquoted2.right

    diff -Naur busybox-1.13.3.orig/shell/hush_test/hush-parsing/starquoted2.right busybox-1.13.3/shell/hush_test/hush-parsing/starquoted2.right
    old new  
    11Should be printed
    22Should be printed
     3Empty:
  • shell/hush_test/hush-parsing/starquoted2.tests

    diff -Naur busybox-1.13.3.orig/shell/hush_test/hush-parsing/starquoted2.tests busybox-1.13.3/shell/hush_test/hush-parsing/starquoted2.tests
    old new  
    1212for a in """$@"; do echo Should not be printed; done
    1313for a in """$@"''"$@"''; do echo Should not be printed; done
    1414for a in ""; do echo Should be printed; done
     15
     16# Bug 207: "$@" expands to nothing, and we erroneously glob "%s\\n" twice:
     17printf "Empty:%s\\n" "$@"
Note: See TracBrowser for help on using the repository browser.