bind dcc n fileinfo tellfileinfo
proctellfileinfo {hand idx text} {
if {$text eq ""} {
foreach f [file channels] {
if {![string match file* $f]} { continue }
catch {tellfileinfo $hand $idx $f}
}
} else {
set f $text
putdcc $idx "Filesock $f -> [file normalize [handle2file $f]]. Opened by \[[handle2opener $f]\]"
}
}
if {![info exists ::opentrace]} {
# add the 2 traces. one to 'open', one to 'close'.
trace add execution open leave tracer_open
trace add execution close leave tracer_close
set ::opentrace 1
}
#procedure to lookup <socket> to <filename> (or commandname if piped)
# Usage: handle2file fileXXXX
# Example: "handle2file [open randomfile w]" should return "randomfile"
# (close the file afterwards :)
prochandle2file {handle} {
if {![info exists ::openfiles($handle)]} {
error"File handle not found"
} else {
return [lindex $::openfiles($handle) 0]
}
}
#procedure to lookup <socket> to <procedure which initially called open>
prochandle2opener {handle} {
if {![info exists ::openfiles($handle)]} {
error"File handle not found"
} else {
return [lindex $::openfiles($handle) 1]
}
}
# tracer_open "open <filename> ?mode?" 0/1 "file..." leave
proctracer_open {cmdstr rescode resstr op} {
# there was an error, file wasn't really opened
if {$rescode} { return }
# check if it was a filesocket
if {[string match file* $resstr]} {
# add handle with corresponding filename to array
if {[catch {info level -1} caller]} { set caller -global- }
set ::openfiles($resstr) [list [lindex [split $cmdstr] 1] $caller]
}
}
# tracer_close "close <handle>" 0/1 "" leave
proctracer_close {cmdstr rescode resstr op} {
set handle [lindex [split $cmdstr] 1]
# there was an error or I don't know about that handle
if {$rescode || ![info exists ::openfiles($handle)]} { return }
# remove handle from array
unset ::openfiles($handle)
}
This post was edited 4 times, last on 09-26-2010, 02:14 by thommey
Advanced options for this topic:
Ignore this topic (Do not list this topic in the "unread topics" search. You are currently not ignoring this topic.) Hide this topic (Hidden topics are not displayed in the topics list. This topic is currently not hidden.)