aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2006-03-11 18:22:35 +0000
committerRob Landley <rob@landley.net>2006-03-11 18:22:35 +0000
commit1c60d9762e150ed9f3bd4584a639ff2d6996699c (patch)
tree8e669ca1b29672e01df57512a286416a380a430c
parent9e094552c8ca9f7e518a071f12eeafda81e2423b (diff)
downloadbusybox-w32-1c60d9762e150ed9f3bd4584a639ff2d6996699c.tar.gz
busybox-w32-1c60d9762e150ed9f3bd4584a639ff2d6996699c.tar.bz2
busybox-w32-1c60d9762e150ed9f3bd4584a639ff2d6996699c.zip
Size reduction by Tito.
-rw-r--r--coreutils/who.c29
1 files changed, 7 insertions, 22 deletions
diff --git a/coreutils/who.c b/coreutils/who.c
index 1156ba20f..2773e1a8b 100644
--- a/coreutils/who.c
+++ b/coreutils/who.c
@@ -14,14 +14,10 @@
14 *---------------------------------------------------------------------- 14 *----------------------------------------------------------------------
15 */ 15 */
16 16
17#include <sys/types.h> 17#include <stdio.h>
18#include <fcntl.h>
19#include <unistd.h>
20#include <stdlib.h> 18#include <stdlib.h>
21#include <utmp.h> 19#include <utmp.h>
22#include <sys/stat.h> 20#include <sys/stat.h>
23#include <errno.h>
24#include <string.h>
25#include <time.h> 21#include <time.h>
26#include "busybox.h" 22#include "busybox.h"
27 23
@@ -29,36 +25,24 @@ int who_main(int argc, char **argv)
29{ 25{
30 struct utmp *ut; 26 struct utmp *ut;
31 struct stat st; 27 struct stat st;
32 int devlen, len; 28 time_t idle;
33 time_t now, idle; 29 char *name;
34 30
35 if (argc > 1) 31 if (argc > 1)
36 bb_show_usage(); 32 bb_show_usage();
37 33
38 setutent(); 34 setutent();
39 devlen = sizeof("/dev/") - 1;
40 printf("USER TTY IDLE FROM HOST\n"); 35 printf("USER TTY IDLE FROM HOST\n");
41 36
42 while ((ut = getutent()) != NULL) { 37 while ((ut = getutent()) != NULL) {
43 char name[40];
44 38
45 if (ut->ut_user[0] && ut->ut_type == USER_PROCESS) { 39 if (ut->ut_user[0] && ut->ut_type == USER_PROCESS) {
46 len = strlen(ut->ut_line); 40 /* ut->ut_line is device name of tty - "/dev/" */
47 if (ut->ut_line[0] == '/') {
48 strncpy(name, ut->ut_line, len);
49 name[len] = '\0';
50 strcpy(ut->ut_line, ut->ut_line + devlen);
51 } else {
52 strcpy(name, "/dev/");
53 strncpy(name+devlen, ut->ut_line, len);
54 name[devlen+len] = '\0';
55 }
56
57 printf("%-10s %-8s ", ut->ut_user, ut->ut_line); 41 printf("%-10s %-8s ", ut->ut_user, ut->ut_line);
58 42
43 name = concat_path_file("/dev/", ut->ut_line);
59 if (stat(name, &st) == 0) { 44 if (stat(name, &st) == 0) {
60 now = time(NULL); 45 idle = time(NULL) - st.st_atime;
61 idle = now - st.st_atime;
62 46
63 if (idle < 60) 47 if (idle < 60)
64 printf("00:00m "); 48 printf("00:00m ");
@@ -75,6 +59,7 @@ int who_main(int argc, char **argv)
75 printf("%-8s ", "?"); 59 printf("%-8s ", "?");
76 60
77 printf("%-12.12s %s\n", ctime((time_t*)&(ut->ut_tv.tv_sec)) + 4, ut->ut_host); 61 printf("%-12.12s %s\n", ctime((time_t*)&(ut->ut_tv.tv_sec)) + 4, ut->ut_host);
62 free(name);
78 } 63 }
79 } 64 }
80 endutent(); 65 endutent();