Semctl problem on SunOS 4.0.3c

Graham Bardsley graham at tcom.stc.co.uk
Tue Jan 15 08:57:58 AEST 1991


Is there anything at all wrong with the following code? When it's run on a
Sparc 1+ running 4.0.3c (EXPORT I presume), it fails with the message :
`Sem create failed: Bad address' from the return from the IPC_STAT.  It
similarly fails if an IPC_SET is attempted. It works fine on Sun3.  I've
looked at the bug lists we have here but find no mention of it, so should
I report this or what??

#include <stdio.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>

static struct semid_ds ctlbuf;

int SemCreate(key, val)
int key;
int val;
{
        int id;
        int status;
        struct sembuf op;

        if ((id=semget((key_t) key,
                       1,
                       IPC_CREAT | 0666)) == -1)
        {
                return -1;
        }

        if (semctl(id, 0, IPC_STAT, &ctlbuf) == -1)	/* Fails here */
        {
                semctl(id,
                      0,
                      IPC_RMID,
                      0);
                return -1;
        }

        return id;

}


int
main(argv,argc)
char **argc;
{
        int sem=SemCreate(123,1);

        if (sem == -1)
        {
                perror("Sem create failed");
                exit(1);
        }
        exit(0);
}

Graham Bardsley,STC Telecoms,Oakleigh Road South,New Southgate, London, N11 1HB
..{uunet,mcsun}!ukc!stc!graham   <graham at tcom.stc.co.uk>  Tel: +44 81 945 3799



More information about the Comp.sys.sun mailing list