Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/coreutils/who.c


Ignore:
Timestamp:
Jan 1, 2014, 12:47:38 AM (10 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.21.1
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mindi-busybox/coreutils/who.c

    r2725 r3232  
    1919/* BB_AUDIT SUSv3 _NOT_ compliant -- missing options -b, -d, -l, -m, -p, -q, -r, -s, -t, -T, -u; Missing argument 'file'.  */
    2020
     21//config:config WHO
     22//config:      bool "who"
     23//config:      default y
     24//config:      depends on FEATURE_UTMP
     25//config:      help
     26//config:        who is used to show who is logged on.
     27
     28//config:config USERS
     29//config:      bool "users"
     30//config:      default y
     31//config:      depends on FEATURE_UTMP
     32//config:      help
     33//config:        Print users currently logged on.
     34
     35//applet:IF_USERS(APPLET_ODDNAME(users, who, BB_DIR_USR_BIN, BB_SUID_DROP, users))
     36//applet:IF_WHO(  APPLET(  who, BB_DIR_USR_BIN, BB_SUID_DROP))
     37
     38//kbuild:lib-$(CONFIG_USERS) += who.o
     39//kbuild:lib-$(CONFIG_WHO) += who.o
     40
     41//usage:#define users_trivial_usage
     42//usage:       ""
     43//usage:#define users_full_usage "\n\n"
     44//usage:       "Print the users currently logged on"
     45
     46//usage:#define who_trivial_usage
     47//usage:       "[-a]"
     48//usage:#define who_full_usage "\n\n"
     49//usage:       "Show who is logged on\n"
     50//usage:     "\n    -a  Show all"
     51//usage:     "\n    -H  Print column headers"
     52
    2153#include "libbb.h"
    22 #include <utmp.h>
    2354
    2455static void idle_string(char *str6, time_t t)
     
    4576    struct utmp *ut;
    4677    unsigned opt;
     78    int do_users = (ENABLE_USERS && (!ENABLE_WHO || applet_name[0] == 'u'));
     79    const char *fmt = "%s";
    4780
    4881    opt_complementary = "=0";
    49     opt = getopt32(argv, "aH");
     82    opt = getopt32(argv, do_users ? "" : "aH");
    5083    if (opt & 2) // -H
    5184        printf("USER\t\tTTY\t\tIDLE\tTIME\t\t HOST\n");
     
    5689         && ((opt & 1) || ut->ut_type == USER_PROCESS)
    5790        ) {
    58             char str6[6];
    59             char name[sizeof("/dev/") + sizeof(ut->ut_line) + 1];
    60             struct stat st;
    61             time_t seconds;
     91            if (!do_users) {
     92                char str6[6];
     93                char name[sizeof("/dev/") + sizeof(ut->ut_line) + 1];
     94                struct stat st;
     95                time_t seconds;
    6296
    63             str6[0] = '?';
    64             str6[1] = '\0';
    65             strcpy(name, "/dev/");
    66             safe_strncpy(ut->ut_line[0] == '/' ? name : name + sizeof("/dev/")-1,
    67                 ut->ut_line,
    68                 sizeof(ut->ut_line)+1
    69             );
    70             if (stat(name, &st) == 0)
    71                 idle_string(str6, st.st_atime);
    72             /* manpages say ut_tv.tv_sec *is* time_t,
    73              * but some systems have it wrong */
    74             seconds = ut->ut_tv.tv_sec;
    75             /* How wide time field can be?
    76              * "Nov 10 19:33:20": 15 chars
    77              * "2010-11-10 19:33": 16 chars
    78              */
    79             printf("%-15.*s %-15.*s %-7s %-16.16s %.*s\n",
    80                     (int)sizeof(ut->ut_user), ut->ut_user,
    81                     (int)sizeof(ut->ut_line), ut->ut_line,
    82                     str6,
    83                     ctime(&seconds) + 4,
    84                     (int)sizeof(ut->ut_host), ut->ut_host
    85             );
     97                str6[0] = '?';
     98                str6[1] = '\0';
     99                strcpy(name, "/dev/");
     100                safe_strncpy(ut->ut_line[0] == '/' ? name : name + sizeof("/dev/")-1,
     101                    ut->ut_line,
     102                    sizeof(ut->ut_line)+1
     103                );
     104                if (stat(name, &st) == 0)
     105                    idle_string(str6, st.st_atime);
     106                /* manpages say ut_tv.tv_sec *is* time_t,
     107                 * but some systems have it wrong */
     108                seconds = ut->ut_tv.tv_sec;
     109                /* How wide time field can be?
     110                 * "Nov 10 19:33:20": 15 chars
     111                 * "2010-11-10 19:33": 16 chars
     112                 */
     113                printf("%-15.*s %-15.*s %-7s %-16.16s %.*s\n",
     114                        (int)sizeof(ut->ut_user), ut->ut_user,
     115                        (int)sizeof(ut->ut_line), ut->ut_line,
     116                        str6,
     117                        ctime(&seconds) + 4,
     118                        (int)sizeof(ut->ut_host), ut->ut_host
     119                );
     120            } else {
     121                printf(fmt, ut->ut_user);
     122                fmt = " %s";
     123            }
    86124        }
    87125    }
     126    if (do_users)
     127        bb_putchar('\n');
    88128    if (ENABLE_FEATURE_CLEAN_UP)
    89129        endutent();
Note: See TracChangeset for help on using the changeset viewer.