/* Attach task with pid 'pid' to cgroup 'cgrp'. Call with cgroup_mutex held. May take task_lock of task  */
static int attach_task_by_pid(struct cgroup *cgrp, u64 pid)
/* Attach task with pid 'pid' to cgroup 'cgrp'. Call with cgroup_mutex held. May take task_lock of task  */
static int attach_task_by_pid(struct cgroup *cgrp, u64 pid)
{
	struct task_struct *tsk;
	const struct cred *cred = current_cred(), *tcred;
	int ret;
	if (pid) {
		rcu_read_lock();
		tsk = find_task_by_vpid(pid);
		if (!tsk || tsk->flags & PF_EXITING) {
			rcu_read_unlock();
			return -ESRCH;
		}
		tcred = __task_cred(tsk);
		if (cred->euid &&
		    cred->euid != tcred->uid &&
		    cred->euid != tcred->suid) {
			rcu_read_unlock();
			return -EACCES;
		}
		get_task_struct(tsk);
		rcu_read_unlock();
	} else {
		tsk = current;
		get_task_struct(tsk);
	}
	ret = cgroup_attach_task(cgrp, tsk);
	put_task_struct(tsk);
	return ret;
}