semctl: Permission denied
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > semctl: Permission denied




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    semctl: Permission denied  
redbox


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-17-07 12:21 PM

i write a simply program about producer/consumer  problem.when  it run
in root user
,it is ok.
But when it run  in other user ,occur a error. semctl: Permission
denied.
Part of my code as so :
key_t key=123;

if((semid=semget(key,2,IPC_CREAT))==0)
{
perror("semget");
exit(1);
}
if(semctl(semid,0,SETVAL,1))//for producer
{
perror("semctl");
exit(1);
}
Obviously ,there are some problem in  semctl.

but i can't found anything about it .Tanks at first.






[ Post a follow-up to this message ]



    Re: semctl: Permission denied  
Jens Thoms Toerring


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-17-07 12:21 PM

redbox <guojianlee@gmail.com> wrote:
> i write a simply program about producer/consumer  problem.when  it run
> in root user
> ,it is ok.
> But when it run  in other user ,occur a error. semctl: Permission
> denied.
> Part of my code as so :
>         key_t key=123;

>         if((semid=semget(key,2,IPC_CREAT))==0)

a) The return value on failure is -1, not 0
b) You have to specify the permission bits together with IPC_CREAT.

>         {
>                 perror("semget");
>                 exit(1);
>         }
>         if(semctl(semid,0,SETVAL,1))//for producer

Same here - semctl() returns a non-negative number on success,
and -1 on failure, so you need to test for -1 (or '< 0') to
catch errors.

>         {
>                 perror("semctl");
>                 exit(1);
>         }
> Obviously ,there are some problem in  semctl.

Since it's not clear if you get an error at all (since you don't
check for the values that would indicate an error) it's hard to
even say if anything goes wrong. But then there probably are
problems even for the case where you are root user since you
don't set the access permissions for the semaphore - IPC_CREAT
normally seems to be defined to be 01000, so no-one has any
permissions for the semaphore. Finally, do you also delete the
semaphore? It won't go away just because your program ends,
if you don't delete it it will continue to exist until you
either delete it using e.g.  the ipcrm utility or you reboot
your machine. And if you then want to re-open it as a diffe-
rent user than the one that created it this could lead to
problems if the access permissions bits aren't set correctly
for this case.
Regards, Jens
--
\   Jens Thoms Toerring  ___      jt@toerring.de
\__________________________      http://toerring.de





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 09:46 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register