Example #1
0
asmlinkage long sys_semget (key_t key, int nsems, int semflg)
{
	int id, err = -EINVAL;
	struct sem_array *sma;

	if (nsems < 0 || nsems > sc_semmsl)
		return -EINVAL;
	down(&sem_ids.sem);
	
	if (key == IPC_PRIVATE) {
		err = newary(key, nsems, semflg);
	} else if ((id = ipc_findkey(&sem_ids, key)) == -1) {  /* key not used */
		if (!(semflg & IPC_CREAT))
			err = -ENOENT;
		else
			err = newary(key, nsems, semflg);
	} else if (semflg & IPC_CREAT && semflg & IPC_EXCL) {
		err = -EEXIST;
	} else {
		sma = sem_lock(id);
		if(sma==NULL)
			BUG();
		if (nsems > sma->sem_nsems)
			err = -EINVAL;
		else if (ipcperms(&sma->sem_perm, semflg))
			err = -EACCES;
		else
			err = sem_buildid(id, sma->sem_perm.seq);
		sem_unlock(id);
	}

	up(&sem_ids.sem);
	return err;
}
Example #2
0
asmlinkage int sys_semget (key_t key, int nsems, int semflg)
{
	int id, err = -EINVAL;
	struct semid_ds *sma;

	lock_kernel();
	if (nsems < 0 || nsems > SEMMSL)
		goto out;
	if (key == IPC_PRIVATE) {
		err = newary(key, nsems, semflg);
	} else if ((id = findkey (key)) == -1) {  /* key not used */
		if (!(semflg & IPC_CREAT))
			err = -ENOENT;
		else
			err = newary(key, nsems, semflg);
	} else if (semflg & IPC_CREAT && semflg & IPC_EXCL) {
		err = -EEXIST;
	} else {
		sma = semary[id];
		if (nsems > sma->sem_nsems)
			err = -EINVAL;
		else if (ipcperms(&sma->sem_perm, semflg))
			err = -EACCES;
		else
			err = (int) sma->sem_perm.seq * SEMMNI + id;
	}
out:
	unlock_kernel();
	return err;
}
Example #3
0
/* 从系统中获取一个信号量 */
int sys_semget (key_t key, int nsems, int semflg)
{
	int id;
	struct semid_ds *sma;
	
	if (nsems < 0  || nsems > SEMMSL)
		return -EINVAL;
	if (key == IPC_PRIVATE) 
		return newary(key, nsems, semflg);
	if ((id = findkey (key)) == -1) {  /* key not used */
		/* 对应key的信号量没有找到,又不是创建标记则出错,否则创建一个新的 */
		if (!(semflg & IPC_CREAT))
			return -ENOENT;
		return newary(key, nsems, semflg);
	}
	if (semflg & IPC_CREAT && semflg & IPC_EXCL)
		return -EEXIST;
	sma = semary[id];
	if (nsems > sma->sem_nsems)
		return -EINVAL;
	if (ipcperms(&sma->sem_perm, semflg))
		return -EACCES;
	/* 和newary返回联系 */
	return sma->sem_perm.seq*SEMMNI + id;
} 
Example #4
0
int sys_semget (key_t key, int nsems, int semflg)
{
	int id;
	struct semid_ds *sma;

	if (nsems < 0 || nsems > SEMMSL)
		return -EINVAL;
	if (key == IPC_PRIVATE)
		return newary(key, nsems, semflg);
	if ((id = findkey (key)) == -1) {  /* key not used */
		if (!(semflg & IPC_CREAT))
			return -ENOENT;
		return newary(key, nsems, semflg);
	}
	if (semflg & IPC_CREAT && semflg & IPC_EXCL)
		return -EEXIST;
	sma = semary[id];
	if (nsems > sma->sem_nsems)
		return -EINVAL;
	if (ipcperms(&sma->sem_perm, semflg))
		return -EACCES;
	return (unsigned int) sma->sem_perm.seq * SEMMNI + id;
}