Operating System - OpenVMS
1752782 Members
6225 Online
108789 Solutions
New Discussion юеВ

C-compile openvms alarm/setjmp/longjmp/signal

 
Seye
New Member

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
New Member

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?
Seye
New Member

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

Now i'm using a ALPHA on OPENVMS 7.3-2 with
compile DECC$COMPILER V7.1-015, but in the future it will be INTEGRITY OPENVMS 8.3-1H1
with c-compile HP I64VMS C V7.3-18.
The behaver of the program is the same on two platforms.
David Jones_21
Trusted Contributor

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

The problem has nothing to do with the signal getting reset. The alarm() signal is not actually interrupting the gets() call (i.e. cancelling the read from stdin), so the stream is still busy when the next call to my_read() calls gets() again. Gets() then returns NULL with errno set to EVMSERR.
I'm looking for marbles all day long.