10f66f451Sopenharmony_ci/* w.c - shows logged in users 20f66f451Sopenharmony_ci * 30f66f451Sopenharmony_ci * Copyright 2012 Gaurang Shastri <gmshastri@gmail.com> 40f66f451Sopenharmony_ci 50f66f451Sopenharmony_ciUSE_W(NEWTOY(w, NULL, TOYFLAG_USR|TOYFLAG_BIN)) 60f66f451Sopenharmony_ci 70f66f451Sopenharmony_ciconfig W 80f66f451Sopenharmony_ci bool "w" 90f66f451Sopenharmony_ci default y 100f66f451Sopenharmony_ci depends on TOYBOX_UTMPX 110f66f451Sopenharmony_ci help 120f66f451Sopenharmony_ci usage: w 130f66f451Sopenharmony_ci 140f66f451Sopenharmony_ci Show who is logged on and since how long they logged in. 150f66f451Sopenharmony_ci*/ 160f66f451Sopenharmony_ci 170f66f451Sopenharmony_ci#include "toys.h" 180f66f451Sopenharmony_ci 190f66f451Sopenharmony_civoid w_main(void) 200f66f451Sopenharmony_ci{ 210f66f451Sopenharmony_ci struct utmpx *x; 220f66f451Sopenharmony_ci 230f66f451Sopenharmony_ci xprintf("USER TTY LOGIN@ FROM"); 240f66f451Sopenharmony_ci setutxent(); 250f66f451Sopenharmony_ci while ((x=getutxent()) != NULL) { 260f66f451Sopenharmony_ci if (x->ut_type==7) { 270f66f451Sopenharmony_ci time_t tt = x->ut_tv.tv_sec; 280f66f451Sopenharmony_ci 290f66f451Sopenharmony_ci xprintf("\n%-9.8s%-9.8s %-4.24s (%-1.12s)", x->ut_user, x->ut_line, 300f66f451Sopenharmony_ci ctime(&tt), x->ut_host); 310f66f451Sopenharmony_ci } 320f66f451Sopenharmony_ci } 330f66f451Sopenharmony_ci xputc('\n'); 340f66f451Sopenharmony_ci} 35