Artifacts Associated With Ticket 3432962
Ticket change [b66194d492] (rid 125413) by karll on 2011-11-03 20:16:54:
- assignee initialized to: "dgp"
- cmimetype initialized to: "text/plain"
- comment initialized to:
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.origThu Nov 3 15:02:54 2011 --- tclMain.cThu 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; ! } } /* - foundin initialized to: "obsolete: 8.5.10"
- is_private initialized to: "0"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "karll"
- subsystem initialized to: "38. Init - Library - Autoload"
- title initialized to:
Some noninteractive invocations of tclsh still run .tclshrc
- type initialized to: "RFE"
Add attachment "patch" [56a7a77cd0] (rid 94355) by karll on 2011-11-04 03:19:07.
Ticket change [c693cd6fb6] (rid 121793) by karll on 2011-11-04 03:19:07:
- icomment:
File Added - 427654: patch
- login: "karll"
- mimetype: "text/plain"
- username: "karll"
- icomment:
Ticket change [357b6cada4] (rid 106941) by dgp on 2011-11-04 03:28:09:
- closedate changed to: "2011-11-03T20:28:09"
- closer changed to: "dgp"
- icomment:
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.
- login: "dgp"
- mimetype: "text/plain"
- resolution changed to: "Invalid"
- status changed to: "Pending"
- subsystem changed to: "50. Embedding Support"
- username: "dgp"
Ticket change [2b548399b6] (rid 118723) by dgp on 2011-11-04 03:37:24:
- icomment:
The test suite makes use of the existing logic. The proposed patch makes 5 tests fail.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [c6386d3ae0] (rid 121730) by karll on 2011-11-04 03:56:08:
- icomment:
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. - login: "karll"
- mimetype: "text/plain"
- username: "karll"
- icomment:
Ticket change [947531719d] (rid 105986) by dgp on 2011-11-04 21:25:11:
- icomment:
Thank you for the followup. I need to review the impact of the change on docs and tests before accepting it.
- login: "dgp"
- mimetype: "text/plain"
- resolution changed to: "None"
- status changed to: "Open"
- username: "dgp"
- icomment:
Ticket change [f58d433301] (rid 130133) by dgp on 2011-11-04 21:42:51:
- icomment:
I was under the impression that this was a change introduced when I revised Tcl_Main() for Tcl 8.4 in 2002. A review of the history indicates otherwise. The reading of an "rc file" by Tcl appears to be introduced in the Tcl 7.0 release, and starting then and unchanged since, Tcl has been sourcing the rc file whenever it is in interactive mode -- reading cmds from stdin -- without regard to whether stdin is a tty.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [423c28a55c] (rid 116335) by dgp on 2012-11-27 00:58:50:
- foundin changed to: "None"
- icomment:
data_type - 360894
- login: "dgp"
- mimetype: "text/plain"
- priority changed to: "8"
- subsystem changed to: "50. Embedding Support"
- username: "dgp"