ARGSUSED */
| 322 | #endif |
| 323 | /* ARGSUSED */ |
| 324 | int |
| 325 | sys_setsid(struct thread *td, struct setsid_args *uap) |
| 326 | { |
| 327 | struct pgrp *pgrp; |
| 328 | int error; |
| 329 | struct proc *p = td->td_proc; |
| 330 | struct pgrp *newpgrp; |
| 331 | struct session *newsess; |
| 332 | |
| 333 | error = 0; |
| 334 | pgrp = NULL; |
| 335 | |
| 336 | newpgrp = uma_zalloc(pgrp_zone, M_WAITOK); |
| 337 | newsess = malloc(sizeof(struct session), M_SESSION, M_WAITOK | M_ZERO); |
| 338 | |
| 339 | sx_xlock(&proctree_lock); |
| 340 | |
| 341 | if (p->p_pgid == p->p_pid || (pgrp = pgfind(p->p_pid)) != NULL) { |
| 342 | if (pgrp != NULL) |
| 343 | PGRP_UNLOCK(pgrp); |
| 344 | error = EPERM; |
| 345 | } else { |
| 346 | (void)enterpgrp(p, p->p_pid, newpgrp, newsess); |
| 347 | td->td_retval[0] = p->p_pid; |
| 348 | newpgrp = NULL; |
| 349 | newsess = NULL; |
| 350 | } |
| 351 | |
| 352 | sx_xunlock(&proctree_lock); |
| 353 | |
| 354 | uma_zfree(pgrp_zone, newpgrp); |
| 355 | free(newsess, M_SESSION); |
| 356 | |
| 357 | return (error); |
| 358 | } |
| 359 | |
| 360 | /* |
| 361 | * set process group (setpgid/old setpgrp) |