| 381 | #include "finsh.h" |
| 382 | |
| 383 | long list_session(void) |
| 384 | { |
| 385 | int count = 0, index; |
| 386 | rt_session_t *sessions; |
| 387 | rt_session_t session; |
| 388 | rt_thread_t thread; |
| 389 | char name[RT_NAME_MAX]; |
| 390 | |
| 391 | rt_kprintf("SID leader process\n"); |
| 392 | rt_kprintf("---- ----------------\n"); |
| 393 | |
| 394 | count = rt_object_get_length(RT_Object_Class_Session); |
| 395 | if (count > 0) |
| 396 | { |
| 397 | /* get pointers */ |
| 398 | sessions = (rt_session_t *)rt_calloc(count, sizeof(rt_session_t)); |
| 399 | if (sessions) |
| 400 | { |
| 401 | index = rt_object_get_pointers(RT_Object_Class_Session, (rt_object_t *)sessions, count); |
| 402 | if (index > 0) |
| 403 | { |
| 404 | for (index = 0; index < count; index++) |
| 405 | { |
| 406 | struct rt_session se; |
| 407 | session = sessions[index]; |
| 408 | SESS_LOCK(session); |
| 409 | rt_memcpy(&se, session, sizeof(struct rt_session)); |
| 410 | SESS_UNLOCK(session); |
| 411 | |
| 412 | if (se.leader && se.leader) |
| 413 | { |
| 414 | thread = rt_list_entry(se.leader->t_grp.prev, struct rt_thread, sibling); |
| 415 | rt_strncpy(name, thread->parent.name, RT_NAME_MAX); |
| 416 | } |
| 417 | else |
| 418 | { |
| 419 | rt_strncpy(name, "nil", RT_NAME_MAX); |
| 420 | } |
| 421 | |
| 422 | rt_kprintf("%4d %-*.*s\n", se.sid, RT_NAME_MAX, RT_NAME_MAX, name); |
| 423 | } |
| 424 | } |
| 425 | rt_free(sessions); |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | return 0; |
| 430 | } |
| 431 | MSH_CMD_EXPORT(list_session, list session); |
| 432 | #endif |
nothing calls this directly
no test coverage detected