[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference noted::hackers_v1

Title:-={ H A C K E R S }=-
Notice:Write locked - see NOTED::HACKERS
Moderator:DIEHRD::MORRIS
Created:Thu Feb 20 1986
Last Modified:Mon Aug 03 1992
Last Successful Update:Fri Jun 06 1997
Number of topics:680
Total number of notes:5456

547.0. "C CHF examples" by WJG::GUINEAU () Tue Sep 08 1987 20:05


Anyone have condition handling examples in C?
T.RTitleUserPersonal
Name
DateLines
547.1Its in SID...MONSTR::DUTKONestor Dutko, VMS/VAXclusters CSSEWed Sep 09 1987 13:51150
Example-C  Creating A User-Written Condition Handler

DATE: 26-SEP-1986

\SOURCE: CSC/CS by Starkey of CISG/LST
\

OVERVIEW:

This example illustrates a user-written condition handling routine that
determines the reason for a system service failure.  This article contains
approximately 140 lines.

CAUTION:  This sample program has been tested using C, V2.2 on VAX/VMS,
V4.4.  However, we cannot guarantee its effectiveness because of the
possibility of error in transmitting or implementing it.  It is meant to
be used as a template for writing your own program, and it may require
modification for use on your system.


SOURCE:

This programming example was taken from the VAX/VMS Education Series,
UTILIZING VMS FEATURES FROM VAX C, C Language Workbook, (Aug 86).

It and a companion volume, UTILIZING VMS FEATURES, Student Programming
Workbook (Aug 86), are part of a self-paced course.  This course can
be ordered by calling Digital Equipment Corporation, Educational
Services, toll-free, 1-800-343-8321.  (The order number is EY-3482E-SP
for the Student Package which includes both.  The course examples and
exercises are also available on various media under a different order
number.)


PROGRAM NOTES:

This program defines and establishes its own condition handling routine to
handle system service failures.

This example illustrates a user-written, condition handling routine that
determines the reason for a system service failure.  The example handler
handles only system service failures.  All other exceptions are
resignalled, allowing them to be handled by the system default handlers.

LIB$ESTABLISH establishes the condition/handler SSHAND.

System service failure mode is enabled so that errors in system service
calls will initiate a search for a condition handler.

The call to SYS$QIOW generates a system service failure.

The function sshand will return  status code to the Condition Handling
Facility.  The Condition Handling Facility passes two arguments to sshand:
the signal array and the mechanism array.

The handler checks the error condition to determine if it is one that it
can handle.  If the routine needed to check for more than one error,
LIB$MATCH_CONDITION could be used.

The SYS$GETMSG System Service translates the error code into the associated
error message.

Assuming the handler took corrective action, it passes a return status code
of SS$CONTINUE back to the Condition Handling Facility, causing the main
program to resume execution.  If the handler did not take corrective
action, it would have returned the code SS$_RESIGNAL, causing the error to
be resignaled for the system default condition handlers.

The first two lines of output are from the condition handler.  Note that
the output from the main program follows.


PROGRAM:

/* SSCOND.C
   This program defines and established its own
   condition handling routine to handle system
   service failures. */

#include ssdef
#include descrip

main()
{
int sshand();

/* establish condition handler */
VAXC$ESTABLISH(sshand);

/* enable system service failure mode */
SYS$SETSFM(1);

/* generate bad system service call */
SYS$QIOW(0,0,0,0,0,0,0,0,0,0,0,0);

printf("\n\nEnd of program.");
}


int sshand(signal, mech)
int signal[], mech[];
{
char buf[133];
short msglen;
$DESCRIPTOR(errmsg, buf);
int status;

/* if not system service failure, resignal */
if (signal[1] != SS$_SSFAIL)
   return SS$_RESIGNAL;
else
   {
   /* display message */
   if (((status = SYS$GETMSG(signal[2], &msglen, &errmsg,
                             15, 0)) &1) !=1)
      LIB$STOP(status);
   printf("\nSystem service call failed:\n%.*s", msglen, buf);

   /* handler would perform corrective action here */

   return SS$_CONTINUE;
   }
}


RUNNING THE PROGRAM:

$ CC SSCOND
$ LINK SSCOND
$ RUN SSCOND
System service call failed:
%SYSTEM-F-IVCHAN, invalid I/O channel

End of program.
$


HOW TO COPY THIS ARTICLE:

We suggest reading this article on a hardcopy terminal.  This will reduce
the possibility of errors from copying the code by hand.  If you must copy
the code by hand, we strongly recommend that after you have copied it, you
select the article from the menu a second time and compare the two versions.
This process will help you spot possible transmission errors.

\SID Keyword Information
\\C  VER_2.N_C  CONDITION  HANDLER  EXAMPLE  $QIOW  $QIO  $GETMSG
\\%CURRENT  #CPS  $SETSFM  LIB$ESTABLISH
\\%QE015  
\SID Review badge as of 17-APR-1987 17:49:33.61 was 140166
547.2PerfectWJG::GUINEAUWed Sep 09 1987 16:024

Thanks!