🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.sun
Article #8780

What to use for 4th argument to semctl when 3rd argument is GETVAL

#8780
From: James Sim
Date: Thu, 27 Jun 1991 20:22
31 lines
1826 bytes
When I call semctl as follows under SunOS version 4.1, I get a segmentation 
fault.  When I use the same code under Concurrent RTU, the code works fine.

semctl(semid, semnum, GETVAL, 0);

When the third argument is GETVAL, semctl is not using the fourth argument,
if I read the man page correctly.  I managed to get the code to work by 
changing the code as follows:

struct sembuf sem_oper;

semctl(semid, semnum, GETVAL, sem_oper);

where sem_oper is an automatic variable, which has not been assigned any
values prior to calling semctl.  I don't see why this should work, since the 
contents of the automatic variable, sem_oper are indeterminate. 

I also tried 

semctl(semid, semnum, GETVAL, 1);

thinking that semctl is expecting a non-zero fourth argument, although why it 
should expect ANYTHING for a fourth argument when the third argument is GETVAL
I don't know.

The man page for semctl does not mention the use of the fourth argument when
the third argument is GETVAL, while it specifically outlines the use of the
fourth argument for certain other values of the third argument.  From this I
inferred that semctl does not use the fourth argument when the third argument
is GETVAL.  So why am I getting a segmentation fault, and what is semctl 
really expecting for the fourth argument?
Technical Details
Message-ID: <4183@brchh104.bnr.ca>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!cunews!bnrgate!brchh104!brchs1!bnr.ca!rice.edu!sun-spots-request

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!cunews!bnrgate!brchh104!brchs1!bnr.ca!rice.edu!sun-spots-request
From: sim@mdtf05.fnal.gov (James Sim)
Newsgroups: comp.sys.sun
Subject: What to use for 4th argument to semctl when 3rd argument is GETVAL
Keywords: No Digest Subjects during Flush
Message-ID: <4183@brchh104.bnr.ca>
Date: 27 Jun 91 20:22:00 GMT
Sender: news@brchh104.bnr.ca
Organization: Sunspots, Flush Mode
Lines: 32
Approved: sun-spots@rice.edu
X-Original-Date:    Tue, 25 Jun 1991 23:51:50 GMT