Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/kern_prot.c
Show First 20 Lines • Show All 327 Lines • ▼ Show 20 Lines | sys_setsid(struct thread *td, struct setsid_args *uap) | ||||
int error; | int error; | ||||
struct proc *p = td->td_proc; | struct proc *p = td->td_proc; | ||||
struct pgrp *newpgrp; | struct pgrp *newpgrp; | ||||
struct session *newsess; | struct session *newsess; | ||||
error = 0; | error = 0; | ||||
pgrp = NULL; | pgrp = NULL; | ||||
newpgrp = malloc(sizeof(struct pgrp), M_PGRP, M_WAITOK | M_ZERO); | newpgrp = uma_zalloc(pgrp_zone, M_WAITOK); | ||||
newsess = malloc(sizeof(struct session), M_SESSION, M_WAITOK | M_ZERO); | newsess = malloc(sizeof(struct session), M_SESSION, M_WAITOK | M_ZERO); | ||||
sx_xlock(&proctree_lock); | sx_xlock(&proctree_lock); | ||||
if (p->p_pgid == p->p_pid || (pgrp = pgfind(p->p_pid)) != NULL) { | if (p->p_pgid == p->p_pid || (pgrp = pgfind(p->p_pid)) != NULL) { | ||||
if (pgrp != NULL) | if (pgrp != NULL) | ||||
PGRP_UNLOCK(pgrp); | PGRP_UNLOCK(pgrp); | ||||
error = EPERM; | error = EPERM; | ||||
} else { | } else { | ||||
(void)enterpgrp(p, p->p_pid, newpgrp, newsess); | (void)enterpgrp(p, p->p_pid, newpgrp, newsess); | ||||
td->td_retval[0] = p->p_pid; | td->td_retval[0] = p->p_pid; | ||||
newpgrp = NULL; | newpgrp = NULL; | ||||
newsess = NULL; | newsess = NULL; | ||||
} | } | ||||
sx_xunlock(&proctree_lock); | sx_xunlock(&proctree_lock); | ||||
if (newpgrp != NULL) | uma_zfree(pgrp_zone, newpgrp); | ||||
free(newpgrp, M_PGRP); | |||||
if (newsess != NULL) | |||||
free(newsess, M_SESSION); | free(newsess, M_SESSION); | ||||
return (error); | return (error); | ||||
} | } | ||||
/* | /* | ||||
* set process group (setpgid/old setpgrp) | * set process group (setpgid/old setpgrp) | ||||
* | * | ||||
* caller does setpgid(targpid, targpgid) | * caller does setpgid(targpid, targpgid) | ||||
Show All 22 Lines | sys_setpgid(struct thread *td, struct setpgid_args *uap) | ||||
int error; | int error; | ||||
struct pgrp *newpgrp; | struct pgrp *newpgrp; | ||||
if (uap->pgid < 0) | if (uap->pgid < 0) | ||||
return (EINVAL); | return (EINVAL); | ||||
error = 0; | error = 0; | ||||
newpgrp = malloc(sizeof(struct pgrp), M_PGRP, M_WAITOK | M_ZERO); | newpgrp = uma_zalloc(pgrp_zone, M_WAITOK); | ||||
sx_xlock(&proctree_lock); | sx_xlock(&proctree_lock); | ||||
if (uap->pid != 0 && uap->pid != curp->p_pid) { | if (uap->pid != 0 && uap->pid != curp->p_pid) { | ||||
if ((targp = pfind(uap->pid)) == NULL) { | if ((targp = pfind(uap->pid)) == NULL) { | ||||
error = ESRCH; | error = ESRCH; | ||||
goto done; | goto done; | ||||
} | } | ||||
if (!inferior(targp)) { | if (!inferior(targp)) { | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | if ((pgrp = pgfind(uap->pgid)) == NULL) { | ||||
} | } | ||||
PGRP_UNLOCK(pgrp); | PGRP_UNLOCK(pgrp); | ||||
error = enterthispgrp(targp, pgrp); | error = enterthispgrp(targp, pgrp); | ||||
} | } | ||||
done: | done: | ||||
sx_xunlock(&proctree_lock); | sx_xunlock(&proctree_lock); | ||||
KASSERT((error == 0) || (newpgrp != NULL), | KASSERT((error == 0) || (newpgrp != NULL), | ||||
("setpgid failed and newpgrp is NULL")); | ("setpgid failed and newpgrp is NULL")); | ||||
if (newpgrp != NULL) | uma_zfree(pgrp_zone, newpgrp); | ||||
free(newpgrp, M_PGRP); | |||||
return (error); | return (error); | ||||
} | } | ||||
/* | /* | ||||
* Use the clause in B.4.2.2 that allows setuid/setgid to be 4.2/4.3BSD | * Use the clause in B.4.2.2 that allows setuid/setgid to be 4.2/4.3BSD | ||||
* compatible. It says that setting the uid/gid to euid/egid is a special | * compatible. It says that setting the uid/gid to euid/egid is a special | ||||
* case of "appropriate privilege". Once the rules are expanded out, this | * case of "appropriate privilege". Once the rules are expanded out, this | ||||
* basically means that setuid(nnn) sets all three id's, in all permitted | * basically means that setuid(nnn) sets all three id's, in all permitted | ||||
▲ Show 20 Lines • Show All 2,022 Lines • Show Last 20 Lines |