Tcl Source Code

View Ticket
Login
Ticket UUID: 2910867
Title: [tclPkgUnknown] and Safe Base
Type: Bug Created on: 2009-12-08 18:10:58
Submitter: dgp Assigned to: dgp
Subsystem: 38. Init - Library - Autoload Severity:
Priority: 5 Medium Last modified: 2026-10-22 17:19:31
Status: Closed Closed by: serhiy.storchaka
Resolution: Fixed Closed on: 2026-10-21 10:03:38
Version: None
Description:
Within [tclPkgUnknown] is:

            # safe interps usually don't have "file exists",
            if {([interp issafe] || [file exists $file])} {
                set code [catch {source $file} msg opt]
                if {$code == 1 &&
                        [lindex [dict get $opt -errorcode] 0] eq "POSIX" &&
                        [lindex [dict get $opt -errorcode] 1] eq "EACCES"} {
                    # $file was not readable; silently ignore
                    continue
                }
                if {$code}  {
                    tclLog "error reading package index file $file: $msg"
                } else {
                    set procdDirs($dir) 1
                }
            }

so in safe interps we intentionally do not verify file existence
before attempting the [source].  This predictably fails in many
of the searched directories, which leads to many [tclLog]
calls to report these failures.

In a safe interp, [puts] is often disabled as well, so the
[tclLog] may be silent.   (this is why the poor logic is
seldom nonticed).

However, when Safe Base is in use, some safety-enabled
version of [puts] is likely on, and the noisy error messages
spew forth.

Whole logic of safe interps needs some review at this
point.

The place this is most easily seen is in test math-12.1
in the test suite of the math package in tcllib.
User Comments:
dkf added on 2010-01-05 15:56:37:
Would also be clearer written with [try ... trap {POSIX EACCES}] in 8.6

johannes-kuhn added on 2010-01-05 20:43:49:
We allow glob, so it might be safe to allow file exists too.

serhiy.storchaka added on 2026-10-21 10:03:38:

Fixed in 8.6.11 by [a638b9a73b]: the Safe Base source alias reports missing or unreadable files with -errorcode {POSIX EACCES}, which tclPkgUnknown ignores, so the spurious "no such file" log messages are gone. Index files that fail for other reasons are still logged, as intended.