[Starkit] where are .dll files written to?

Steve Landers steve at digitalsmarties.com
Thu Mar 8 08:09:26 CET 2007


On 08/03/2007, at 12:40 AM, Steve Blinkhorn wrote:

> What I find on a
> Win2000 Professional box is that the files are copied to %temp% as
> TCL???.tmp, and deleted on normal exit.   But they persist if the
> application is crashed out rather than exiting cleanly.
>
> I am no expert on Windows internals, so I do not know whether these
> files need to remain accessible throughout the runtime of an  
> application
> or whether they are loaded into memory just once - in which case it  
> would
> seem sensible for them to be deleted immediately rather than only  
> on normal
> exit from the application.   But I imagine that this is a matter for
> the Tcl core rather than just Starkits.

It is, but you can provide a workaround that is helpful in some  
circumstances.

When loading a shared library on most Unix platforms, the Tcl VFS  
code will first copy it from the VFS to a temporary file, then  
dynamically load it, then remove the temporary file.

On Windows and HP-UX it can't remove the temporary file while it is  
still in use by the system, so this has to happen during the Tcl  
shutdown sequence, as you observe. As an aside, this is strong  
evidence that HP-UX is not Unix ;-)

In the past I've included some code in my applications to clean up  
any of these temporary files left lying around after an application  
or system crash. I thought that I'd wikified it, but can't locate it  
so I've included it here in case it is useful to you.

You'll need to set appropriate values for dir and pattern in the  
Windows section of the switch command. Call "Cleanup" near the start  
of your application and it will prevent temporary files from  
accumulating over time.

Steve

----------------

#
#  Clean up temporary files left by Tcl when loading shared libraries  
from
#  within a virtual file system (VFS).
#
#  Only needed on certain platforms (the Tclkit version number
#  is in $vfs::tclkit_version)
#
proc Cleanup {} {
     global tcl_platform
     switch $tcl_platform(os) {
         HP-UX {
             # Tcl uses mkstemp to create the temporary file. As at  
HP-UX
             # B.11.00 this doesn't use the TMPDIR, TMP or TEMP  
variables, but
             # rather places the temporary files in /var/tmp
             set dir /var/tmp
             set pattern "tcl??????"
         }
         Windows* {
             return
         }
         default {
             return
         }
     }
     # note we silently ignore any errors
     catch {
         if {[file isdirectory $dir]} {
             set user $tcl_platform(user)
             set now [clock seconds]
             # number of seconds old that a temporary file must be  
before it will be
             # deleted - this is done to avoid the (extremely  
unlikely) race
             # condition wherein two copies of the application are run
             # currently, and this cleanup runs between the VFS  
creating the
	    # temporary file and when it loads it
             set age 10
             cd $dir
             foreach file [glob $pattern] {
                 # only those files owned by the current user
                 if {[file attributes $file -owner] eq $user} {
                     if {[expr {$now - [file mtime $file]}] > $age} {
                         file delete $file
                     }
                 }
             }
         }
     } msg
     # puts stderr "msg = $msg"          ;# uncomment to debug
}


More information about the Starkit mailing list