|
| 1 | +--- shell.c.orig 2017-03-25 20:15:24.155329613 +0100 |
| 2 | ++++ shell.c 2017-03-25 20:18:40.204346454 +0100 |
| 3 | +@@ -373,6 +373,7 @@ |
| 4 | + #endif |
| 5 | + volatile int locally_skip_execution; |
| 6 | + volatile int arg_index, top_level_arg_index; |
| 7 | ++ char buf[21]; |
| 8 | + #ifdef __OPENNT |
| 9 | + char **env; |
| 10 | + |
| 11 | +@@ -461,61 +462,11 @@ |
| 12 | + set_shell_name (argv[0]); |
| 13 | + shell_start_time = NOW; /* NOW now defined in general.h */ |
| 14 | + |
| 15 | +- /* Parse argument flags from the input line. */ |
| 16 | +- |
| 17 | +- /* Find full word arguments first. */ |
| 18 | +- arg_index = parse_long_options (argv, arg_index, argc); |
| 19 | +- |
| 20 | +- if (want_initial_help) |
| 21 | +- { |
| 22 | +- show_shell_usage (stdout, 1); |
| 23 | +- exit (EXECUTION_SUCCESS); |
| 24 | +- } |
| 25 | +- |
| 26 | +- if (do_version) |
| 27 | +- { |
| 28 | +- show_shell_version (1); |
| 29 | +- exit (EXECUTION_SUCCESS); |
| 30 | +- } |
| 31 | +- |
| 32 | +- echo_input_at_read = verbose_flag; /* --verbose given */ |
| 33 | +- |
| 34 | +- /* All done with full word options; do standard shell option parsing.*/ |
| 35 | +- this_command_name = shell_name; /* for error reporting */ |
| 36 | +- arg_index = parse_shell_options (argv, arg_index, argc); |
| 37 | +- |
| 38 | +- /* If user supplied the "--login" (or -l) flag, then set and invert |
| 39 | +- LOGIN_SHELL. */ |
| 40 | +- if (make_login_shell) |
| 41 | +- { |
| 42 | +- login_shell++; |
| 43 | +- login_shell = -login_shell; |
| 44 | +- } |
| 45 | +- |
| 46 | + set_login_shell ("login_shell", login_shell != 0); |
| 47 | + |
| 48 | +- if (dump_po_strings) |
| 49 | +- dump_translatable_strings = 1; |
| 50 | +- |
| 51 | +- if (dump_translatable_strings) |
| 52 | +- read_but_dont_execute = 1; |
| 53 | +- |
| 54 | + if (running_setuid && privileged_mode == 0) |
| 55 | + disable_priv_mode (); |
| 56 | + |
| 57 | +- /* Need to get the argument to a -c option processed in the |
| 58 | +- above loop. The next arg is a command to execute, and the |
| 59 | +- following args are $0...$n respectively. */ |
| 60 | +- if (want_pending_command) |
| 61 | +- { |
| 62 | +- command_execution_string = argv[arg_index]; |
| 63 | +- if (command_execution_string == 0) |
| 64 | +- { |
| 65 | +- report_error (_("%s: option requires an argument"), "-c"); |
| 66 | +- exit (EX_BADUSAGE); |
| 67 | +- } |
| 68 | +- arg_index++; |
| 69 | +- } |
| 70 | + this_command_name = (char *)NULL; |
| 71 | + |
| 72 | + /* First, let the outside world know about our interactive status. |
| 73 | +@@ -526,7 +477,7 @@ |
| 74 | + standard input is a terminal |
| 75 | + standard error is a terminal |
| 76 | + Refer to Posix.2, the description of the `sh' utility. */ |
| 77 | +- |
| 78 | ++#if 0 |
| 79 | + if (forced_interactive || /* -i flag */ |
| 80 | + (!command_execution_string && /* No -c command and ... */ |
| 81 | + wordexp_only == 0 && /* No --wordexp and ... */ |
| 82 | +@@ -537,33 +488,8 @@ |
| 83 | + init_interactive (); |
| 84 | + else |
| 85 | + init_noninteractive (); |
| 86 | +- |
| 87 | +- /* |
| 88 | +- * Some systems have the bad habit of starting login shells with lots of open |
| 89 | +- * file descriptors. For instance, most systems that have picked up the |
| 90 | +- * pre-4.0 Sun YP code leave a file descriptor open each time you call one |
| 91 | +- * of the getpw* functions, and it's set to be open across execs. That |
| 92 | +- * means one for login, one for xterm, one for shelltool, etc. There are |
| 93 | +- * also systems that open persistent FDs to other agents or files as part |
| 94 | +- * of process startup; these need to be set to be close-on-exec. |
| 95 | +- */ |
| 96 | +- if (login_shell && interactive_shell) |
| 97 | +- { |
| 98 | +- for (i = 3; i < 20; i++) |
| 99 | +- SET_CLOSE_ON_EXEC (i); |
| 100 | +- } |
| 101 | +- |
| 102 | +- /* If we're in a strict Posix.2 mode, turn on interactive comments, |
| 103 | +- alias expansion in non-interactive shells, and other Posix.2 things. */ |
| 104 | +- if (posixly_correct) |
| 105 | +- { |
| 106 | +- bind_variable ("POSIXLY_CORRECT", "y", 0); |
| 107 | +- sv_strict_posix ("POSIXLY_CORRECT"); |
| 108 | +- } |
| 109 | +- |
| 110 | +- /* Now we run the shopt_alist and process the options. */ |
| 111 | +- if (shopt_alist) |
| 112 | +- run_shopt_alist (); |
| 113 | ++#endif |
| 114 | ++ init_noninteractive(); |
| 115 | + |
| 116 | + /* From here on in, the shell must be a normal functioning shell. |
| 117 | + Variables from the environment are expected to be set, etc. */ |
| 118 | +@@ -572,51 +498,6 @@ |
| 119 | + set_default_lang (); |
| 120 | + set_default_locale_vars (); |
| 121 | + |
| 122 | +- /* |
| 123 | +- * M-x term -> TERM=eterm-color INSIDE_EMACS='251,term:0.96' (eterm) |
| 124 | +- * M-x shell -> TERM='dumb' INSIDE_EMACS='25.1,comint' (no line editing) |
| 125 | +- * |
| 126 | +- * Older versions of Emacs may set EMACS to 't' or to something like |
| 127 | +- * '22.1 (term:0.96)' instead of (or in addition to) setting INSIDE_EMACS. |
| 128 | +- * They may set TERM to 'eterm' instead of 'eterm-color'. They may have |
| 129 | +- * a now-obsolete command that sets neither EMACS nor INSIDE_EMACS: |
| 130 | +- * M-x terminal -> TERM='emacs-em7955' (line editing) |
| 131 | +- */ |
| 132 | +- if (interactive_shell) |
| 133 | +- { |
| 134 | +- char *term, *emacs, *inside_emacs;; |
| 135 | +- int emacs_term, in_emacs; |
| 136 | +- |
| 137 | +- term = get_string_value ("TERM"); |
| 138 | +- emacs = get_string_value ("EMACS"); |
| 139 | +- inside_emacs = get_string_value ("INSIDE_EMACS"); |
| 140 | +- |
| 141 | +- if (inside_emacs) |
| 142 | +- { |
| 143 | +- emacs_term = strstr (inside_emacs, ",term:") != 0; |
| 144 | +- in_emacs = 1; |
| 145 | +- } |
| 146 | +- else if (emacs) |
| 147 | +- { |
| 148 | +- /* Infer whether we are in an older Emacs. */ |
| 149 | +- emacs_term = strstr (emacs, " (term:") != 0; |
| 150 | +- in_emacs = emacs_term || STREQ (emacs, "t"); |
| 151 | +- } |
| 152 | +- else |
| 153 | +- in_emacs = emacs_term = 0; |
| 154 | +- |
| 155 | +- /* Not sure any emacs terminal emulator sets TERM=emacs any more */ |
| 156 | +- no_line_editing |= STREQ (term, "emacs"); |
| 157 | +- no_line_editing |= in_emacs && STREQ (term, "dumb"); |
| 158 | +- |
| 159 | +- /* running_under_emacs == 2 for `eterm' */ |
| 160 | +- running_under_emacs = in_emacs || STREQN (term, "emacs", 5); |
| 161 | +- running_under_emacs += emacs_term && STREQN (term, "eterm", 5); |
| 162 | +- |
| 163 | +- if (running_under_emacs) |
| 164 | +- gnu_error_format = 1; |
| 165 | +- } |
| 166 | +- |
| 167 | + top_level_arg_index = arg_index; |
| 168 | + old_errexit_flag = exit_immediately_on_error; |
| 169 | + |
| 170 | +@@ -674,21 +555,15 @@ |
| 171 | + #endif |
| 172 | + |
| 173 | + /* The startup files are run with `set -e' temporarily disabled. */ |
| 174 | +- if (locally_skip_execution == 0 && running_setuid == 0) |
| 175 | ++ /*if (locally_skip_execution == 0 && running_setuid == 0) |
| 176 | + { |
| 177 | + old_errexit_flag = exit_immediately_on_error; |
| 178 | + exit_immediately_on_error = 0; |
| 179 | + |
| 180 | + run_startup_files (); |
| 181 | + exit_immediately_on_error += old_errexit_flag; |
| 182 | +- } |
| 183 | ++ }*/ |
| 184 | + |
| 185 | +- /* If we are invoked as `sh', turn on Posix mode. */ |
| 186 | +- if (act_like_sh) |
| 187 | +- { |
| 188 | +- bind_variable ("POSIXLY_CORRECT", "y", 0); |
| 189 | +- sv_strict_posix ("POSIXLY_CORRECT"); |
| 190 | +- } |
| 191 | + |
| 192 | + #if defined (RESTRICTED_SHELL) |
| 193 | + /* Turn on the restrictions after executing the startup files. This |
| 194 | +@@ -711,76 +586,14 @@ |
| 195 | + cmd_init (); /* initialize the command object caches */ |
| 196 | + uwp_init (); |
| 197 | + |
| 198 | +- if (command_execution_string) |
| 199 | +- { |
| 200 | +- arg_index = bind_args (argv, arg_index, argc, 0); |
| 201 | +- startup_state = 2; |
| 202 | +- |
| 203 | +- if (debugging_mode) |
| 204 | +- start_debugger (); |
| 205 | +- |
| 206 | +-#if defined (ONESHOT) |
| 207 | +- executing = 1; |
| 208 | +- run_one_command (command_execution_string); |
| 209 | +- exit_shell (last_command_exit_value); |
| 210 | +-#else /* ONESHOT */ |
| 211 | +- with_input_from_string (command_execution_string, "-c"); |
| 212 | +- goto read_and_execute; |
| 213 | +-#endif /* !ONESHOT */ |
| 214 | +- } |
| 215 | +- |
| 216 | + /* Get possible input filename and set up default_buffered_input or |
| 217 | + default_input as appropriate. */ |
| 218 | +- if (arg_index != argc && read_from_stdin == 0) |
| 219 | +- { |
| 220 | +- open_shell_script (argv[arg_index]); |
| 221 | +- arg_index++; |
| 222 | +- } |
| 223 | +- else if (interactive == 0) |
| 224 | +- { |
| 225 | +- /* In this mode, bash is reading a script from stdin, which is a |
| 226 | +- pipe or redirected file. */ |
| 227 | +-#if defined (BUFFERED_INPUT) |
| 228 | +- default_buffered_input = fileno (stdin); /* == 0 */ |
| 229 | +-#else |
| 230 | +- setbuf (default_input, (char *)NULL); |
| 231 | +-#endif /* !BUFFERED_INPUT */ |
| 232 | +- read_from_stdin = 1; |
| 233 | +- } |
| 234 | +- else if (arg_index == argc) |
| 235 | +- /* "If there are no operands and the -c option is not specified, the -s |
| 236 | +- option shall be assumed." */ |
| 237 | +- read_from_stdin = 1; |
| 238 | + |
| 239 | ++ open_shell_script (argv[0]); |
| 240 | + set_bash_input (); |
| 241 | + |
| 242 | + /* Bind remaining args to $1 ... $n */ |
| 243 | +- arg_index = bind_args (argv, arg_index, argc, 1); |
| 244 | +- |
| 245 | +- if (debugging_mode && locally_skip_execution == 0 && running_setuid == 0 && (reading_shell_script || interactive_shell == 0)) |
| 246 | +- start_debugger (); |
| 247 | +- |
| 248 | +- /* Do the things that should be done only for interactive shells. */ |
| 249 | +- if (interactive_shell) |
| 250 | +- { |
| 251 | +- /* Set up for checking for presence of mail. */ |
| 252 | +- reset_mail_timer (); |
| 253 | +- init_mail_dates (); |
| 254 | +- |
| 255 | +-#if defined (HISTORY) |
| 256 | +- /* Initialize the interactive history stuff. */ |
| 257 | +- bash_initialize_history (); |
| 258 | +- /* Don't load the history from the history file if we've already |
| 259 | +- saved some lines in this session (e.g., by putting `history -s xx' |
| 260 | +- into one of the startup files). */ |
| 261 | +- if (shell_initialized == 0 && history_lines_this_session == 0) |
| 262 | +- load_history (); |
| 263 | +-#endif /* HISTORY */ |
| 264 | +- |
| 265 | +- /* Initialize terminal state for interactive shells after the |
| 266 | +- .bash_profile and .bashrc are interpreted. */ |
| 267 | +- get_tty_state (); |
| 268 | +- } |
| 269 | ++ arg_index = bind_args (argv, 1, argc, 1); |
| 270 | + |
| 271 | + #if !defined (ONESHOT) |
| 272 | + read_and_execute: |
| 273 | +@@ -1484,22 +1297,6 @@ |
| 274 | + filename = savestring (script_name); |
| 275 | + |
| 276 | + fd = open (filename, O_RDONLY); |
| 277 | +- if ((fd < 0) && (errno == ENOENT) && (absolute_program (filename) == 0)) |
| 278 | +- { |
| 279 | +- e = errno; |
| 280 | +- /* If it's not in the current directory, try looking through PATH |
| 281 | +- for it. */ |
| 282 | +- path_filename = find_path_file (script_name); |
| 283 | +- if (path_filename) |
| 284 | +- { |
| 285 | +- free (filename); |
| 286 | +- filename = path_filename; |
| 287 | +- fd = open (filename, O_RDONLY); |
| 288 | +- } |
| 289 | +- else |
| 290 | +- errno = e; |
| 291 | +- } |
| 292 | +- |
| 293 | + if (fd < 0) |
| 294 | + { |
| 295 | + e = errno; |
| 296 | +@@ -1550,6 +1347,8 @@ |
| 297 | + /* Only do this with non-tty file descriptors we can seek on. */ |
| 298 | + if (fd_is_tty == 0 && (lseek (fd, 0L, 1) != -1)) |
| 299 | + { |
| 300 | ++ char buf[21]; |
| 301 | ++ long long siz=0; |
| 302 | + /* Check to see if the `file' in `bash file' is a binary file |
| 303 | + according to the same tests done by execute_simple_command (), |
| 304 | + and report an error and exit if it is. */ |
| 305 | +@@ -1573,13 +1372,24 @@ |
| 306 | + } |
| 307 | + exit (EX_NOEXEC); |
| 308 | + } |
| 309 | +- else if (sample_len > 0 && (check_binary_file (sample, sample_len))) |
| 310 | ++ /*else if (sample_len > 0 && (check_binary_file (sample, sample_len))) |
| 311 | + { |
| 312 | + internal_error (_("%s: cannot execute binary file"), filename); |
| 313 | + exit (EX_BINARY_FILE); |
| 314 | +- } |
| 315 | ++ }*/ |
| 316 | ++ lseek(fd, -20L, SEEK_END); |
| 317 | ++ if (read(fd, buf, 20) != 20) { |
| 318 | ++ internal_error(_("%s: unable to read size"), filename); |
| 319 | ++ exit (EX_BADUSAGE); |
| 320 | ++ } |
| 321 | ++ siz = atoll(buf); |
| 322 | ++ if (siz == 0) { |
| 323 | ++ internal_error(_("%s: unable to get script size"), filename); |
| 324 | ++ exit (EX_BADUSAGE); |
| 325 | ++ } |
| 326 | ++ lseek(fd, -21-siz, SEEK_END); |
| 327 | + /* Now rewind the file back to the beginning. */ |
| 328 | +- lseek (fd, 0L, 0); |
| 329 | ++ /*lseek (fd, 0L, 0);*/ |
| 330 | + } |
| 331 | + |
| 332 | + /* Open the script. But try to move the file descriptor to a randomly |
0 commit comments