Operating System - OpenVMS
cancel
Showing results for 
Search instead for 
Did you mean: 

C-compile openvms alarm/setjmp/longjmp/signal

 
Seye
Occasional Visitor

C-compile openvms alarm/setjmp/longjmp/signal

I like to make a timed_gets but the reset of alarm() seems not working:
Base source:
#include
#include
#include
static jmp_buf jbuf;
unsigned char lijn[1024];
int cnt;

static alarmroutin()
{
alarm(0);
longjmp(jbuf,TRUE);
}

static my_read(lijn,cnt)
char *lijn;
int cnt;
{
int alarmroutin();

if (setjmp(jbuf)) return FALSE;
signal (SIGALRM, alarmroutin);
alarm(10);
*lijn='\0';
printf ("\n geef iets %d :",cnt);gets(lijn);
alarm(0);
return strlen(lijn);
}

main()
{
unsigned char *p;
int i,my_read();

cnt=0;
while (cnt < 100000000){
i=my_read(lijn,cnt);
alarm(0);
cnt++;
printf("\n%d\n",i);
if (strstr(lijn,"STOP")) break;
}
}

What is wrong?
7 REPLIES 7
Joseph Huber_1
Honored Contributor

Re: C-compile openvms alarm/setjmp/longjmp/signal

If You correct the C syntax, the program compiles (with a minor warning), and runs, although I don't know what to wxpect after alarm fires the first time, it return timeout always afterwards.

Start of the corrected program:

#include
#include
#include
#include
#include
#include
#include

#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif

static jmp_buf jbuf;
unsigned char lijn[1024];
int cnt;

static void alarmroutin(int sig)
{
alarm(0);
longjmp(jbuf,TRUE);
}

static my_read(lijn,cnt)
char *lijn;
int cnt;
{
if (setjmp(jbuf)) return FALSE;
http://www.mpp.mpg.de/~huber
Joseph Huber_1
Honored Contributor

Re: C-compile openvms alarm/setjmp/longjmp/signal

>> but the reset of alarm() seems not working.
Oh, and under Linux/gcc it has the inverse effect: alarm never fires again after the first time ...
http://www.mpp.mpg.de/~huber
Dennis Handly
Acclaimed Contributor

Re: C-compile openvms alarm/setjmp/longjmp/signal

>but the reset of alarm() seems not working

This is probably due to the fact you aren't using sigsetjmp/siglongjmp to save the signal masks.
Some OSes will block the current signal upon entry to the signal handler and unblock on exit. Other OSes will only block the signal if specified in sigaction(2). HP-UX will not block it for signal(2) so my similar test program works fine.
Seye
Occasional Visitor

Re: C-compile openvms alarm/setjmp/longjmp/signal

Tanks for your help but none seems to worck
Hoff
Honored Contributor

Re: C-compile openvms alarm/setjmp/longjmp/signal

Can this program use native APIs, and not the C APIs?

(If this is Itanium, tossing around lots of signals - once you get it all working - tend to be bad performance news, too.)

What's the background on this requirement? OpenVMS platform, code portability requirements, OpenVMS version, etc?