Пример #1
0
asmlinkage long sys_msgget (key_t key, int msgflg)
{
	int id, ret = -EPERM;
	struct msg_queue *msq;
	
	down(&msg_ids.sem);
	if (key == IPC_PRIVATE) 
		ret = newque(key, msgflg);
	else if ((id = ipc_findkey(&msg_ids, key)) == -1) { /* key not used */
		if (!(msgflg & IPC_CREAT))
			ret = -ENOENT;
		else
			ret = newque(key, msgflg);
	} else if (msgflg & IPC_CREAT && msgflg & IPC_EXCL) {
		ret = -EEXIST;
	} else {
		msq = msg_lock(id);
		if(msq==NULL)
			BUG();
		if (ipcperms(&msq->q_perm, msgflg))
			ret = -EACCES;
		else
			ret = msg_buildid(id, msq->q_perm.seq);
		msg_unlock(id);
	}
	up(&msg_ids.sem);
	TRACE_IPC(TRACE_EV_IPC_MSG_CREATE, ret, msgflg);
	return ret;
}
Пример #2
0
asmlinkage int sys_msgget (key_t key, int msgflg)
{
	int id, ret = -EPERM;
	struct msqid_ds *msq;
	
	lock_kernel();
	if (key == IPC_PRIVATE) 
		ret = newque(key, msgflg);
	else if ((id = findkey (key)) == -1) { /* key not used */
		if (!(msgflg & IPC_CREAT))
			ret = -ENOENT;
		else
			ret = newque(key, msgflg);
	} else if (msgflg & IPC_CREAT && msgflg & IPC_EXCL) {
		ret = -EEXIST;
	} else {
		msq = msgque[id];
		if (msq == IPC_UNUSED || msq == IPC_NOID)
			ret = -EIDRM;
		else if (ipcperms(&msq->msg_perm, msgflg))
			ret = -EACCES;
		else
			ret = (unsigned int) msq->msg_perm.seq * MSGMNI + id;
	}
	unlock_kernel();
	return ret;
} 
Пример #3
0
asmlinkage long sys_msgget(key_t key, int msgflg)
{
	struct msg_queue *msq;
	int id, ret = -EPERM;
	struct ipc_namespace *ns;

	ns = current->nsproxy->ipc_ns;
	
	mutex_lock(&msg_ids(ns).mutex);
	if (key == IPC_PRIVATE) 
		ret = newque(ns, key, msgflg);
	else if ((id = ipc_findkey(&msg_ids(ns), key)) == -1) { /* key not used */
		if (!(msgflg & IPC_CREAT))
			ret = -ENOENT;
		else
			ret = newque(ns, key, msgflg);
	} else if (msgflg & IPC_CREAT && msgflg & IPC_EXCL) {
		ret = -EEXIST;
	} else {
		msq = msg_lock(ns, id);
		BUG_ON(msq == NULL);
		if (ipcperms(&msq->q_perm, msgflg))
			ret = -EACCES;
		else {
			int qid = msg_buildid(ns, id, msq->q_perm.seq);

			ret = security_msg_queue_associate(msq, msgflg);
			if (!ret)
				ret = qid;
		}
		msg_unlock(msq);
	}
	mutex_unlock(&msg_ids(ns).mutex);

	return ret;
}