view toys/posix/who.c @ 1564:685a0da6ca59 draft

probe for getspnam(), forkpty(), utmpx, replace sethostname() Android is missing all of these; we need to probe for some so we have a config symbol to depend on. sethostname() is easily replaced. We got termios.h via pty.h; now it's not included in configure-step tools, so we need termios.h to generate globals.
author Isaac Dunham <>
date Wed, 19 Nov 2014 16:38:46 -0600
parents 53f165466f3b
children 57f2a26fa92c
line wrap: on
line source

/* who.c - display who is on the system
 * Copyright 2012 ProFUSION Embedded Systems
 * by Luis Felipe Strano Moraes <>
 * See
 * Posix says to support many options (-abdHlmpqrstTu) but this
 * isn't aimed at minicomputers with modem pools.


config WHO
  bool "who"
  default y
  depends on TOYBOX_UTMPX
    usage: who

    Print logged user information on system

#define FOR_who
#include "toys.h"

void who_main(void)
  struct utmpx *entry;


  while ((entry = getutxent())) {
    if ((toys.optflags & FLAG_a) || entry->ut_type == USER_PROCESS) {
      time_t time;
      int time_size;
      char *times;

      time = entry->ut_tv.tv_sec;
      times = ctime(&time);
      time_size = strlen(times) - 2;
      printf("%s\t%s\t%*.*s\t(%s)\n", entry->ut_user, entry->ut_line,
        time_size, time_size, ctime(&time), entry->ut_host);