2014-11-30 2 views
0

다른 사용자의 프로그램이 내 세마포를 수정하도록 허용했지만 (기본적으로 제거), 실패했습니다. 다음은 C - 세마포어 권한 문제

내 세마포어 생성 명령입니다 :의 다른 사용자가 실행 오류와 세마포어를 삭제 할 수 없습니다 있습니다

여전히
if ((semID = semget(key, 2, IPC_CREAT | 0777)) == -1) { 
    perror("Sem Creation:"); 
       exit(2); 
    } 

프로그램이 "소유자가 아님"

+2

권한이 사용자의'umask'에 의해 변경 될 수 있습니다. –

답변

0

the man page for semctl에 따르면

IPC_RMID 세마포어 집합을 즉시 제거하고, 세마포어로 차단 된 모든 프로세스를 활성화시킵니다. p (2)는 세트를 호출합니다 (오류 리턴 및 errno는 EIDRM으로 설정 됨). 호출 한 프로세스의 유효 사용자 ID는 세마포어 세트의 작성자 또는 소유자와 일치해야하며 그렇지 않으면 호출자가 권한을 가져야합니다.

따라서 세마포를 제거하려는 프로세스에는 소유자 또는 작성자의 사용자 ID가 있어야하며 수퍼 유저 여야합니다.

편집 : 당신은 세마포어의 ipc_perm 구조의 uid 필드 (소유자 ID)를 설정하는 IPC_SET 옵션 semctl()을 사용할 수 있습니다. 그렇게하면 소유권을 다른 사용자 ID로 이전 할 수 있습니다 (작성자 ID는 변경되지 않음). 링크 된 man 페이지를보고 IPC_SET 섹션을 읽으십시오.

+0

다른 프로세스/사용자에게 (어떤 식 으로든) 세마포를 제거 할 권한을 부여 할 수 없습니까? – user3440629

0
here is what you need to know about semaphore creation/removal 
Notice that a named semaphore is created using sem_open() NOT semget() 


    POSIX semaphores come in two forms: named semaphores and unnamed 
    semaphores. 

    Named semaphores 
      A named semaphore is identified by a name of the form 
      /somename; that is, a null-terminated string of up to 
      NAME_MAX-4 (i.e., 251) characters consisting of an initial 
      slash, followed by one or more characters, none of which are 
      slashes. Two processes can operate on the same named 
      semaphore by passing the same name to sem_open(3). 

      The sem_open(3) function creates a new named semaphore or 
      opens an existing named semaphore. After the semaphore has 
      been opened, it can be operated on using sem_post(3) and 
      sem_wait(3). When a process has finished using the semaphore, 
      it can use sem_close(3) to close the semaphore. When all 
      processes have finished using the semaphore, it can be removed 
      from the system using sem_unlink(3).