Ignore:
Timestamp:
Jan 1, 2014, 12:47:38 AM (7 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/procps/uptime.c

    r2725 r3232  
    88 */
    99
    10 /* This version of uptime doesn't display the number of users on the system,
    11  * since busybox init doesn't mess with utmp.  For folks using utmp that are
    12  * just dying to have # of users reported, feel free to write it as some type
    13  * of CONFIG_FEATURE_UTMP_SUPPORT #define
     10/* 2011     Pere Orga <gotrunks@gmail.com>
     11 *
     12 * Added FEATURE_UPTIME_UTMP_SUPPORT flag.
    1413 */
    1514
    1615/* getopt not needed */
    1716
     17//config:config UPTIME
     18//config:   bool "uptime"
     19//config:   default y
     20//config:   select PLATFORM_LINUX #sysinfo()
     21//config:   help
     22//config:     uptime gives a one line display of the current time, how long
     23//config:     the system has been running, how many users are currently logged
     24//config:     on, and the system load averages for the past 1, 5, and 15 minutes.
     25//config:
     26//config:config FEATURE_UPTIME_UTMP_SUPPORT
     27//config:   bool "Support for showing the number of users"
     28//config:   default y
     29//config:   depends on UPTIME && FEATURE_UTMP
     30//config:   help
     31//config:     Makes uptime display the number of users currently logged on.
     32
     33//usage:#define uptime_trivial_usage
     34//usage:       ""
     35//usage:#define uptime_full_usage "\n\n"
     36//usage:       "Display the time since the last boot"
     37//usage:
     38//usage:#define uptime_example_usage
     39//usage:       "$ uptime\n"
     40//usage:       "  1:55pm  up  2:30, load average: 0.09, 0.04, 0.00\n"
     41
    1842#include "libbb.h"
     43#ifdef __linux__
     44# include <sys/sysinfo.h>
     45#endif
     46
    1947
    2048#ifndef FSHIFT
    2149# define FSHIFT 16              /* nr of bits of precision */
    2250#endif
    23 #define FIXED_1         (1<<FSHIFT)     /* 1.0 as fixed-point */
    24 #define LOAD_INT(x) ((x) >> FSHIFT)
    25 #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
     51#define FIXED_1      (1 << FSHIFT)     /* 1.0 as fixed-point */
     52#define LOAD_INT(x)  (unsigned)((x) >> FSHIFT)
     53#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
    2654
    2755
     
    2957int uptime_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
    3058{
    31     int updays, uphours, upminutes;
     59    unsigned updays, uphours, upminutes;
    3260    struct sysinfo info;
    3361    struct tm *current_time;
     
    3967    sysinfo(&info);
    4068
    41     printf(" %02d:%02d:%02d up ",
     69    printf(" %02u:%02u:%02u up ",
    4270            current_time->tm_hour, current_time->tm_min, current_time->tm_sec);
    43     updays = (int) info.uptime / (60*60*24);
     71    updays = (unsigned) info.uptime / (unsigned)(60*60*24);
    4472    if (updays)
    45         printf("%d day%s, ", updays, (updays != 1) ? "s" : "");
    46     upminutes = (int) info.uptime / 60;
    47     uphours = (upminutes / 60) % 24;
     73        printf("%u day%s, ", updays, (updays != 1) ? "s" : "");
     74    upminutes = (unsigned) info.uptime / (unsigned)60;
     75    uphours = (upminutes / (unsigned)60) % (unsigned)24;
    4876    upminutes %= 60;
    4977    if (uphours)
    50         printf("%2d:%02d, ", uphours, upminutes);
     78        printf("%2u:%02u", uphours, upminutes);
    5179    else
    52         printf("%d min, ", upminutes);
     80        printf("%u min", upminutes);
    5381
    54     printf("load average: %ld.%02ld, %ld.%02ld, %ld.%02ld\n",
     82#if ENABLE_FEATURE_UPTIME_UTMP_SUPPORT
     83    {
     84        struct utmp *ut;
     85        unsigned users = 0;
     86        while ((ut = getutent()) != NULL) {
     87            if ((ut->ut_type == USER_PROCESS) && (ut->ut_name[0] != '\0'))
     88                users++;
     89        }
     90        printf(",  %u users", users);
     91    }
     92#endif
     93
     94    printf(",  load average: %u.%02u, %u.%02u, %u.%02u\n",
    5595            LOAD_INT(info.loads[0]), LOAD_FRAC(info.loads[0]),
    5696            LOAD_INT(info.loads[1]), LOAD_FRAC(info.loads[1]),
Note: See TracChangeset for help on using the changeset viewer.