aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-11-15 23:28:11 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2009-11-15 23:28:11 +0100
commita7ccdeef396700d1ed78b9f97de0d10c706b169f (patch)
tree4ef45efdaaac81d2a4c31b16d9cc36ba2d3a22e1 /shell
parent647553a4fcbbc169b4390d9ef8e4657f0ffe1a5f (diff)
downloadbusybox-w32-a7ccdeef396700d1ed78b9f97de0d10c706b169f.tar.gz
busybox-w32-a7ccdeef396700d1ed78b9f97de0d10c706b169f.tar.bz2
busybox-w32-a7ccdeef396700d1ed78b9f97de0d10c706b169f.zip
libbb: added xfdopen_for_read/write
function old new delta xfdopen_helper - 40 +40 logdir_open 1163 1184 +21 process_stdin 433 443 +10 xfdopen_for_write - 9 +9 doCommands 2465 2474 +9 patch_main 1214 1222 +8 bbunpack 457 465 +8 xfdopen_for_read - 7 +7 scan_tree 258 262 +4 xstrtoul_range_sfx 230 231 +1 sendmail_main 957 955 -2 passwd_main 1027 1023 -4 parse 969 964 -5 test_main 253 247 -6 sed_main 655 649 -6 dos2unix_main 437 429 -8 fbsplash_main 950 938 -12 handle_dir_common 371 354 -17 expand_vars_to_list 2197 2169 -28 update_passwd 1275 1246 -29 ------------------------------------------------------------------------------ (add/remove: 3/0 grow/shrink: 7/10 up/down: 117/-117) Total: 0 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r--shell/hush.c15
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. */
5309static int process_command_subs(o_string *dest, const char *s) 5309static 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 */