Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Tk console breaks [exec]

Closed / Fixed437489ffffffffffffffffffffffffffffffffffCreated 25 years agoUpdated 25 years ago
Descriptionplain2001-06-29 22:51:06
The attached file, mywish.c, creates a customized
"wish" program on Unix that makes use of the Tk
console developed for Windows.  The routines that
make this possible, Tk_InitConsoleChannels() and
Tk_CreateConsoleWindow() are public.

Create a program from the attached file with gcc
like so:

gcc -o mywish mywish.cc -ltk8.3 -ltcl8.3

Then start ./mywish and up pops the console.
So far so good.

Enter in the console:

% exec xeyes &;# or whatever is available
forked process couldn't set up input/output: bad file
number
% set errorCode
POSIX EBADF {bad file number}

I tracked down the problem in unix/tclUnixPipe.c
and will attach a one-liner patch that fixes it.
dgpplain2001-06-30 05:51:07
File Added - 7946: mywish.c
dgpplain2001-06-30 05:52:45
File Added - 7947: pipe.patch

Logged In: YES 
user_id=80530

Here's the patch...
dgpplain2001-07-06 02:27:18
Logged In: YES 
user_id=80530

Note that after this fix, the child process can
start up, but it will have no standard channels.
(File descriptors 0, 1, 2 will be closed).

Unless the child process handles that possibility,
there can still be trouble.  Note especially that
if the child process includes a Tcl interp, the
first 3 channels created will "become" stdin,
stdout and stderr.  Unless that is controlled
carefully, it will probably lead to unpredictable
behavior.

Can anyone explain why Tcl_CreateChannel does that?
andreas_kupriesplain2001-08-23 05:57:14
Logged In: YES 
user_id=75003

It allows you to close stdout, open a file (or socket) and 
thus have that file/socket as the new stdout of the 
application.
dgp Ticket [437489ffff]: 1 change [History diff]2001-12-08 00:06:28
andreas_kupriesplain2001-12-11 09:43:43
Logged In: YES 
user_id=75003

Patch committed to head.
Log in (anonymous is fine) to add a comment.

Attachments: