Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/coreutils/who.c


Ignore:
Timestamp:
Feb 25, 2011, 9:26:54 PM (13 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File:
1 edited

Legend:

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

    r1765 r2725  
    1313 * Copyright (c) 2002 AYR Networks, Inc.
    1414 *
    15  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
     15 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    1616 *
    1717 *----------------------------------------------------------------------
    1818 */
     19/* BB_AUDIT SUSv3 _NOT_ compliant -- missing options -b, -d, -l, -m, -p, -q, -r, -s, -t, -T, -u; Missing argument 'file'.  */
    1920
    2021#include "libbb.h"
    2122#include <utmp.h>
    22 #include <time.h>
    2323
    2424static void idle_string(char *str6, time_t t)
     
    4040}
    4141
    42 int who_main(int argc, char **argv);
    43 int who_main(int argc, char **argv)
     42int who_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     43int who_main(int argc UNUSED_PARAM, char **argv)
    4444{
    45     char str6[6];
    4645    struct utmp *ut;
    47     struct stat st;
    48     char *name;
     46    unsigned opt;
    4947
    50     if (argc > 1) {
    51         bb_show_usage();
    52     }
     48    opt_complementary = "=0";
     49    opt = getopt32(argv, "aH");
     50    if (opt & 2) // -H
     51        printf("USER\t\tTTY\t\tIDLE\tTIME\t\t HOST\n");
    5352
    5453    setutent();
    55     printf("USER       TTY      IDLE      TIME           HOST\n");
    5654    while ((ut = getutent()) != NULL) {
    57         if (ut->ut_user[0] && ut->ut_type == USER_PROCESS) {
    58             time_t thyme = ut->ut_tv.tv_sec;
     55        if (ut->ut_user[0]
     56         && ((opt & 1) || ut->ut_type == USER_PROCESS)
     57        ) {
     58            char str6[6];
     59            char name[sizeof("/dev/") + sizeof(ut->ut_line) + 1];
     60            struct stat st;
     61            time_t seconds;
    5962
    60             /* ut->ut_line is device name of tty - "/dev/" */
    61             name = concat_path_file("/dev", ut->ut_line);
    6263            str6[0] = '?';
    6364            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            );
    6470            if (stat(name, &st) == 0)
    6571                idle_string(str6, st.st_atime);
    66             printf("%-10s %-8s %-9s %-14.14s %s\n",
    67                     ut->ut_user, ut->ut_line, str6,
    68                     ctime(&thyme) + 4, ut->ut_host);
    69             if (ENABLE_FEATURE_CLEAN_UP)
    70                 free(name);
     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            );
    7186        }
    7287    }
    7388    if (ENABLE_FEATURE_CLEAN_UP)
    7489        endutent();
    75     return 0;
     90    return EXIT_SUCCESS;
    7691}
Note: See TracChangeset for help on using the changeset viewer.