MCPcopy Index your code
hub / github.com/RT-Thread/rt-thread / sys_setsid

Function sys_setsid

components/lwp/lwp_session.c:299–342  ·  view source on GitHub ↗

* setsid() creates a new session if the calling process is not a process group leader. * The calling process is the leader of the new session (i.e., its session ID is made the same as its process ID). * The calling process also becomes the process group leader of a new process group in the session * (i.e., its process group ID is made the same as its process ID). */

Source from the content-addressed store, hash-verified

297 * (i.e., its process group ID is made the same as its process ID).
298 */
299sysret_t sys_setsid(void)
300{
301 rt_lwp_t process;
302 pid_t pid;
303 rt_processgroup_t group;
304 rt_session_t session;
305 sysret_t err = 0;
306
307 process = lwp_self();
308 pid = lwp_to_pid(process);
309
310 /**
311 * if the calling process is already a process group leader.
312 */
313 if (lwp_pgrp_find(pid))
314 {
315 err = -EPERM;
316 goto exit;
317 }
318
319 group = lwp_pgrp_create(process);
320 if (group)
321 {
322 lwp_pgrp_move(group, process);
323 session = lwp_session_create(process);
324 if (session)
325 {
326 lwp_session_move(session, group);
327 }
328 else
329 {
330 lwp_pgrp_delete(group);
331 }
332 err = lwp_sid_get_bysession(session);
333 }
334 else
335 {
336 err = -ENOMEM;
337 }
338
339
340exit:
341 return err;
342}
343
344/**
345 * getsid() returns the session ID of the process with process ID pid.

Callers

nothing calls this directly

Calls 9

lwp_selfFunction · 0.85
lwp_to_pidFunction · 0.85
lwp_pgrp_findFunction · 0.85
lwp_pgrp_createFunction · 0.85
lwp_pgrp_moveFunction · 0.85
lwp_session_createFunction · 0.85
lwp_session_moveFunction · 0.85
lwp_pgrp_deleteFunction · 0.85
lwp_sid_get_bysessionFunction · 0.85

Tested by

no test coverage detected