ARGSUSED */
| 378 | #endif |
| 379 | /* ARGSUSED */ |
| 380 | int |
| 381 | sys_setpgid(struct thread *td, struct setpgid_args *uap) |
| 382 | { |
| 383 | struct proc *curp = td->td_proc; |
| 384 | struct proc *targp; /* target process */ |
| 385 | struct pgrp *pgrp; /* target pgrp */ |
| 386 | int error; |
| 387 | struct pgrp *newpgrp; |
| 388 | |
| 389 | if (uap->pgid < 0) |
| 390 | return (EINVAL); |
| 391 | |
| 392 | error = 0; |
| 393 | |
| 394 | newpgrp = uma_zalloc(pgrp_zone, M_WAITOK); |
| 395 | |
| 396 | sx_xlock(&proctree_lock); |
| 397 | if (uap->pid != 0 && uap->pid != curp->p_pid) { |
| 398 | if ((targp = pfind(uap->pid)) == NULL) { |
| 399 | error = ESRCH; |
| 400 | goto done; |
| 401 | } |
| 402 | if (!inferior(targp)) { |
| 403 | PROC_UNLOCK(targp); |
| 404 | error = ESRCH; |
| 405 | goto done; |
| 406 | } |
| 407 | if ((error = p_cansee(td, targp))) { |
| 408 | PROC_UNLOCK(targp); |
| 409 | goto done; |
| 410 | } |
| 411 | if (targp->p_pgrp == NULL || |
| 412 | targp->p_session != curp->p_session) { |
| 413 | PROC_UNLOCK(targp); |
| 414 | error = EPERM; |
| 415 | goto done; |
| 416 | } |
| 417 | if (targp->p_flag & P_EXEC) { |
| 418 | PROC_UNLOCK(targp); |
| 419 | error = EACCES; |
| 420 | goto done; |
| 421 | } |
| 422 | PROC_UNLOCK(targp); |
| 423 | } else |
| 424 | targp = curp; |
| 425 | if (SESS_LEADER(targp)) { |
| 426 | error = EPERM; |
| 427 | goto done; |
| 428 | } |
| 429 | if (uap->pgid == 0) |
| 430 | uap->pgid = targp->p_pid; |
| 431 | if ((pgrp = pgfind(uap->pgid)) == NULL) { |
| 432 | if (uap->pgid == targp->p_pid) { |
| 433 | error = enterpgrp(targp, uap->pgid, newpgrp, |
| 434 | NULL); |
| 435 | if (error == 0) |
| 436 | newpgrp = NULL; |
| 437 | } else |
nothing calls this directly
no test coverage detected