RE: 4GL question
Posted in 2000
Topics: Storage & Space Management, Error Codes & Troubleshooting, Connectivity: ESQL/C, 4GL & Embedded SQL, Server Administration, Versions, Editions & End-of-Life
Wouldn't that sample code override all 4gl signal handling? I would think you might save the old interupts if they exist in a global structure and in your signal handler set back to the old and resend the signal. here is an example of saving the old interrupt: #include <stdio.h> #include <signal.h> void *func; void *oldfunc; void sighand(); void sigold(); void main() { /* make it as if there was already a signal set */ oldfunc=signal(SIGINT, sigold); /* set the signal save the old */ func = (void *)signal(SIGINT, sighand); getchar(); /* wait for input */ return; } void sighand() { /* stuff you want to do */ printf("caught new\\n"); signal(SIGINT, func); kill(getpid(), SIGINT); } void sigold() { /* code to release memory ... */ printf("caught old\\n"); kill(getpid(), SIGINT); } This is not really production worthy either though, I think you have to have sigaction, sigsuspend ... to get something which is hard for a user to screw up. This is because consecutive SIGINT's for the above program could bypass the second signal handler. The sigaction, sigsuspend... help get around such issues. Will P.S. SIGKILL cant be trapped, most others can be though. >===== Original Message From Paul Watson <paulw@wfsoftware.com> ===== >Surely though kill can't be trapped. If the instance dies then the 4gl >can call it's own internal handler and exit accordingly. Below, >hopefully >the chunk of esql below should allow you to look at trapping the >trappable >signals and tidying up. It might be useful, it's very old though > >#include <stdio.h> >#include <signal.h> / >$include sqlca; >#define ERROR sqlca.sqlcode >#define CISAM sqlca.sqlerrd[1] > >main(argc, argv) >int argc; >char *argv[]; >{ >''' $char''dbname[18]; >''' int''' sighand(); > >''' signal(SIGHUP, sighand);'' >''' signal(SIGINT, sighand);''' >''' signal(SIGQUIT, sighand);''' >''' signal(SIGFPE, sighand);''' >''' signal(SIGBUS, sighand);''' >''' signal(SIGSEGV, sighand);' >''' signal(SIGTERM, sighand);'' > >''' /* The above could be replaced by >''' { >''''''' int i; >''''''' for(i=1; i<NSIG; i++) >''''''''''' signal(i, sighand); >''' } >''' */ > >''' sprintf(dbname,"%s", argv[1]); >''' $database $dbname; >''' /* >''' The main code lives from here >''' */ > >''' $close database; >} > >int sighand()''' /* signal handling function */ >{ >''' sqlbreak();''' >''' sqlexit();''' >''' exit(1);''' >} > > > >"Carlson@WHSmith" wrote: >> >> William Rice wrote: >> > >> > Do you mean propagated back to the shell through $? (this is the only way >> > I know of signal information of a called process is passed on) >> > >> >> That's it . . . . >> >> I'm aware of the 'exit program' functionality, but that presupposes a >> planned exit from the program. I'm looking for a way to trap an >> unexpected "program clobber" (e.g.. KILL, instance drops, etc.) and send >> it back to the shell. >> >> > >> > >===== Original Message From "Mark D. Stock" <mdstock@mydas.freeserve.co.uk> >> > ===== >> > >"Carlson@WHSmith" wrote: >> > >> >> > >> For all the 4GL gurus out there: >> > >> >> > >> HPUX 10.20 >> > >> IDS 7.30.uc7 >> > >> 4GL 7.20.ud6 >> > >> >> > >> I'm looking to return error codes from a 4GL program to the shell. >> > >> While I can trap and return an error code using "exit program", is there >> > >> a way to trap an error code if the program was killed, crashed, etc.??? >> > > >> > >As I remember you can do this with a shell wrapper and a carefully coded >> > >trap command. Interrupts are just that and will therefore never reach >> > >your EXIT PROGRAM. However, they are (or were) propagated back to the >> > >shell script. Don't trap too much otherwise the shell script will lock >> > >up. Sorry I don't have any examples. >> > > >> > >Cheers, >> > >-- >> > >Mark. >> > > >> > >+----------------------------------------------------------+-----------+ >> > >| Mark D. Stock mailto:mdstock@mydas.freeserve.co.uk |//////// /| >> > >| http://www.informix.com http://www.informixhandbook.com |///// / //| >> > >| http://www.iiug.org +-----------------------------------+//// / ///| >> > >| |What year 2000 bug? year 2000 bug? |/// / ////| >> > >| |year 2000 bug? year 2000 bug? year |// / /////| >> > >| |2000 bug? year 2000 bug? year 1900 |/ ////////| >> > >+----------------------+-----------------------------------+-----------+ >> > >> > ------------------------------------------------------------ >> > This e-mail has been sent to you courtesy of OperaMail, as a free service from >> > Opera Software, makers of the award-winning Web Browser, Opera. Visit us at >> > http://www.opera.com/ or our portal at: http://www.myopera.com/ Your free e-mail >> > account is waiting at: http://www.operamail.com/ >> > ------------------------------------------------------------ >> >> -- >> John Carlson >> Informix DBA >> WHSmith USA >> >> #include std_disclaimer.h /* These are my opinions, not my company's >> opinion */ > >-- >Paul Watson # >WF Software Ltd # You are only young once >Tel: +44 1436 674728 # but you can be immature >Fax: +44 1436 678693 # for ever >www.wfsoftware.com # ------------------------------------------------------------ This e-mail has been sent to you courtesy of OperaMail, as a free service from Opera Software, makers of the award-winning Web Browser, Opera. Visit us at http://www.opera.com/ or our portal at: http://www.myopera.com/ Your free e-mail account is waiting at: http://www.operamail.com/ ------------------------------------------------------------
Yes, but it was only a starting point:-)) William Rice wrote: > > Wouldn't that sample code override all 4gl signal handling? > I would think you might save the old interupts if they exist in a global > structure > and in your signal handler set back to the old and resend the signal. > > here is an example of saving the old interrupt: > #include <stdio.h> > #include <signal.h> > > void *func; > void *oldfunc; > void sighand(); > void sigold(); > > void main() > { > /* make it as if there was already a signal set */ > oldfunc=signal(SIGINT, sigold); > > /* set the signal save the old */ > func = (void *)signal(SIGINT, sighand); > getchar(); /* wait for input */ > return; > } > void sighand() > { > /* stuff you want to do */ > printf("caught new\\n"); > signal(SIGINT, func); > kill(getpid(), SIGINT); > } > > void sigold() > { > /* code to release memory ... */ > printf("caught old\\n"); > kill(getpid(), SIGINT); > } > > This is not really production worthy either though, I think you have to > have sigaction, sigsuspend ... to get something which is hard for a > user to screw up. This is because consecutive SIGINT's for the above program > could bypass the second signal handler. The sigaction, sigsuspend... > help get around such issues. > > Will > > P.S. SIGKILL cant be trapped, most others can be though. > > >===== Original Message From Paul Watson <paulw@wfsoftware.com> ===== > >Surely though kill can't be trapped. If the instance dies then the 4gl > >can call it's own internal handler and exit accordingly. Below, > >hopefully > >the chunk of esql below should allow you to look at trapping the > >trappable > >signals and tidying up. It might be useful, it's very old though > > [cutting] -- Paul Watson # WF Software Ltd # You are only young once Tel: +44 1436 674728 # but you can be immature Fax: +44 1436 678693 # for ever www.wfsoftware.com #