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

Function print_user

src/who.c:311–423  ·  view source on GitHub ↗

Send properly parsed USER_PROCESS info to print_line. The most recent boot time is BOOTTIME. */

Source from the content-addressed store, hash-verified

309/* Send properly parsed USER_PROCESS info to print_line. The most
310 recent boot time is BOOTTIME. */
311static void
312print_user (STRUCT_UTMP const *utmp_ent, time_t boottime)
313{
314 struct stat stats;
315 time_t last_change;
316 char mesg;
317 char idlestr[IDLESTR_LEN + 1];
318 PIDSTR_DECL_AND_INIT (pidstr, utmp_ent);
319 static char *hoststr;
320#if HAVE_STRUCT_XTMP_UT_HOST
321 static idx_t hostlen;
322#endif
323
324 /* If ut_line contains a space, the device name starts after the space. */
325 char *line = utmp_ent->ut_line;
326 char *space = strchr (line, ' ');
327 line = space ? space + 1 : line;
328
329 int dirfd;
330 if (IS_ABSOLUTE_FILE_NAME (line))
331 dirfd = AT_FDCWD;
332 else
333 {
334 static int dev_dirfd;
335 if (!dev_dirfd)
336 {
337 dev_dirfd = open ("/dev", O_PATHSEARCH | O_DIRECTORY);
338 if (dev_dirfd < 0)
339 dev_dirfd = AT_FDCWD - 1;
340 }
341 dirfd = dev_dirfd;
342 }
343
344 if (AT_FDCWD <= dirfd && fstatat (dirfd, line, &stats, 0) == 0)
345 {
346 mesg = is_tty_writable (&stats) ? '+' : '-';
347 last_change = stats.st_atime;
348 }
349 else
350 {
351 mesg = '?';
352 last_change = 0;
353 }
354
355 if (last_change)
356 sprintf (idlestr, "%.*s", IDLESTR_LEN, idle_string (last_change, boottime));
357 else
358 sprintf (idlestr, " ?");
359
360#if HAVE_STRUCT_XTMP_UT_HOST
361 if (utmp_ent->ut_host[0])
362 {
363 char *host = NULL;
364 char *display = NULL;
365 char *ut_host = utmp_ent->ut_host;
366
367 /* Look for an X display. */
368 display = strchr (ut_host, ':');

Callers 1

scan_entriesFunction · 0.70

Calls 4

is_tty_writableFunction · 0.85
idle_stringFunction · 0.70
print_lineFunction · 0.70
time_stringFunction · 0.70

Tested by

no test coverage detected