Send properly parsed USER_PROCESS info to print_line. The most recent boot time is BOOTTIME. */
| 309 | /* Send properly parsed USER_PROCESS info to print_line. The most |
| 310 | recent boot time is BOOTTIME. */ |
| 311 | static void |
| 312 | print_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, ':'); |
no test coverage detected