Skip to content

Commit c25558b

Browse files
committed
patch 7.4.1484
Problem: Channel "err-io" value "out" is not supported. Solution: Connect stderr to stdout if wanted.
1 parent d6547fc commit c25558b

5 files changed

Lines changed: 60 additions & 16 deletions

File tree

src/os_unix.c

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5045,6 +5045,7 @@ mch_start_job(char **argv, job_T *job, jobopt_T *options)
50455045
int fd_err[2]; /* for stderr */
50465046
# ifdef FEAT_CHANNEL
50475047
channel_T *channel = NULL;
5048+
int use_out_for_err = options->jo_io[PART_ERR] == JIO_OUT;
50485049
#endif
50495050

50505051
/* default is to fail */
@@ -5056,7 +5057,8 @@ mch_start_job(char **argv, job_T *job, jobopt_T *options)
50565057
/* TODO: without the channel feature connect the child to /dev/null? */
50575058
# ifdef FEAT_CHANNEL
50585059
/* Open pipes for stdin, stdout, stderr. */
5059-
if ((pipe(fd_in) < 0) || (pipe(fd_out) < 0) ||(pipe(fd_err) < 0))
5060+
if (pipe(fd_in) < 0 || pipe(fd_out) < 0
5061+
|| (!use_out_for_err && pipe(fd_err) < 0))
50605062
goto failed;
50615063

50625064
channel = add_channel();
@@ -5093,17 +5095,26 @@ mch_start_job(char **argv, job_T *job, jobopt_T *options)
50935095
ignored = dup(fd_in[0]);
50945096
close(fd_in[0]);
50955097

5098+
/* set up stderr for the child */
5099+
if (use_out_for_err)
5100+
{
5101+
close(2);
5102+
ignored = dup(fd_out[1]);
5103+
}
5104+
else
5105+
{
5106+
close(fd_err[0]);
5107+
close(2);
5108+
ignored = dup(fd_err[1]);
5109+
close(fd_err[1]);
5110+
}
5111+
50965112
/* set up stdout for the child */
50975113
close(fd_out[0]);
50985114
close(1);
50995115
ignored = dup(fd_out[1]);
51005116
close(fd_out[1]);
51015117

5102-
/* set up stderr for the child */
5103-
close(fd_err[0]);
5104-
close(2);
5105-
ignored = dup(fd_err[1]);
5106-
close(fd_err[1]);
51075118
# endif
51085119

51095120
/* See above for type of argv. */
@@ -5123,9 +5134,13 @@ mch_start_job(char **argv, job_T *job, jobopt_T *options)
51235134
/* child stdin, stdout and stderr */
51245135
close(fd_in[0]);
51255136
close(fd_out[1]);
5126-
close(fd_err[1]);
51275137
# ifdef FEAT_CHANNEL
5128-
channel_set_pipes(channel, fd_in[1], fd_out[0], fd_err[0]);
5138+
if (!use_out_for_err)
5139+
# endif
5140+
close(fd_err[1]);
5141+
# ifdef FEAT_CHANNEL
5142+
channel_set_pipes(channel, fd_in[1], fd_out[0],
5143+
use_out_for_err ? INVALID_FD : fd_err[0]);
51295144
channel_set_job(channel, job);
51305145
channel_set_options(channel, options);
51315146
# ifdef FEAT_GUI

src/os_win32.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5000,6 +5000,7 @@ mch_start_job(char *cmd, job_T *job, jobopt_T *options)
50005000
HANDLE jo;
50015001
# ifdef FEAT_CHANNEL
50025002
channel_T *channel;
5003+
int use_out_for_err = options->jo_io[PART_ERR] == JIO_OUT;
50035004
HANDLE ifd[2];
50045005
HANDLE ofd[2];
50055006
HANDLE efd[2];
@@ -5038,13 +5039,14 @@ mch_start_job(char *cmd, job_T *job, jobopt_T *options)
50385039
|| !pSetHandleInformation(ifd[1], HANDLE_FLAG_INHERIT, 0)
50395040
|| !CreatePipe(&ofd[0], &ofd[1], &saAttr, 0)
50405041
|| !pSetHandleInformation(ofd[0], HANDLE_FLAG_INHERIT, 0)
5041-
|| !CreatePipe(&efd[0], &efd[1], &saAttr, 0)
5042-
|| !pSetHandleInformation(efd[0], HANDLE_FLAG_INHERIT, 0))
5042+
|| (!use_out_for_err
5043+
&& (!CreatePipe(&efd[0], &efd[1], &saAttr, 0)
5044+
|| !pSetHandleInformation(efd[0], HANDLE_FLAG_INHERIT, 0))))
50435045
goto failed;
50445046
si.dwFlags |= STARTF_USESTDHANDLES;
50455047
si.hStdInput = ifd[0];
50465048
si.hStdOutput = ofd[1];
5047-
si.hStdError = efd[1];
5049+
si.hStdError = use_out_for_err ? ofd[1] : efd[1];
50485050
# endif
50495051

50505052
if (!vim_create_process(cmd, TRUE,
@@ -5075,10 +5077,12 @@ mch_start_job(char *cmd, job_T *job, jobopt_T *options)
50755077
# ifdef FEAT_CHANNEL
50765078
CloseHandle(ifd[0]);
50775079
CloseHandle(ofd[1]);
5078-
CloseHandle(efd[1]);
5080+
if (!use_out_for_err)
5081+
CloseHandle(efd[1]);
50795082

50805083
job->jv_channel = channel;
5081-
channel_set_pipes(channel, (sock_T)ifd[1], (sock_T)ofd[0], (sock_T)efd[0]);
5084+
channel_set_pipes(channel, (sock_T)ifd[1], (sock_T)ofd[0],
5085+
use_out_for_err ? INVALID_FD : (sock_T)efd[0]);
50825086
channel_set_job(channel, job);
50835087
channel_set_options(channel, options);
50845088

src/testdir/test_channel.vim

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,8 @@ func s:raw_one_time_callback(port)
339339
endfunc
340340

341341
func Test_raw_one_time_callback()
342-
call ch_logfile('channellog', 'w')
343342
call ch_log('Test_raw_one_time_callback()')
344343
call s:run_server('s:raw_one_time_callback')
345-
call ch_logfile('')
346344
endfunc
347345

348346
"""""""""
@@ -420,6 +418,9 @@ func Test_nl_pipe()
420418
call ch_sendraw(handle, "echo something\n")
421419
call assert_equal("something", ch_readraw(handle))
422420

421+
call ch_sendraw(handle, "echoerr wrong\n")
422+
call assert_equal("wrong", ch_readraw(handle, {'part': 'err'}))
423+
423424
call ch_sendraw(handle, "double this\n")
424425
call assert_equal("this", ch_readraw(handle))
425426
call assert_equal("AND this", ch_readraw(handle))
@@ -431,6 +432,25 @@ func Test_nl_pipe()
431432
endtry
432433
endfunc
433434

435+
func Test_nl_err_to_out_pipe()
436+
if !has('job')
437+
return
438+
endif
439+
call ch_log('Test_nl_err_to_out_pipe()')
440+
let job = job_start(s:python . " test_channel_pipe.py", {'err-io': 'out'})
441+
call assert_equal("run", job_status(job))
442+
try
443+
let handle = job_getchannel(job)
444+
call ch_sendraw(handle, "echo something\n")
445+
call assert_equal("something", ch_readraw(handle))
446+
447+
call ch_sendraw(handle, "echoerr wrong\n")
448+
call assert_equal("wrong", ch_readraw(handle))
449+
finally
450+
call job_stop(job)
451+
endtry
452+
endfunc
453+
434454
func Test_pipe_to_buffer()
435455
if !has('job')
436456
return

src/testdir/test_channel_pipe.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@
1818
print("Goodbye!")
1919
sys.stdout.flush()
2020
break
21-
if typed.startswith("echo"):
21+
if typed.startswith("echo "):
2222
print(typed[5:-1])
2323
sys.stdout.flush()
24+
if typed.startswith("echoerr"):
25+
print(typed[8:-1], file=sys.stderr)
26+
sys.stderr.flush()
2427
if typed.startswith("double"):
2528
print(typed[7:-1] + "\nAND " + typed[7:-1])
2629
sys.stdout.flush()

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,8 @@ static char *(features[]) =
743743

744744
static int included_patches[] =
745745
{ /* Add new patch number below this line */
746+
/**/
747+
1484,
746748
/**/
747749
1483,
748750
/**/

0 commit comments

Comments
 (0)