static inline bool desirable_utmp_entry (STRUCT_UTMP const *u, int options) { return ! (options & READ_UTMP_CHECK_PIDS && IS_USER_PROCESS (u) && (UT_PID (u) <= 0 || (kill (UT_PID (u), 0) < 0 && errno == ESRCH))); }
static inline bool desirable_utmp_entry (STRUCT_UTMP const *u, int options) { bool user_proc = IS_USER_PROCESS (u); if ((options & READ_UTMP_USER_PROCESS) && !user_proc) return false; if ((options & READ_UTMP_CHECK_PIDS) && user_proc && (UT_PID (u) <= 0 || (kill (UT_PID (u), 0) < 0 && errno == ESRCH))) return false; return true; }
void wtmpxrawdump (const char *wtmpfile, const char *user) { STRUCT_UTMP *utp; struct in_addr addr; char *addr_string, *time_string; if (access (wtmpfile, R_OK)) die (errno, "cannot access the file"); /* Ignore the return value for now. Solaris' utmpname returns 1 upon success -- which is contrary to what the GNU libc version does. In addition, older GNU libc versions are actually void. */ UTMP_NAME_FUNCTION (wtmpfile); SET_UTMP_ENT (); while ((utp = GET_UTMP_ENT ()) != NULL) { if (user && strncmp (UT_USER (utp), user, sizeof (UT_USER (utp)))) continue; /* FIXME: missing support for IPv6 */ #ifdef HAVE_UTP_UT_ADDR_V6 addr.s_addr = utp->ut_addr_v6[0]; #endif addr_string = inet_ntoa (addr); time_string = timetostr (UT_TIME_MEMBER (utp)); switch (utp->ut_type) { default: /* Note: also catch EMPTY/UT_UNKNOWN values */ printf ("%-9s", "NONE"); break; #ifdef RUN_LVL /* Undefined on AIX if _ALL_SOURCE is false */ case RUN_LVL: printf ("%-9s", "RUNLEVEL"); break; #endif case BOOT_TIME: printf ("%-9s", "REBOOT"); break; case OLD_TIME: case NEW_TIME: /* FIXME */ break; case INIT_PROCESS: printf ("%-9s", "INIT"); break; case LOGIN_PROCESS: printf ("%-9s", "LOGIN"); break; case USER_PROCESS: printf ("%-9.*s", sizeof (UT_USER (utp)), UT_USER (utp)); break; case DEAD_PROCESS: printf ("%-9s", "DEAD"); break; #ifdef ACCOUNTING /* Undefined on AIX if _ALL_SOURCE is false */ case ACCOUNTING: printf ("%-9s", "ACCOUNT"); break; #endif } /* pid */ UT_PID (utp) ? printf ("[%05d]", UT_PID (utp)) : printf ("[%5s]", "-"); /* line id host addr date&time */ printf (" [%-12.*s] [%-4.*s] [%-19.*s] [%-15.15s] [%-19.19s]\n", sizeof (utp->ut_line), utp->ut_line, sizeof (utp->ut_id), utp->ut_id, sizeof (utp->ut_host), utp->ut_host, addr_string, time_string); } END_UTMP_ENT (); }