MCPcopy Create free account
hub / github.com/coreutils/coreutils / scan_entries

Function scan_entries

src/who.c:554–601  ·  view source on GitHub ↗

Display UTMP_BUF, which should have N entries. */

Source from the content-addressed store, hash-verified

552
553/* Display UTMP_BUF, which should have N entries. */
554static void
555scan_entries (idx_t n, STRUCT_UTMP const *utmp_buf)
556{
557 char *ttyname_b IF_LINT ( = NULL);
558 time_t boottime = TYPE_MINIMUM (time_t);
559
560 if (include_heading)
561 print_heading ();
562
563 if (my_line_only)
564 {
565 ttyname_b = ttyname (STDIN_FILENO);
566 if (!ttyname_b)
567 return;
568 if (STRNCMP_LIT (ttyname_b, "/dev/") == 0)
569 ttyname_b += sizeof "/dev/" - 1; /* Discard /dev/ prefix. */
570 }
571
572 while (n--)
573 {
574 if (!my_line_only
575 || str_endswith (utmp_buf->ut_line, ttyname_b))
576 {
577 if (need_users && IS_USER_PROCESS (utmp_buf))
578 print_user (utmp_buf, boottime);
579 else if (need_runlevel && UT_TYPE_RUN_LVL (utmp_buf))
580 print_runlevel (utmp_buf);
581 else if (need_boottime && UT_TYPE_BOOT_TIME (utmp_buf))
582 print_boottime (utmp_buf);
583 /* I've never seen one of these, so I don't know what it should
584 look like :^)
585 FIXME: handle OLD_TIME also, perhaps show the delta? */
586 else if (need_clockchange && UT_TYPE_NEW_TIME (utmp_buf))
587 print_clockchange (utmp_buf);
588 else if (need_initspawn && UT_TYPE_INIT_PROCESS (utmp_buf))
589 print_initspawn (utmp_buf);
590 else if (need_login && UT_TYPE_LOGIN_PROCESS (utmp_buf))
591 print_login (utmp_buf);
592 else if (need_deadprocs && UT_TYPE_DEAD_PROCESS (utmp_buf))
593 print_deadprocs (utmp_buf);
594 }
595
596 if (UT_TYPE_BOOT_TIME (utmp_buf))
597 boottime = utmp_buf->ut_ts.tv_sec;
598
599 utmp_buf++;
600 }
601}
602
603/* Display a list of who is on the system, according to utmp file FILENAME.
604 Use read_utmp OPTIONS to read the file. */

Callers 1

whoFunction · 0.70

Calls 8

print_runlevelFunction · 0.85
print_boottimeFunction · 0.85
print_clockchangeFunction · 0.85
print_initspawnFunction · 0.85
print_loginFunction · 0.85
print_deadprocsFunction · 0.85
print_headingFunction · 0.70
print_userFunction · 0.70

Tested by

no test coverage detected