* 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). */
| 297 | * (i.e., its process group ID is made the same as its process ID). |
| 298 | */ |
| 299 | sysret_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 | |
| 340 | exit: |
| 341 | return err; |
| 342 | } |
| 343 | |
| 344 | /** |
| 345 | * getsid() returns the session ID of the process with process ID pid. |
nothing calls this directly
no test coverage detected