view toys/other/w.c @ 1775:57f2a26fa92c draft toast

To ensure that toybox can be installed alongside busybox without confusing update-alternatives, the paths of the links installed by toybox should match those installed by busybox. This is accomplished by changing the flags of a few tools within toybox.
author Paul Barker <paul@paulbarker.me.uk>
date Sat, 04 Apr 2015 11:58:06 -0500
parents 685a0da6ca59
children
line wrap: on
line source

/* w.c - shows logged in users
 *
 * Copyright 2012 Gaurang Shastri <gmshastri@gmail.com>

USE_W(NEWTOY(w, NULL, TOYFLAG_USR|TOYFLAG_BIN))

config W
  bool "w"
  default y
  depends on TOYBOX_UTMPX
  help
    usage: w

    Show who is logged on and since how long they logged in.
*/

#include "toys.h"

void w_main(void)
{
  struct utmpx *x;

  xprintf("USER     TTY             LOGIN@              FROM");
  setutxent();
  while ((x=getutxent()) != NULL) {
    if (x->ut_type==7) {
      time_t tt = x->ut_tv.tv_sec;

      xprintf("\n%-9.8s%-9.8s %-4.24s (%-1.12s)", x->ut_user, x->ut_line,
        ctime(&tt), x->ut_host);
    }
  }
  xputc('\n');
}