MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / sys_setpgid

Function sys_setpgid

components/lwp/lwp_pgrp.c:323–478  ·  view source on GitHub ↗

* setpgid() sets the PGID of the process specified by pid to pgid. * If pid is zero, then the process ID of the calling process is used. * If pgid is zero, then the PGID of the process specified by pid is made the same as its process ID. * If setpgid() is used to move a process from one process group to another (as is done by some shells when * creating pipelines), both process groups

Source from the content-addressed store, hash-verified

321 * match the session ID of the joining process.
322 */
323sysret_t sys_setpgid(pid_t pid, pid_t pgid)
324{
325 rt_lwp_t process, self_process;
326 pid_t sid;
327 rt_processgroup_t group;
328 rt_session_t session;
329 sysret_t err = 0;
330
331 if (pgid == 0)
332 {
333 pgid = pid;
334 }
335 if (pgid < 0)
336 {
337 return -EINVAL;
338 }
339
340 self_process = lwp_self();
341
342 if (pid == 0)
343 {
344 pid = self_process->pid;
345 process = self_process;
346 }
347 else
348 {
349 lwp_pid_lock_take();
350 process = lwp_from_pid_locked(pid);
351 lwp_pid_lock_release();
352
353 if (process == RT_NULL)
354 {
355 return -ESRCH;
356 }
357 }
358
359 LWP_LOCK(process);
360
361 if (process->parent == self_process)
362 {
363 /**
364 * change the process group ID of one of the children of the calling process and the child was in
365 * a different session
366 */
367 if (lwp_sid_get_byprocess(process) != lwp_sid_get_byprocess(self_process))
368 {
369 err = -EPERM;
370 LWP_UNLOCK(process);
371 goto exit;
372 }
373 /**
374 * An attempt was made to change the process group ID of one of the children of the calling process
375 * and the child had already performed an execve(2)
376 */
377 if (process->did_exec)
378 {
379 err = -EACCES;
380 LWP_UNLOCK(process);

Callers

nothing calls this directly

Calls 13

lwp_selfFunction · 0.85
lwp_pid_lock_takeFunction · 0.85
lwp_from_pid_lockedFunction · 0.85
lwp_pid_lock_releaseFunction · 0.85
lwp_sid_get_byprocessFunction · 0.85
lwp_pgrp_findFunction · 0.85
lwp_pgrp_createFunction · 0.85
lwp_pgrp_moveFunction · 0.85
lwp_session_findFunction · 0.85
lwp_session_insertFunction · 0.85
lwp_sid_get_bypgrpFunction · 0.85
lwp_to_pidFunction · 0.85

Tested by

no test coverage detected