diff options
Diffstat (limited to 'shell')
| -rw-r--r-- | shell/ash.c | 129 |
1 files changed, 63 insertions, 66 deletions
diff --git a/shell/ash.c b/shell/ash.c index 16a2da5ac..02ed48017 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
| @@ -663,6 +663,13 @@ var_end(const char *var) | |||
| 663 | return var; | 663 | return var; |
| 664 | } | 664 | } |
| 665 | 665 | ||
| 666 | /* Wrapper around strcmp for bsearch */ | ||
| 667 | static int | ||
| 668 | pstrcmp(const void *a, const void *b) | ||
| 669 | { | ||
| 670 | return strcmp((char*)a, *(char**)b); | ||
| 671 | } | ||
| 672 | |||
| 666 | /* Our signal logic never blocks individual signals | 673 | /* Our signal logic never blocks individual signals |
| 667 | * using signal mask - only by setting SIG_IGN handler. | 674 | * using signal mask - only by setting SIG_IGN handler. |
| 668 | * Therefore just unmasking all of them instead of "restore old mask" | 675 | * Therefore just unmasking all of them instead of "restore old mask" |
| @@ -8450,11 +8457,11 @@ struct builtincmd { | |||
| 8450 | int (*builtin)(int, char **) FAST_FUNC; | 8457 | int (*builtin)(int, char **) FAST_FUNC; |
| 8451 | /* unsigned flags; */ | 8458 | /* unsigned flags; */ |
| 8452 | }; | 8459 | }; |
| 8453 | #define IS_BUILTIN_SPECIAL(b) ((b)->name[0] & 1) | 8460 | #define IS_BUILTIN_SPECIAL(b) ((b)->name[-1] & 1) |
| 8454 | /* "regular" builtins always take precedence over commands, | 8461 | /* "regular" builtins always take precedence over commands, |
| 8455 | * regardless of PATH=....%builtin... position */ | 8462 | * regardless of PATH=....%builtin... position */ |
| 8456 | #define IS_BUILTIN_REGULAR(b) ((b)->name[0] & 2) | 8463 | #define IS_BUILTIN_REGULAR(b) ((b)->name[-1] & 2) |
| 8457 | #define IS_BUILTIN_ASSIGN(b) ((b)->name[0] & 4) | 8464 | #define IS_BUILTIN_ASSIGN(b) ((b)->name[-1] & 4) |
| 8458 | 8465 | ||
| 8459 | union param { | 8466 | union param { |
| 8460 | int index; | 8467 | int index; |
| @@ -9059,19 +9066,14 @@ static const char *const tokname_array[] ALIGN_PTR = { | |||
| 9059 | "}", | 9066 | "}", |
| 9060 | }; | 9067 | }; |
| 9061 | 9068 | ||
| 9062 | /* Wrapper around strcmp for qsort/bsearch/... */ | ||
| 9063 | static int | ||
| 9064 | pstrcmp(const void *a, const void *b) | ||
| 9065 | { | ||
| 9066 | return strcmp((char*)a, *(char**)b); | ||
| 9067 | } | ||
| 9068 | |||
| 9069 | static const char *const * | 9069 | static const char *const * |
| 9070 | findkwd(const char *s) | 9070 | findkwd(const char *s) |
| 9071 | { | 9071 | { |
| 9072 | return bsearch(s, tokname_array + KWDOFFSET, | 9072 | return bsearch( |
| 9073 | ARRAY_SIZE(tokname_array) - KWDOFFSET, | 9073 | s, tokname_array + KWDOFFSET, ARRAY_SIZE(tokname_array) - KWDOFFSET, |
| 9074 | sizeof(tokname_array[0]), pstrcmp); | 9074 | sizeof(tokname_array[0]), |
| 9075 | pstrcmp | ||
| 9076 | ); | ||
| 9075 | } | 9077 | } |
| 9076 | 9078 | ||
| 9077 | /* | 9079 | /* |
| @@ -10741,22 +10743,22 @@ static int FAST_FUNC sleepcmd(int argc, char **argv) { return sleep_main(argc, | |||
| 10741 | 10743 | ||
| 10742 | /* Keep these in proper order since it is searched via bsearch() */ | 10744 | /* Keep these in proper order since it is searched via bsearch() */ |
| 10743 | static const struct builtincmd builtintab[] = { | 10745 | static const struct builtincmd builtintab[] = { |
| 10744 | { BUILTIN_SPEC_REG "." , dotcmd }, | 10746 | { BUILTIN_SPEC_REG "." +1, dotcmd }, |
| 10745 | { BUILTIN_SPEC_REG ":" , truecmd }, | 10747 | { BUILTIN_SPEC_REG ":" +1, truecmd }, |
| 10746 | #if ENABLE_ASH_TEST | 10748 | #if ENABLE_ASH_TEST |
| 10747 | { BUILTIN_REGULAR "[" , testcmd }, | 10749 | { BUILTIN_REGULAR "[" +1, testcmd }, |
| 10748 | #endif | 10750 | #endif |
| 10749 | #if BASH_TEST2 | 10751 | #if BASH_TEST2 |
| 10750 | { BUILTIN_REGULAR "[[" , testcmd }, | 10752 | { BUILTIN_REGULAR "[[" +1, testcmd }, |
| 10751 | #endif | 10753 | #endif |
| 10752 | #if ENABLE_ASH_ALIAS | 10754 | #if ENABLE_ASH_ALIAS |
| 10753 | { BUILTIN_REG_ASSG "alias" , aliascmd }, | 10755 | { BUILTIN_REG_ASSG "alias" +1, aliascmd }, |
| 10754 | #endif | 10756 | #endif |
| 10755 | #if JOBS | 10757 | #if JOBS |
| 10756 | { BUILTIN_REGULAR "bg" , fg_bgcmd }, | 10758 | { BUILTIN_REGULAR "bg" +1, fg_bgcmd }, |
| 10757 | #endif | 10759 | #endif |
| 10758 | { BUILTIN_SPEC_REG "break" , breakcmd }, | 10760 | { BUILTIN_SPEC_REG "break" +1, breakcmd }, |
| 10759 | { BUILTIN_REGULAR "cd" , cdcmd }, | 10761 | { BUILTIN_REGULAR "cd" +1, cdcmd }, |
| 10760 | #define COMMANDCMD (builtintab + \ | 10762 | #define COMMANDCMD (builtintab + \ |
| 10761 | /* . : */ 2 + \ | 10763 | /* . : */ 2 + \ |
| 10762 | /* [ */ 1 * ENABLE_ASH_TEST + \ | 10764 | /* [ */ 1 * ENABLE_ASH_TEST + \ |
| @@ -10765,84 +10767,79 @@ static const struct builtincmd builtintab[] = { | |||
| 10765 | /* bg */ 1 * JOBS + \ | 10767 | /* bg */ 1 * JOBS + \ |
| 10766 | /* break cd */ 2) | 10768 | /* break cd */ 2) |
| 10767 | #if ENABLE_ASH_CMDCMD | 10769 | #if ENABLE_ASH_CMDCMD |
| 10768 | { BUILTIN_REGULAR "command" , commandcmd }, | 10770 | { BUILTIN_REGULAR "command" +1, commandcmd }, |
| 10769 | #endif | 10771 | #endif |
| 10770 | { BUILTIN_SPEC_REG "continue", breakcmd }, | 10772 | { BUILTIN_SPEC_REG "continue"+1, breakcmd }, |
| 10771 | #if ENABLE_ASH_ECHO | 10773 | #if ENABLE_ASH_ECHO |
| 10772 | { BUILTIN_REGULAR "echo" , echocmd }, | 10774 | { BUILTIN_REGULAR "echo" +1, echocmd }, |
| 10773 | #endif | 10775 | #endif |
| 10774 | #define EVALCMD (COMMANDCMD + \ | 10776 | #define EVALCMD (COMMANDCMD + \ |
| 10775 | /* command */ 1 * ENABLE_ASH_CMDCMD + \ | 10777 | /* command */ 1 * ENABLE_ASH_CMDCMD + \ |
| 10776 | /* continue */ 1 + \ | 10778 | /* continue */ 1 + \ |
| 10777 | /* echo */ 1 * ENABLE_ASH_ECHO + \ | 10779 | /* echo */ 1 * ENABLE_ASH_ECHO + \ |
| 10778 | 0) | 10780 | 0) |
| 10779 | { BUILTIN_SPEC_REG "eval" , NULL }, /*evalcmd() has a differing prototype*/ | 10781 | { BUILTIN_SPEC_REG "eval" +1, NULL }, /*evalcmd() has a differing prototype*/ |
| 10780 | #define EXECCMD (EVALCMD + \ | 10782 | #define EXECCMD (EVALCMD + \ |
| 10781 | /* eval */ 1) | 10783 | /* eval */ 1) |
| 10782 | { BUILTIN_SPEC_REG "exec" , execcmd }, | 10784 | { BUILTIN_SPEC_REG "exec" +1, execcmd }, |
| 10783 | { BUILTIN_SPEC_REG "exit" , exitcmd }, | 10785 | { BUILTIN_SPEC_REG "exit" +1, exitcmd }, |
| 10784 | { BUILTIN_SPEC_REG_ASSG "export" , exportcmd }, | 10786 | { BUILTIN_SPEC_REG_ASSG "export" +1, exportcmd }, |
| 10785 | { BUILTIN_REGULAR "false" , falsecmd }, | 10787 | { BUILTIN_REGULAR "false" +1, falsecmd }, |
| 10786 | #if JOBS | 10788 | #if JOBS |
| 10787 | { BUILTIN_REGULAR "fg" , fg_bgcmd }, | 10789 | { BUILTIN_REGULAR "fg" +1, fg_bgcmd }, |
| 10788 | #endif | 10790 | #endif |
| 10789 | #if ENABLE_ASH_GETOPTS | 10791 | #if ENABLE_ASH_GETOPTS |
| 10790 | { BUILTIN_REGULAR "getopts" , getoptscmd }, | 10792 | { BUILTIN_REGULAR "getopts" +1, getoptscmd }, |
| 10791 | #endif | 10793 | #endif |
| 10792 | { BUILTIN_REGULAR "hash" , hashcmd }, | 10794 | { BUILTIN_REGULAR "hash" +1, hashcmd }, |
| 10793 | #if ENABLE_ASH_HELP | 10795 | #if ENABLE_ASH_HELP |
| 10794 | { BUILTIN_NOSPEC "help" , helpcmd }, | 10796 | { BUILTIN_NOSPEC "help" +1, helpcmd }, |
| 10795 | #endif | 10797 | #endif |
| 10796 | #if MAX_HISTORY | 10798 | #if MAX_HISTORY |
| 10797 | { BUILTIN_NOSPEC "history" , historycmd }, | 10799 | { BUILTIN_NOSPEC "history" +1, historycmd }, |
| 10798 | #endif | 10800 | #endif |
| 10799 | #if JOBS | 10801 | #if JOBS |
| 10800 | { BUILTIN_REGULAR "jobs" , jobscmd }, | 10802 | { BUILTIN_REGULAR "jobs" +1, jobscmd }, |
| 10801 | { BUILTIN_REGULAR "kill" , killcmd }, | 10803 | { BUILTIN_REGULAR "kill" +1, killcmd }, |
| 10802 | #endif | 10804 | #endif |
| 10803 | #if ENABLE_FEATURE_SH_MATH | 10805 | #if ENABLE_FEATURE_SH_MATH |
| 10804 | { BUILTIN_NOSPEC "let" , letcmd }, | 10806 | { BUILTIN_NOSPEC "let" +1, letcmd }, |
| 10805 | #endif | 10807 | #endif |
| 10806 | { BUILTIN_SPEC_REG_ASSG "local" , localcmd }, | 10808 | { BUILTIN_SPEC_REG_ASSG "local" +1, localcmd }, |
| 10807 | #if ENABLE_ASH_PRINTF | 10809 | #if ENABLE_ASH_PRINTF |
| 10808 | { BUILTIN_REGULAR "printf" , printfcmd }, | 10810 | { BUILTIN_REGULAR "printf" +1, printfcmd }, |
| 10809 | #endif | 10811 | #endif |
| 10810 | { BUILTIN_REGULAR "pwd" , pwdcmd }, | 10812 | { BUILTIN_REGULAR "pwd" +1, pwdcmd }, |
| 10811 | { BUILTIN_REGULAR "read" , readcmd }, | 10813 | { BUILTIN_REGULAR "read" +1, readcmd }, |
| 10812 | { BUILTIN_SPEC_REG_ASSG "readonly", exportcmd }, | 10814 | { BUILTIN_SPEC_REG_ASSG "readonly"+1, exportcmd }, |
| 10813 | { BUILTIN_SPEC_REG "return" , returncmd }, | 10815 | { BUILTIN_SPEC_REG "return" +1, returncmd }, |
| 10814 | { BUILTIN_SPEC_REG "set" , setcmd }, | 10816 | { BUILTIN_SPEC_REG "set" +1, setcmd }, |
| 10815 | { BUILTIN_SPEC_REG "shift" , shiftcmd }, | 10817 | { BUILTIN_SPEC_REG "shift" +1, shiftcmd }, |
| 10816 | #if ENABLE_ASH_SLEEP | 10818 | #if ENABLE_ASH_SLEEP |
| 10817 | { BUILTIN_REGULAR "sleep" , sleepcmd }, | 10819 | { BUILTIN_REGULAR "sleep" +1, sleepcmd }, |
| 10818 | #endif | 10820 | #endif |
| 10819 | #if BASH_SOURCE | 10821 | #if BASH_SOURCE |
| 10820 | { BUILTIN_SPEC_REG "source" , dotcmd }, | 10822 | { BUILTIN_SPEC_REG "source" +1, dotcmd }, |
| 10821 | #endif | 10823 | #endif |
| 10822 | #if ENABLE_ASH_TEST | 10824 | #if ENABLE_ASH_TEST |
| 10823 | { BUILTIN_REGULAR "test" , testcmd }, | 10825 | { BUILTIN_REGULAR "test" +1, testcmd }, |
| 10824 | #endif | 10826 | #endif |
| 10825 | { BUILTIN_SPEC_REG "times" , timescmd }, | 10827 | { BUILTIN_SPEC_REG "times" +1, timescmd }, |
| 10826 | { BUILTIN_SPEC_REG "trap" , trapcmd }, | 10828 | { BUILTIN_SPEC_REG "trap" +1, trapcmd }, |
| 10827 | { BUILTIN_REGULAR "true" , truecmd }, | 10829 | { BUILTIN_REGULAR "true" +1, truecmd }, |
| 10828 | { BUILTIN_REGULAR "type" , typecmd }, | 10830 | { BUILTIN_REGULAR "type" +1, typecmd }, |
| 10829 | { BUILTIN_REGULAR "ulimit" , ulimitcmd }, | 10831 | { BUILTIN_REGULAR "ulimit" +1, ulimitcmd }, |
| 10830 | { BUILTIN_REGULAR "umask" , umaskcmd }, | 10832 | { BUILTIN_REGULAR "umask" +1, umaskcmd }, |
| 10831 | #if ENABLE_ASH_ALIAS | 10833 | #if ENABLE_ASH_ALIAS |
| 10832 | { BUILTIN_REGULAR "unalias" , unaliascmd }, | 10834 | { BUILTIN_REGULAR "unalias" +1, unaliascmd }, |
| 10833 | #endif | 10835 | #endif |
| 10834 | { BUILTIN_SPEC_REG "unset" , unsetcmd }, | 10836 | { BUILTIN_SPEC_REG "unset" +1, unsetcmd }, |
| 10835 | { BUILTIN_REGULAR "wait" , waitcmd }, | 10837 | { BUILTIN_REGULAR "wait" +1, waitcmd }, |
| 10836 | }; | 10838 | }; |
| 10837 | 10839 | ||
| 10838 | /* | 10840 | /* |
| 10839 | * Search the table of builtin commands. | 10841 | * Search the table of builtin commands. |
| 10840 | */ | 10842 | */ |
| 10841 | static int | ||
| 10842 | pstrcmp1(const void *a, const void *b) | ||
| 10843 | { | ||
| 10844 | return strcmp((char*)a, *(char**)b + 1); | ||
| 10845 | } | ||
| 10846 | static struct builtincmd * | 10843 | static struct builtincmd * |
| 10847 | find_builtin(const char *name) | 10844 | find_builtin(const char *name) |
| 10848 | { | 10845 | { |
| @@ -10850,7 +10847,7 @@ find_builtin(const char *name) | |||
| 10850 | 10847 | ||
| 10851 | bp = bsearch( | 10848 | bp = bsearch( |
| 10852 | name, builtintab, ARRAY_SIZE(builtintab), sizeof(builtintab[0]), | 10849 | name, builtintab, ARRAY_SIZE(builtintab), sizeof(builtintab[0]), |
| 10853 | pstrcmp1 | 10850 | pstrcmp |
| 10854 | ); | 10851 | ); |
| 10855 | return bp; | 10852 | return bp; |
| 10856 | } | 10853 | } |
| @@ -10910,7 +10907,7 @@ static int | |||
| 10910 | evalcommand(union node *cmd, int flags) | 10907 | evalcommand(union node *cmd, int flags) |
| 10911 | { | 10908 | { |
| 10912 | static const struct builtincmd null_bltin = { | 10909 | static const struct builtincmd null_bltin = { |
| 10913 | BUILTIN_REGULAR "", bltincmd | 10910 | BUILTIN_REGULAR ""+1, bltincmd |
| 10914 | }; | 10911 | }; |
| 10915 | struct localvar_list *localvar_stop; | 10912 | struct localvar_list *localvar_stop; |
| 10916 | struct parsefile *file_stop; | 10913 | struct parsefile *file_stop; |
