Re: [tkined] mib error messages, part 2.

Juergen Schoenwaelder (schoenw@ibr.cs.tu-bs.de)
Thu, 9 Jul 1998 15:19:01 +0200

>>>>> Michael Landman writes:

Michael> using the mib load command, I note that some error messages,
Michael> like the one I described in my previous email, are non-fatal.

Michael> If, in my tcl script, I wanted to have "access" to that error
Michael> message, how the heck can I get at it?

Michael> For example,

Michael> "mib load <filename>" normally returns nothing, if there is
Michael> no errors.

Michael> "mib load <filename>" might return: "<filename>: no parent
Michael> <x> for node <y>" if there was some non-fatal error
Michael> processing the file.

Michael> However, TCL_ERROR is not really set in this case, and
Michael> "catch" always returns 0. If I wanted to "know" in my tcl
Michael> script that I received such an error, does anybody know how
Michael> this can be done??

The current MIB does not have a nice way to deal with errors. Error
messages are simply written to stderr, which is not a good idea within
an interpreter environment. Anyway, the parser is ugly and needs to be
replaced for various reasons some day so I did not spend time to fix
this.

You are right, however, that there should be at least an error
indication so that a script can check whether the mib load command
succeeded or not. Below is a patch which fixes this for most cases.

Juergen

diff -c tnm/snmp/tnmMibParser.c.orig tnm/snmp/tnmMibParser.c
*** tnm/snmp/tnmMibParser.c.orig Thu Nov 13 12:04:33 1997
--- tnm/snmp/tnmMibParser.c Thu Jul 9 15:05:10 1998
***************
*** 363,369 ****
tnm_MibTCSaveMark = tnm_MibTCList;
nodePtr = ParseFile(fp);
fclose(fp);
! if (nodePtr != NULL || tnm_MibTCList != tnm_MibTCSaveMark) {
fp = fopen(frozen, "wb");
if (fp != NULL) {
Tnm_MibWriteFrozen(fp, nodePtr);
--- 362,371 ----
tnm_MibTCSaveMark = tnm_MibTCList;
nodePtr = ParseFile(fp);
fclose(fp);
! if (nodePtr == NULL && tnm_MibTCList == tnm_MibTCSaveMark) {
! unlink(frozen);
! return NULL;
! } else {
fp = fopen(frozen, "wb");
if (fp != NULL) {
Tnm_MibWriteFrozen(fp, nodePtr);
diff -c tnm/snmp/tnmMibTcl.c.orig snmp/tnmMibTcl.c
*** tnm/snmp/tnmMibTcl.c.orig Fri Sep 13 17:03:34 1996
--- tnm/snmp/tnmMibTcl.c Thu Jul 9 15:10:03 1998
***************
*** 429,436 ****
if (fileName) {
tnm_MibTree = Tnm_MibParse(fileName, frozenFileName, tnm_MibTree);
if (tnm_MibTree == NULL) {
! Tcl_AppendResult(interp, "parsing MIB file ", fileName," failed",
! (char *) NULL);
code = TCL_ERROR;
}
} else {
--- 433,440 ----
if (fileName) {
tnm_MibTree = Tnm_MibParse(fileName, frozenFileName, tnm_MibTree);
if (tnm_MibTree == NULL) {
! Tcl_AppendResult(interp, "couldn't parse MIB file \"",
! fileName,"\"", (char *) NULL);
code = TCL_ERROR;
}
} else {

--
!! 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.