diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-01-08 17:40:18 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-01-08 17:40:18 +0100 |
commit | 7a85c60e7e370d0bc171bd10043c1eb7c20ab913 (patch) | |
tree | b031df0a1fb3a55138ed1446994d4bdd75aa1dba /shell | |
parent | 1125d7d6801940a5218b74c8fd46f1eaa2e4de39 (diff) | |
download | busybox-w32-7a85c60e7e370d0bc171bd10043c1eb7c20ab913.tar.gz busybox-w32-7a85c60e7e370d0bc171bd10043c1eb7c20ab913.tar.bz2 busybox-w32-7a85c60e7e370d0bc171bd10043c1eb7c20ab913.zip |
hush: make read and trap builtins optional
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r-- | shell/hush.c | 189 |
1 files changed, 118 insertions, 71 deletions
diff --git a/shell/hush.c b/shell/hush.c index 9aafb4d25..e6e8c1baf 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -49,7 +49,6 @@ | |||
49 | * [un]alias, command, fc, getopts, newgrp, readonly, times | 49 | * [un]alias, command, fc, getopts, newgrp, readonly, times |
50 | * make complex ${var%...} constructs support optional | 50 | * make complex ${var%...} constructs support optional |
51 | * make here documents optional | 51 | * make here documents optional |
52 | * make trap, read, ulimit builtins optional | ||
53 | * | 52 | * |
54 | * Bash compat TODO: | 53 | * Bash compat TODO: |
55 | * redirection of stdout+stderr: &> and >& | 54 | * redirection of stdout+stderr: &> and >& |
@@ -110,41 +109,6 @@ | |||
110 | //config: help | 109 | //config: help |
111 | //config: Enable {abc,def} extension. | 110 | //config: Enable {abc,def} extension. |
112 | //config: | 111 | //config: |
113 | //config:config HUSH_HELP | ||
114 | //config: bool "help builtin" | ||
115 | //config: default y | ||
116 | //config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH | ||
117 | //config: help | ||
118 | //config: Enable help builtin in hush. Code size + ~1 kbyte. | ||
119 | //config: | ||
120 | //config:config HUSH_PRINTF | ||
121 | //config: bool "printf builtin" | ||
122 | //config: default y | ||
123 | //config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH | ||
124 | //config: help | ||
125 | //config: Enable printf builtin in hush. | ||
126 | //config: | ||
127 | //config:config HUSH_KILL | ||
128 | //config: bool "kill builtin (for kill %jobspec)" | ||
129 | //config: default y | ||
130 | //config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH | ||
131 | //config: help | ||
132 | //config: Enable kill builtin in hush. | ||
133 | //config: | ||
134 | //config:config HUSH_WAIT | ||
135 | //config: bool "wait builtin" | ||
136 | //config: default y | ||
137 | //config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH | ||
138 | //config: help | ||
139 | //config: Enable wait builtin in hush. | ||
140 | //config: | ||
141 | //config:config HUSH_TYPE | ||
142 | //config: bool "type builtin" | ||
143 | //config: default y | ||
144 | //config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH | ||
145 | //config: help | ||
146 | //config: Enable type builtin in hush. | ||
147 | //config: | ||
148 | //config:config HUSH_INTERACTIVE | 112 | //config:config HUSH_INTERACTIVE |
149 | //config: bool "Interactive mode" | 113 | //config: bool "Interactive mode" |
150 | //config: default y | 114 | //config: default y |
@@ -209,7 +173,7 @@ | |||
209 | //config: Enable support for shell functions in hush. +800 bytes. | 173 | //config: Enable support for shell functions in hush. +800 bytes. |
210 | //config: | 174 | //config: |
211 | //config:config HUSH_LOCAL | 175 | //config:config HUSH_LOCAL |
212 | //config: bool "Support local builtin" | 176 | //config: bool "local builtin" |
213 | //config: default y | 177 | //config: default y |
214 | //config: depends on HUSH_FUNCTIONS | 178 | //config: depends on HUSH_FUNCTIONS |
215 | //config: help | 179 | //config: help |
@@ -238,6 +202,62 @@ | |||
238 | //config: This instructs hush to print commands before execution. | 202 | //config: This instructs hush to print commands before execution. |
239 | //config: Adds ~300 bytes. | 203 | //config: Adds ~300 bytes. |
240 | //config: | 204 | //config: |
205 | //config:config HUSH_HELP | ||
206 | //config: bool "help builtin" | ||
207 | //config: default y | ||
208 | //config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH | ||
209 | //config: help | ||
210 | //config: Enable help builtin in hush. Code size + ~1 kbyte. | ||
211 | //config: | ||
212 | //config:config HUSH_PRINTF | ||
213 | //config: bool "printf builtin" | ||
214 | //config: default y | ||
215 | //config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH | ||
216 | //config: help | ||
217 | //config: Enable printf builtin in hush. | ||
218 | //config: | ||
219 | //config:config HUSH_KILL | ||
220 | //config: bool "kill builtin (for kill %jobspec)" | ||
221 | //config: default y | ||
222 | //config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH | ||
223 | //config: help | ||
224 | //config: Enable kill builtin in hush. | ||
225 | //config: | ||
226 | //config:config HUSH_WAIT | ||
227 | //config: bool "wait builtin" | ||
228 | //config: default y | ||
229 | //config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH | ||
230 | //config: help | ||
231 | //config: Enable wait builtin in hush. | ||
232 | //config: | ||
233 | //config:config HUSH_TRAP | ||
234 | //config: bool "trap builtin" | ||
235 | //config: default y | ||
236 | //config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH | ||
237 | //config: help | ||
238 | //config: Enable trap builtin in hush. | ||
239 | //config: | ||
240 | //config:config HUSH_ULIMIT | ||
241 | //config: bool "ulimit builtin" | ||
242 | //config: default y | ||
243 | //config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH | ||
244 | //config: help | ||
245 | //config: Enable ulimit builtin in hush. | ||
246 | //config: | ||
247 | //config:config HUSH_TYPE | ||
248 | //config: bool "type builtin" | ||
249 | //config: default y | ||
250 | //config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH | ||
251 | //config: help | ||
252 | //config: Enable type builtin in hush. | ||
253 | //config: | ||
254 | //config:config HUSH_READ | ||
255 | //config: bool "read builtin" | ||
256 | //config: default y | ||
257 | //config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH | ||
258 | //config: help | ||
259 | //config: Enable read builtin in hush. | ||
260 | //config: | ||
241 | //config:config MSH | 261 | //config:config MSH |
242 | //config: bool "msh (deprecated: aliased to hush)" | 262 | //config: bool "msh (deprecated: aliased to hush)" |
243 | //config: default n | 263 | //config: default n |
@@ -842,7 +862,12 @@ struct globals { | |||
842 | #else | 862 | #else |
843 | # define G_fatal_sig_mask 0 | 863 | # define G_fatal_sig_mask 0 |
844 | #endif | 864 | #endif |
865 | #if ENABLE_HUSH_TRAP | ||
845 | char **traps; /* char *traps[NSIG] */ | 866 | char **traps; /* char *traps[NSIG] */ |
867 | # define G_traps G.traps | ||
868 | #else | ||
869 | # define G_traps ((char**)NULL) | ||
870 | #endif | ||
846 | sigset_t pending_set; | 871 | sigset_t pending_set; |
847 | #if HUSH_DEBUG | 872 | #if HUSH_DEBUG |
848 | unsigned long memleak_value; | 873 | unsigned long memleak_value; |
@@ -892,12 +917,16 @@ static int builtin_memleak(char **argv) FAST_FUNC; | |||
892 | static int builtin_printf(char **argv) FAST_FUNC; | 917 | static int builtin_printf(char **argv) FAST_FUNC; |
893 | #endif | 918 | #endif |
894 | static int builtin_pwd(char **argv) FAST_FUNC; | 919 | static int builtin_pwd(char **argv) FAST_FUNC; |
920 | #if ENABLE_HUSH_READ | ||
895 | static int builtin_read(char **argv) FAST_FUNC; | 921 | static int builtin_read(char **argv) FAST_FUNC; |
922 | #endif | ||
896 | static int builtin_set(char **argv) FAST_FUNC; | 923 | static int builtin_set(char **argv) FAST_FUNC; |
897 | static int builtin_shift(char **argv) FAST_FUNC; | 924 | static int builtin_shift(char **argv) FAST_FUNC; |
898 | static int builtin_source(char **argv) FAST_FUNC; | 925 | static int builtin_source(char **argv) FAST_FUNC; |
899 | static int builtin_test(char **argv) FAST_FUNC; | 926 | static int builtin_test(char **argv) FAST_FUNC; |
927 | #if ENABLE_HUSH_TRAP | ||
900 | static int builtin_trap(char **argv) FAST_FUNC; | 928 | static int builtin_trap(char **argv) FAST_FUNC; |
929 | #endif | ||
901 | #if ENABLE_HUSH_TYPE | 930 | #if ENABLE_HUSH_TYPE |
902 | static int builtin_type(char **argv) FAST_FUNC; | 931 | static int builtin_type(char **argv) FAST_FUNC; |
903 | #endif | 932 | #endif |
@@ -973,7 +1002,9 @@ static const struct built_in_command bltins1[] = { | |||
973 | #if HUSH_DEBUG | 1002 | #if HUSH_DEBUG |
974 | BLTIN("memleak" , builtin_memleak , NULL), | 1003 | BLTIN("memleak" , builtin_memleak , NULL), |
975 | #endif | 1004 | #endif |
1005 | #if ENABLE_HUSH_READ | ||
976 | BLTIN("read" , builtin_read , "Input into variable"), | 1006 | BLTIN("read" , builtin_read , "Input into variable"), |
1007 | #endif | ||
977 | #if ENABLE_HUSH_FUNCTIONS | 1008 | #if ENABLE_HUSH_FUNCTIONS |
978 | BLTIN("return" , builtin_return , "Return from a function"), | 1009 | BLTIN("return" , builtin_return , "Return from a function"), |
979 | #endif | 1010 | #endif |
@@ -982,12 +1013,16 @@ static const struct built_in_command bltins1[] = { | |||
982 | #if ENABLE_HUSH_BASH_COMPAT | 1013 | #if ENABLE_HUSH_BASH_COMPAT |
983 | BLTIN("source" , builtin_source , "Run commands in a file"), | 1014 | BLTIN("source" , builtin_source , "Run commands in a file"), |
984 | #endif | 1015 | #endif |
1016 | #if ENABLE_HUSH_TRAP | ||
985 | BLTIN("trap" , builtin_trap , "Trap signals"), | 1017 | BLTIN("trap" , builtin_trap , "Trap signals"), |
1018 | #endif | ||
986 | BLTIN("true" , builtin_true , NULL), | 1019 | BLTIN("true" , builtin_true , NULL), |
987 | #if ENABLE_HUSH_TYPE | 1020 | #if ENABLE_HUSH_TYPE |
988 | BLTIN("type" , builtin_type , "Show command type"), | 1021 | BLTIN("type" , builtin_type , "Show command type"), |
989 | #endif | 1022 | #endif |
1023 | #if ENABLE_HUSH_ULIMIT | ||
990 | BLTIN("ulimit" , shell_builtin_ulimit , "Control resource limits"), | 1024 | BLTIN("ulimit" , shell_builtin_ulimit , "Control resource limits"), |
1025 | #endif | ||
991 | BLTIN("umask" , builtin_umask , "Set file creation mask"), | 1026 | BLTIN("umask" , builtin_umask , "Set file creation mask"), |
992 | BLTIN("unset" , builtin_unset , "Unset variables"), | 1027 | BLTIN("unset" , builtin_unset , "Unset variables"), |
993 | #if ENABLE_HUSH_WAIT | 1028 | #if ENABLE_HUSH_WAIT |
@@ -1712,13 +1747,13 @@ static void hush_exit(int exitcode) | |||
1712 | #endif | 1747 | #endif |
1713 | 1748 | ||
1714 | fflush_all(); | 1749 | fflush_all(); |
1715 | if (G.exiting <= 0 && G.traps && G.traps[0] && G.traps[0][0]) { | 1750 | if (G.exiting <= 0 && G_traps && G_traps[0] && G_traps[0][0]) { |
1716 | char *argv[3]; | 1751 | char *argv[3]; |
1717 | /* argv[0] is unused */ | 1752 | /* argv[0] is unused */ |
1718 | argv[1] = G.traps[0]; | 1753 | argv[1] = G_traps[0]; |
1719 | argv[2] = NULL; | 1754 | argv[2] = NULL; |
1720 | G.exiting = 1; /* prevent EXIT trap recursion */ | 1755 | G.exiting = 1; /* prevent EXIT trap recursion */ |
1721 | /* Note: G.traps[0] is not cleared! | 1756 | /* Note: G_traps[0] is not cleared! |
1722 | * "trap" will still show it, if executed | 1757 | * "trap" will still show it, if executed |
1723 | * in the handler */ | 1758 | * in the handler */ |
1724 | builtin_eval(argv); | 1759 | builtin_eval(argv); |
@@ -1769,14 +1804,14 @@ static int check_and_run_traps(void) | |||
1769 | } while (sig < NSIG); | 1804 | } while (sig < NSIG); |
1770 | break; | 1805 | break; |
1771 | got_sig: | 1806 | got_sig: |
1772 | if (G.traps && G.traps[sig]) { | 1807 | if (G_traps && G_traps[sig]) { |
1773 | debug_printf_exec("%s: sig:%d handler:'%s'\n", __func__, sig, G.traps[sig]); | 1808 | debug_printf_exec("%s: sig:%d handler:'%s'\n", __func__, sig, G.traps[sig]); |
1774 | if (G.traps[sig][0]) { | 1809 | if (G_traps[sig][0]) { |
1775 | /* We have user-defined handler */ | 1810 | /* We have user-defined handler */ |
1776 | smalluint save_rcode; | 1811 | smalluint save_rcode; |
1777 | char *argv[3]; | 1812 | char *argv[3]; |
1778 | /* argv[0] is unused */ | 1813 | /* argv[0] is unused */ |
1779 | argv[1] = G.traps[sig]; | 1814 | argv[1] = G_traps[sig]; |
1780 | argv[2] = NULL; | 1815 | argv[2] = NULL; |
1781 | save_rcode = G.last_exitcode; | 1816 | save_rcode = G.last_exitcode; |
1782 | builtin_eval(argv); | 1817 | builtin_eval(argv); |
@@ -5924,13 +5959,15 @@ static void switch_off_special_sigs(unsigned mask) | |||
5924 | sig++; | 5959 | sig++; |
5925 | if (!(mask & 1)) | 5960 | if (!(mask & 1)) |
5926 | continue; | 5961 | continue; |
5927 | if (G.traps) { | 5962 | #if ENABLE_HUSH_TRAP |
5928 | if (G.traps[sig] && !G.traps[sig][0]) | 5963 | if (G_traps) { |
5964 | if (G_traps[sig] && !G_traps[sig][0]) | ||
5929 | /* trap is '', has to remain SIG_IGN */ | 5965 | /* trap is '', has to remain SIG_IGN */ |
5930 | continue; | 5966 | continue; |
5931 | free(G.traps[sig]); | 5967 | free(G_traps[sig]); |
5932 | G.traps[sig] = NULL; | 5968 | G_traps[sig] = NULL; |
5933 | } | 5969 | } |
5970 | #endif | ||
5934 | /* We are here only if no trap or trap was not '' */ | 5971 | /* We are here only if no trap or trap was not '' */ |
5935 | install_sighandler(sig, SIG_DFL); | 5972 | install_sighandler(sig, SIG_DFL); |
5936 | } | 5973 | } |
@@ -5947,7 +5984,7 @@ static void reset_traps_to_defaults(void) | |||
5947 | /* This function is always called in a child shell | 5984 | /* This function is always called in a child shell |
5948 | * after fork (not vfork, NOMMU doesn't use this function). | 5985 | * after fork (not vfork, NOMMU doesn't use this function). |
5949 | */ | 5986 | */ |
5950 | unsigned sig; | 5987 | IF_HUSH_TRAP(unsigned sig;) |
5951 | unsigned mask; | 5988 | unsigned mask; |
5952 | 5989 | ||
5953 | /* Child shells are not interactive. | 5990 | /* Child shells are not interactive. |
@@ -5956,35 +5993,37 @@ static void reset_traps_to_defaults(void) | |||
5956 | * Same goes for SIGTERM, SIGHUP, SIGINT. | 5993 | * Same goes for SIGTERM, SIGHUP, SIGINT. |
5957 | */ | 5994 | */ |
5958 | mask = (G.special_sig_mask & SPECIAL_INTERACTIVE_SIGS) | G_fatal_sig_mask; | 5995 | mask = (G.special_sig_mask & SPECIAL_INTERACTIVE_SIGS) | G_fatal_sig_mask; |
5959 | if (!G.traps && !mask) | 5996 | if (!G_traps && !mask) |
5960 | return; /* already no traps and no special sigs */ | 5997 | return; /* already no traps and no special sigs */ |
5961 | 5998 | ||
5962 | /* Switch off special sigs */ | 5999 | /* Switch off special sigs */ |
5963 | switch_off_special_sigs(mask); | 6000 | switch_off_special_sigs(mask); |
5964 | #if ENABLE_HUSH_JOB | 6001 | # if ENABLE_HUSH_JOB |
5965 | G_fatal_sig_mask = 0; | 6002 | G_fatal_sig_mask = 0; |
5966 | #endif | 6003 | # endif |
5967 | G.special_sig_mask &= ~SPECIAL_INTERACTIVE_SIGS; | 6004 | G.special_sig_mask &= ~SPECIAL_INTERACTIVE_SIGS; |
5968 | /* SIGQUIT,SIGCHLD and maybe SPECIAL_JOBSTOP_SIGS | 6005 | /* SIGQUIT,SIGCHLD and maybe SPECIAL_JOBSTOP_SIGS |
5969 | * remain set in G.special_sig_mask */ | 6006 | * remain set in G.special_sig_mask */ |
5970 | 6007 | ||
5971 | if (!G.traps) | 6008 | # if ENABLE_HUSH_TRAP |
6009 | if (!G_traps) | ||
5972 | return; | 6010 | return; |
5973 | 6011 | ||
5974 | /* Reset all sigs to default except ones with empty traps */ | 6012 | /* Reset all sigs to default except ones with empty traps */ |
5975 | for (sig = 0; sig < NSIG; sig++) { | 6013 | for (sig = 0; sig < NSIG; sig++) { |
5976 | if (!G.traps[sig]) | 6014 | if (!G_traps[sig]) |
5977 | continue; /* no trap: nothing to do */ | 6015 | continue; /* no trap: nothing to do */ |
5978 | if (!G.traps[sig][0]) | 6016 | if (!G_traps[sig][0]) |
5979 | continue; /* empty trap: has to remain SIG_IGN */ | 6017 | continue; /* empty trap: has to remain SIG_IGN */ |
5980 | /* sig has non-empty trap, reset it: */ | 6018 | /* sig has non-empty trap, reset it: */ |
5981 | free(G.traps[sig]); | 6019 | free(G_traps[sig]); |
5982 | G.traps[sig] = NULL; | 6020 | G_traps[sig] = NULL; |
5983 | /* There is no signal for trap 0 (EXIT) */ | 6021 | /* There is no signal for trap 0 (EXIT) */ |
5984 | if (sig == 0) | 6022 | if (sig == 0) |
5985 | continue; | 6023 | continue; |
5986 | install_sighandler(sig, pick_sighandler(sig)); | 6024 | install_sighandler(sig, pick_sighandler(sig)); |
5987 | } | 6025 | } |
6026 | # endif | ||
5988 | } | 6027 | } |
5989 | 6028 | ||
5990 | #else /* !BB_MMU */ | 6029 | #else /* !BB_MMU */ |
@@ -6024,10 +6063,10 @@ static void re_execute_shell(char ***to_free, const char *s, | |||
6024 | cnt++; | 6063 | cnt++; |
6025 | 6064 | ||
6026 | empty_trap_mask = 0; | 6065 | empty_trap_mask = 0; |
6027 | if (G.traps) { | 6066 | if (G_traps) { |
6028 | int sig; | 6067 | int sig; |
6029 | for (sig = 1; sig < NSIG; sig++) { | 6068 | for (sig = 1; sig < NSIG; sig++) { |
6030 | if (G.traps[sig] && !G.traps[sig][0]) | 6069 | if (G_traps[sig] && !G_traps[sig][0]) |
6031 | empty_trap_mask |= 1LL << sig; | 6070 | empty_trap_mask |= 1LL << sig; |
6032 | } | 6071 | } |
6033 | } | 6072 | } |
@@ -6220,6 +6259,7 @@ static FILE *generate_stream_from_string(const char *s, pid_t *pid_p) | |||
6220 | xmove_fd(channel[1], 1); | 6259 | xmove_fd(channel[1], 1); |
6221 | /* Prevent it from trying to handle ctrl-z etc */ | 6260 | /* Prevent it from trying to handle ctrl-z etc */ |
6222 | IF_HUSH_JOB(G.run_list_level = 1;) | 6261 | IF_HUSH_JOB(G.run_list_level = 1;) |
6262 | # if ENABLE_HUSH_TRAP | ||
6223 | /* Awful hack for `trap` or $(trap). | 6263 | /* Awful hack for `trap` or $(trap). |
6224 | * | 6264 | * |
6225 | * http://www.opengroup.org/onlinepubs/009695399/utilities/trap.html | 6265 | * http://www.opengroup.org/onlinepubs/009695399/utilities/trap.html |
@@ -6263,6 +6303,7 @@ static FILE *generate_stream_from_string(const char *s, pid_t *pid_p) | |||
6263 | fflush_all(); /* important */ | 6303 | fflush_all(); /* important */ |
6264 | _exit(0); | 6304 | _exit(0); |
6265 | } | 6305 | } |
6306 | # endif | ||
6266 | # if BB_MMU | 6307 | # if BB_MMU |
6267 | reset_traps_to_defaults(); | 6308 | reset_traps_to_defaults(); |
6268 | parse_and_run_string(s); | 6309 | parse_and_run_string(s); |
@@ -8160,10 +8201,12 @@ static void install_sighandlers(unsigned mask) | |||
8160 | if (old_handler == SIG_IGN) { | 8201 | if (old_handler == SIG_IGN) { |
8161 | /* oops... restore back to IGN, and record this fact */ | 8202 | /* oops... restore back to IGN, and record this fact */ |
8162 | install_sighandler(sig, old_handler); | 8203 | install_sighandler(sig, old_handler); |
8163 | if (!G.traps) | 8204 | #if ENABLE_HUSH_TRAP |
8164 | G.traps = xzalloc(sizeof(G.traps[0]) * NSIG); | 8205 | if (!G_traps) |
8165 | free(G.traps[sig]); | 8206 | G_traps = xzalloc(sizeof(G_traps[0]) * NSIG); |
8166 | G.traps[sig] = xzalloc(1); /* == xstrdup(""); */ | 8207 | free(G_traps[sig]); |
8208 | G_traps[sig] = xzalloc(1); /* == xstrdup(""); */ | ||
8209 | #endif | ||
8167 | } | 8210 | } |
8168 | } | 8211 | } |
8169 | } | 8212 | } |
@@ -8464,10 +8507,10 @@ int hush_main(int argc, char **argv) | |||
8464 | if (empty_trap_mask != 0) { | 8507 | if (empty_trap_mask != 0) { |
8465 | int sig; | 8508 | int sig; |
8466 | install_special_sighandlers(); | 8509 | install_special_sighandlers(); |
8467 | G.traps = xzalloc(sizeof(G.traps[0]) * NSIG); | 8510 | G_traps = xzalloc(sizeof(G_traps[0]) * NSIG); |
8468 | for (sig = 1; sig < NSIG; sig++) { | 8511 | for (sig = 1; sig < NSIG; sig++) { |
8469 | if (empty_trap_mask & (1LL << sig)) { | 8512 | if (empty_trap_mask & (1LL << sig)) { |
8470 | G.traps[sig] = xzalloc(1); /* == xstrdup(""); */ | 8513 | G_traps[sig] = xzalloc(1); /* == xstrdup(""); */ |
8471 | install_sighandler(sig, SIG_IGN); | 8514 | install_sighandler(sig, SIG_IGN); |
8472 | } | 8515 | } |
8473 | } | 8516 | } |
@@ -9114,6 +9157,7 @@ static int FAST_FUNC builtin_shift(char **argv) | |||
9114 | return EXIT_FAILURE; | 9157 | return EXIT_FAILURE; |
9115 | } | 9158 | } |
9116 | 9159 | ||
9160 | #if ENABLE_HUSH_READ | ||
9117 | /* Interruptibility of read builtin in bash | 9161 | /* Interruptibility of read builtin in bash |
9118 | * (tested on bash-4.2.8 by sending signals (not by ^C)): | 9162 | * (tested on bash-4.2.8 by sending signals (not by ^C)): |
9119 | * | 9163 | * |
@@ -9178,23 +9222,25 @@ static int FAST_FUNC builtin_read(char **argv) | |||
9178 | 9222 | ||
9179 | return (uintptr_t)r; | 9223 | return (uintptr_t)r; |
9180 | } | 9224 | } |
9225 | #endif | ||
9181 | 9226 | ||
9227 | #if ENABLE_HUSH_TRAP | ||
9182 | static int FAST_FUNC builtin_trap(char **argv) | 9228 | static int FAST_FUNC builtin_trap(char **argv) |
9183 | { | 9229 | { |
9184 | int sig; | 9230 | int sig; |
9185 | char *new_cmd; | 9231 | char *new_cmd; |
9186 | 9232 | ||
9187 | if (!G.traps) | 9233 | if (!G_traps) |
9188 | G.traps = xzalloc(sizeof(G.traps[0]) * NSIG); | 9234 | G_traps = xzalloc(sizeof(G_traps[0]) * NSIG); |
9189 | 9235 | ||
9190 | argv++; | 9236 | argv++; |
9191 | if (!*argv) { | 9237 | if (!*argv) { |
9192 | int i; | 9238 | int i; |
9193 | /* No args: print all trapped */ | 9239 | /* No args: print all trapped */ |
9194 | for (i = 0; i < NSIG; ++i) { | 9240 | for (i = 0; i < NSIG; ++i) { |
9195 | if (G.traps[i]) { | 9241 | if (G_traps[i]) { |
9196 | printf("trap -- "); | 9242 | printf("trap -- "); |
9197 | print_escaped(G.traps[i]); | 9243 | print_escaped(G_traps[i]); |
9198 | /* note: bash adds "SIG", but only if invoked | 9244 | /* note: bash adds "SIG", but only if invoked |
9199 | * as "bash". If called as "sh", or if set -o posix, | 9245 | * as "bash". If called as "sh", or if set -o posix, |
9200 | * then it prints short signal names. | 9246 | * then it prints short signal names. |
@@ -9224,11 +9270,11 @@ static int FAST_FUNC builtin_trap(char **argv) | |||
9224 | continue; | 9270 | continue; |
9225 | } | 9271 | } |
9226 | 9272 | ||
9227 | free(G.traps[sig]); | 9273 | free(G_traps[sig]); |
9228 | G.traps[sig] = xstrdup(new_cmd); | 9274 | G_traps[sig] = xstrdup(new_cmd); |
9229 | 9275 | ||
9230 | debug_printf("trap: setting SIG%s (%i) to '%s'\n", | 9276 | debug_printf("trap: setting SIG%s (%i) to '%s'\n", |
9231 | get_signame(sig), sig, G.traps[sig]); | 9277 | get_signame(sig), sig, G_traps[sig]); |
9232 | 9278 | ||
9233 | /* There is no signal for 0 (EXIT) */ | 9279 | /* There is no signal for 0 (EXIT) */ |
9234 | if (sig == 0) | 9280 | if (sig == 0) |
@@ -9268,6 +9314,7 @@ static int FAST_FUNC builtin_trap(char **argv) | |||
9268 | argv++; | 9314 | argv++; |
9269 | goto process_sig_list; | 9315 | goto process_sig_list; |
9270 | } | 9316 | } |
9317 | #endif | ||
9271 | 9318 | ||
9272 | #if ENABLE_HUSH_TYPE | 9319 | #if ENABLE_HUSH_TYPE |
9273 | /* http://www.opengroup.org/onlinepubs/9699919799/utilities/type.html */ | 9320 | /* http://www.opengroup.org/onlinepubs/9699919799/utilities/type.html */ |