Re: [tkined] sample agent: snmpd-proc.tcl

Juergen Schoenwaelder (schoenw@ibr.cs.tu-bs.de)
Fri, 3 Jul 1998 12:36:30 +0200

Vincent Qing Yin <vyin@cs.ubc.ca> wrote:

> I'm have trouble understanding the sample snmpd-proc.tcl
> under the scotty/tnm/agents directory:
>
> proc SNMP_ProcInit {s} {
> ...
> $s bind procReload.0 set {
> 1 ====> global procReload procID procCmd
> 2 ====> foreach id [array names proc] {
> unset proc($id)
> }
> catch {unset cmd}
> array set cmd [SNMP_GetPS]
> foreach pid [array names cmd] {
> %S instance procID.$pid proc(id,$pid) $pid
> 3 ======> %S instance procCmd.$pid proc(cmd,$pid) $cmd($pid)
> }
> set procReload [DateAndTime]
> }
> }
>
>
> 1) Does `global' statement actually create the global variable, if
> it doesn't already exist? I don't see those three variables
> referenced outside the procedure, so I assume they come into
> existence when the procedure is called for the first time.
> In any case, after calling that proc, I issued the command
> % puts $procReload
> can't read "procReload": no such variable
> So where is procReload?

A Tcl variable is created when it is first used. See the Tcl
documentation for more details.

> 2) What is `proc'? Is that a _local_ array? I don't see that
> referenced outside of the above procedure. If it were local, how
> could it be used later on in the `%S instance' command?

It is a global array. Note that the "$s bind" command defines a
callback. This callback is always evaluated in global scope. This
means that the global statement (#1) is actually not needed. The
"inline" notation used in the script is short but a bit confusing.
The "$s bind" command is pretty similar in this respect to the Tk
bind command.

> 3) What is the purpose of `proc(cmd,$pid)'? Does it only serve
> as a place holder to keep track of what MIB instance we have
> created, so that later we can `unset proc($id)'?

The proc array is the global Tcl variable which is read to obtain
values whenever the agent processes SNMP get or getnext operations.
See the snmp(n) man page for more details. The unset above (#2)
actually destroys the instances known by the SNMP engine.

Juergen

Juergen Schoenwaelder schoenw@ibr.cs.tu-bs.de http://www.cs.tu-bs.de/~schoenw
Technical University Braunschweig, Dept. Operating Systems & Computer Networks
Bueltenweg 74/75, 38106 Braunschweig, Germany. (Tel. +49 531 / 391 3283)

--
!! This message is brought to you via the `tkined & scotty' mailing list.
!! Please do not reply to this message to unsubscribe. To subscribe or
!! unsubscribe, send a mail message to <tkined-request@ibr.cs.tu-bs.de>.
!! See http://wwwsnmp.cs.utwente.nl/~schoenw/scotty/ for more information.