change semaphore perm

Hi,

I've a problem with this simple code about of semaphore:

#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<semaphore.h>
#include<sys/types.h>
#include<sys/mman.h>
#include<sys/fcntl.h>

#define SemName "/SEM_1"   

int main (int argc, char **argv)
{
   char name[20];
   sem_t *semdes;
   sprintf(name, SemName);
   printf("\nSto creando il semaforo %s...\t", name);
   semdes = sem_open(name, O_CREAT | O_EXCL, 0666, 1);  // crea il semaforo
   printf("Semaforo %s creato!\n\n", name);

}

The code is ok, but now I would a way to view/change the perms of the semaphore.... And really I don't know a way to do it. :frowning:

Can anyone show me a way to do it...?

Do you mean sem_getvalue or are you thinking about changing permissions?

is it that you want to change the permissions of the sem ?

change it that at the time of sem_creation itself !!!!

or is it that you want to change the perms once it is created ???

I'm thinking about changing permissions....

I want change it AFTER the sem creation...

There is some confusion here. sem_open creates the semaphore in memory using it's own rules. The named semaphore can be accessed as long as the other process knows the name of the semaphore.

If you want to change things, then you will have to created shared memory, like you get with shmget then maybe calling shmat, and create your own mutex or semphore there.

You can't change protection on the memory allocated with sem_open and it's family of calls.