diff options
Diffstat (limited to 'shell')
-rw-r--r-- | shell/hush.c | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/shell/hush.c b/shell/hush.c index 6f394d1d5..ede8d680e 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -5301,25 +5301,22 @@ static FILE *generate_stream_from_string(const char *s, pid_t *pid_p) | |||
5301 | free(to_free); | 5301 | free(to_free); |
5302 | # endif | 5302 | # endif |
5303 | close(channel[1]); | 5303 | close(channel[1]); |
5304 | //TODO: libbb: fdopen_or_die? | 5304 | close_on_exec_on(channel[0]); |
5305 | return fdopen(channel[0], "r"); | 5305 | return xfdopen_for_read(channel[0]); |
5306 | } | 5306 | } |
5307 | 5307 | ||
5308 | /* Return code is exit status of the process that is run. */ | 5308 | /* Return code is exit status of the process that is run. */ |
5309 | static int process_command_subs(o_string *dest, const char *s) | 5309 | static int process_command_subs(o_string *dest, const char *s) |
5310 | { | 5310 | { |
5311 | FILE *pf; | 5311 | FILE *fp; |
5312 | struct in_str pipe_str; | 5312 | struct in_str pipe_str; |
5313 | pid_t pid; | 5313 | pid_t pid; |
5314 | int status, ch, eol_cnt; | 5314 | int status, ch, eol_cnt; |
5315 | 5315 | ||
5316 | pf = generate_stream_from_string(s, &pid); | 5316 | fp = generate_stream_from_string(s, &pid); |
5317 | if (pf == NULL) | ||
5318 | return 1; | ||
5319 | close_on_exec_on(fileno(pf)); | ||
5320 | 5317 | ||
5321 | /* Now send results of command back into original context */ | 5318 | /* Now send results of command back into original context */ |
5322 | setup_file_in_str(&pipe_str, pf); | 5319 | setup_file_in_str(&pipe_str, fp); |
5323 | eol_cnt = 0; | 5320 | eol_cnt = 0; |
5324 | while ((ch = i_getch(&pipe_str)) != EOF) { | 5321 | while ((ch = i_getch(&pipe_str)) != EOF) { |
5325 | if (ch == '\n') { | 5322 | if (ch == '\n') { |
@@ -5334,7 +5331,7 @@ static int process_command_subs(o_string *dest, const char *s) | |||
5334 | } | 5331 | } |
5335 | 5332 | ||
5336 | debug_printf("done reading from `cmd` pipe, closing it\n"); | 5333 | debug_printf("done reading from `cmd` pipe, closing it\n"); |
5337 | fclose(pf); | 5334 | fclose(fp); |
5338 | /* We need to extract exitcode. Test case | 5335 | /* We need to extract exitcode. Test case |
5339 | * "true; echo `sleep 1; false` $?" | 5336 | * "true; echo `sleep 1; false` $?" |
5340 | * should print 1 */ | 5337 | * should print 1 */ |