|
From: SourceForge.net <no...@so...> - 2011-11-03 20:56:09
|
Bugs item #3432962, was opened at 2011-11-03 13:16 Message generated for change (Comment added) made by karll You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=110894&aid=3432962&group_id=10894 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: 50. Embedding Support Group: current: 8.5.10 Status: Pending Resolution: Invalid Priority: 5 Private: No Submitted By: Karl Lehenbauer (karll) Assigned to: Don Porter (dgp) Summary: Some noninteractive invocations of tclsh still run .tclshrc Initial Comment: Running Tcl without command line arguments but with input not coming from a tty causes .tclshrc (or equivalent) to be loaded. It shouldn't. (We don't want peoples' tclshrc files to cause noninteractive Tcl programs to change their behavior.) How to reproduce: Put something in your .tclshrc like... puts ".tclshrc loaded" echo exit | tclsh8.5 It will emit ".tclshrc loaded". It shouldn't. Note that in the above example, or any other where stdin isn't a tty, tcl_interactive is correctly set to 0. Here is a context diff for a patch that fixes the bug: *** tclMain.c.orig Thu Nov 3 15:02:54 2011 --- tclMain.c Thu Nov 3 15:04:12 2011 *************** *** 460,472 **** } /* ! * We're running interactively. Source a user-specific startup file if the ! * application specified one and if the file exists. */ ! Tcl_SourceRCFile(interp); ! if (Tcl_LimitExceeded(interp)) { ! goto done; } /* --- 460,475 ---- } /* ! * No script file was specified on the command line. ! * If we're running interactively, source a user-specific ! * startup file if the application specified one and if the file exists. */ ! if (tty) { ! Tcl_SourceRCFile(interp); ! if (Tcl_LimitExceeded(interp)) { ! goto done; ! } } /* ---------------------------------------------------------------------- Comment By: Karl Lehenbauer (karll) Date: 2011-11-03 13:56 Message: I am the inventor of .tclshrc, which first appeared in TclX in, like, 1991. My intention in making it that tclshrc only be loaded when Tcl is used interactively was to prevent peoples' tclshrc files from changing the behavior of noninteractive Tcl programs, preventing "spooky actions at a distance" and also trying to keep people from accidentally distributing programs with subtle dependencies on something that's done in their tclshrc file, that they might not even realize, like loading some package. I'm not proposing changing tcl_interactive or how it gets set. I'm not proposing changing how Tcl behaves if it has any arguments on the command line, which is by far the most common noninteractive use. I'm merely asking for the rc file to never be loaded if Tcl isn't interactive, whereas right now it *almost* never is loaded if Tcl isn't interactive. What's the test for setting tcl_interactive? It's set to the result of isatty(0). For the example of a Makefile action, like echo "pkg_mkIndex ." | tclsh tcl_interactive will properly be 0. I assert this is truly noninteractive invocation of tclsh (you'll never get a command prompt) and Tcl agrees with me in that it set tcl_interactive to 0. All I'm asking is that tclshrc not be loaded when Tcl isn't interactive, which is aligned with its original intention. The problem was discovered by exactly the problem I was trying to prevent. One of our developers had a custom tclshrc file that caused 'echo "pkg_mkIndex ." | tclsh' to malfunction, for them and them only, in a subtle way that took hours to track down. ---------------------------------------------------------------------- Comment By: Don Porter (dgp) Date: 2011-11-03 13:37 Message: The test suite makes use of the existing logic. The proposed patch makes 5 tests fail. ---------------------------------------------------------------------- Comment By: Don Porter (dgp) Date: 2011-11-03 13:28 Message: The logic currently in Tcl_Main, and the meaning of "interactive" on which it is based, have been in place nearly 10 years. I'm not inclined to change it without a clearer reason why. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=110894&aid=3432962&group_id=10894 |