* getsid() returns the session ID of the process with process ID pid. * If pid is 0, getsid() returns the session ID of the calling process. */
| 346 | * If pid is 0, getsid() returns the session ID of the calling process. |
| 347 | */ |
| 348 | sysret_t sys_getsid(pid_t pid) |
| 349 | { |
| 350 | rt_lwp_t process, self_process; |
| 351 | pid_t sid; |
| 352 | |
| 353 | lwp_pid_lock_take(); |
| 354 | process = lwp_from_pid_locked(pid); |
| 355 | lwp_pid_lock_release(); |
| 356 | |
| 357 | if (process == RT_NULL) |
| 358 | { |
| 359 | return -ESRCH; |
| 360 | } |
| 361 | |
| 362 | self_process = lwp_self(); |
| 363 | sid = lwp_sid_get_byprocess(process); |
| 364 | |
| 365 | if (sid != lwp_sid_get_byprocess(self_process)) |
| 366 | { |
| 367 | /** |
| 368 | * A process with process ID pid exists, but it is not in the same session as the calling process, |
| 369 | * and the implementation considers this an error. |
| 370 | * |
| 371 | * Note: Linux does not return EPERM. |
| 372 | */ |
| 373 | return -EPERM; |
| 374 | } |
| 375 | |
| 376 | return sid; |
| 377 | } |
| 378 | |
| 379 | #ifdef RT_USING_FINSH |
| 380 |
nothing calls this directly
no test coverage detected