Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/procps


Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (8 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
3 added
15 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/procps/free.c

    r3232 r3621  
    2323
    2424#include "libbb.h"
     25#include "common_bufsiz.h"
    2526#ifdef __linux__
    2627# include <sys/sysinfo.h>
     
    3637#endif
    3738} FIX_ALIASING;
    38 #define G (*(struct globals*)&bb_common_bufsiz1)
    39 #define INIT_G() do { } while (0)
     39#define G (*(struct globals*)bb_common_bufsiz1)
     40#define INIT_G() do { setup_common_bufsiz(); } while (0)
    4041
    4142
     
    4546}
    4647
     48static unsigned long parse_cached_kb(void)
     49{
     50    char buf[60]; /* actual lines we expect are ~30 chars or less */
     51    FILE *fp;
     52    unsigned long cached = 0;
     53
     54    fp = xfopen_for_read("/proc/meminfo");
     55    while (fgets(buf, sizeof(buf), fp) != NULL) {
     56        if (sscanf(buf, "Cached: %lu %*s\n", &cached) == 1)
     57            break;
     58    }
     59    if (ENABLE_FEATURE_CLEAN_UP)
     60        fclose(fp);
     61
     62    return cached;
     63}
    4764
    4865int free_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     
    5067{
    5168    struct sysinfo info;
     69    unsigned long long cached;
    5270
    5371    INIT_G();
     
    7492    }
    7593#endif
    76 
    77     sysinfo(&info);
    78 
    79     /* Kernels prior to 2.4.x will return info.mem_unit==0, so cope... */
    80     G.mem_unit = (info.mem_unit ? info.mem_unit : 1);
    81 
    82     printf("     %13s%13s%13s%13s%13s\n",
     94    printf("       %11s%11s%11s%11s%11s%11s\n"
     95    "Mem:   ",
    8396        "total",
    8497        "used",
    8598        "free",
    86         "shared", "buffers" /* swap and total don't have these columns */
    87         /* procps version 3.2.8 also shows "cached" column, but
    88          * sysinfo() does not provide this value, need to parse
    89          * /proc/meminfo instead and get "Cached: NNN kB" from there.
    90          */
     99        "shared", "buffers", "cached" /* swap and total don't have these columns */
    91100    );
    92101
    93 #define FIELDS_5 "%13llu%13llu%13llu%13llu%13llu\n"
    94 #define FIELDS_3 (FIELDS_5 + 2*6)
    95 #define FIELDS_2 (FIELDS_5 + 3*6)
     102    sysinfo(&info);
     103    /* Kernels prior to 2.4.x will return info.mem_unit==0, so cope... */
     104    G.mem_unit = (info.mem_unit ? info.mem_unit : 1);
     105    /* Extract cached from /proc/meminfo and convert to mem_units */
     106    cached = ((unsigned long long) parse_cached_kb() * 1024) / G.mem_unit;
    96107
    97     printf("Mem: ");
    98     printf(FIELDS_5,
    99         scale(info.totalram),
    100         scale(info.totalram - info.freeram),
    101         scale(info.freeram),
    102         scale(info.sharedram),
    103         scale(info.bufferram)
     108#define FIELDS_6 "%11llu%11llu%11llu%11llu%11llu%11llu\n"
     109#define FIELDS_3 (FIELDS_6 + 3*6)
     110#define FIELDS_2 (FIELDS_6 + 4*6)
     111
     112    printf(FIELDS_6,
     113        scale(info.totalram),                //total
     114        scale(info.totalram - info.freeram), //used
     115        scale(info.freeram),                 //free
     116        scale(info.sharedram),               //shared
     117        scale(info.bufferram),               //buffers
     118        scale(cached)                        //cached
    104119    );
    105120    /* Show alternate, more meaningful busy/free numbers by counting
    106      * buffer cache as free memory (make it "-/+ buffers/cache"
    107      * if/when we add support for "cached" column): */
    108     printf("-/+ buffers:      ");
     121     * buffer cache as free memory. */
     122    printf("-/+ buffers/cache:");
     123    cached += info.freeram;
     124    cached += info.bufferram;
    109125    printf(FIELDS_2,
    110         scale(info.totalram - info.freeram - info.bufferram),
    111         scale(info.freeram + info.bufferram)
     126        scale(info.totalram - cached), //used
     127        scale(cached)                  //free
    112128    );
    113129#if BB_MMU
    114     printf("Swap:");
     130    printf("Swap:  ");
    115131    printf(FIELDS_3,
    116         scale(info.totalswap),
    117         scale(info.totalswap - info.freeswap),
    118         scale(info.freeswap)
     132        scale(info.totalswap),                 //total
     133        scale(info.totalswap - info.freeswap), //used
     134        scale(info.freeswap)                   //free
    119135    );
    120136#endif
  • branches/3.3/mindi-busybox/procps/fuser.c

    r3232 r3621  
    1919
    2020#include "libbb.h"
     21#include "common_bufsiz.h"
    2122
    2223#define MAX_LINE 255
     
    4445    int killsig;
    4546} FIX_ALIASING;
    46 #define G (*(struct globals*)&bb_common_bufsiz1)
     47#define G (*(struct globals*)bb_common_bufsiz1)
    4748#define INIT_G() do { \
     49    setup_common_bufsiz(); \
    4850    G.mypid = getpid(); \
    4951    G.killsig = SIGKILL; \
  • branches/3.3/mindi-busybox/procps/iostat.c

    r3232 r3621  
    110110};
    111111
    112 static ALWAYS_INLINE unsigned get_user_hz(void)
    113 {
    114     return sysconf(_SC_CLK_TCK);
    115 }
    116 
    117112static ALWAYS_INLINE int this_is_smp(void)
    118113{
     
    148143    /* %X: time representation for the current locale */
    149144    strftime(buf, sizeof(buf), "%x %X", &G.tmtime);
    150     printf("%s\n", buf);
     145    puts(buf);
    151146}
    152147
     
    415410
    416411    /* Get number of clock ticks per sec */
    417     G.clk_tck = get_user_hz();
     412    G.clk_tck = bb_clk_tck();
    418413
    419414    /* Determine number of CPUs */
  • branches/3.3/mindi-busybox/procps/kill.c

    r3232 r3621  
    6161 */
    6262
    63 int kill_main(int argc, char **argv)
     63int kill_main(int argc UNUSED_PARAM, char **argv)
    6464{
    6565    char *arg;
     
    8080
    8181    /* Parse any options */
    82     argc--;
    8382    arg = *++argv;
    8483
    85     if (argc < 1 || arg[0] != '-') {
     84    if (!arg || arg[0] != '-') {
    8685        goto do_it_now;
    8786    }
     
    9291     * We try to mimic what kill from coreutils-6.8 does */
    9392    if (arg[1] == 'l' && arg[2] == '\0') {
    94         if (argc == 1) {
     93        arg = *++argv;
     94        if (!arg) {
    9595            /* Print the whole signal list */
    9696            print_signames();
     
    9898        }
    9999        /* -l <sig list> */
    100         while ((arg = *++argv)) {
     100        do {
    101101            if (isdigit(arg[0])) {
    102102                signo = bb_strtou(arg, NULL, 10);
     
    119119                printf("%d\n", signo);
    120120            }
    121         }
    122         /* If they specified -l, we are all done */
     121            arg = *++argv;
     122        } while (arg);
    123123        return EXIT_SUCCESS;
    124124    }
     
    128128        quiet = 1;
    129129        arg = *++argv;
    130         argc--;
    131         if (argc < 1)
     130        if (!arg)
    132131            bb_show_usage();
    133132        if (arg[0] != '-')
     
    141140        goto do_it_now;
    142141
    143     if (argc > 1 && arg[0] == 's' && arg[1] == '\0') { /* -s SIG? */
    144         argc--;
     142    if (argv[1] && arg[0] == 's' && arg[1] == '\0') { /* -s SIG? */
    145143        arg = *++argv;
    146144    } /* else it must be -SIG */
     
    151149    }
    152150    arg = *++argv;
    153     argc--;
    154151
    155152 do_it_now:
     
    159156        pid_t sid;
    160157        procps_status_t* p = NULL;
    161         int ret = 0;
     158        /* compat: exitcode 2 is "no one was signaled" */
     159        int ret = 2;
    162160
    163161        /* Find out our session id */
     
    168166        /* Signal all processes except those in our session */
    169167        while ((p = procps_scan(p, PSSCAN_PID|PSSCAN_SID)) != NULL) {
    170             int i;
     168            char **args;
    171169
    172170            if (p->sid == (unsigned)sid
     171             || p->sid == 0 /* compat: kernel thread, don't signal it */
    173172             || p->pid == (unsigned)pid
    174173             || p->pid == 1
     
    179178            /* All remaining args must be -o PID options.
    180179             * Check p->pid against them. */
    181             for (i = 0; i < argc; i++) {
     180            args = argv;
     181            while (*args) {
    182182                pid_t omit;
    183183
    184                 arg = argv[i];
     184                arg = *args++;
    185185                if (arg[0] != '-' || arg[1] != 'o') {
    186186                    bb_error_msg("bad option '%s'", arg);
     
    189189                }
    190190                arg += 2;
    191                 if (!arg[0] && argv[++i])
    192                     arg = argv[i];
     191                if (!arg[0] && *args)
     192                    arg = *args++;
    193193                omit = bb_strtoi(arg, NULL, 10);
    194194                if (errno) {
     
    201201            }
    202202            kill(p->pid, signo);
     203            ret = 0;
    203204 dont_kill: ;
    204205        }
     
    211212
    212213    /* Pid or name is required for kill/killall */
    213     if (argc < 1) {
     214    if (!arg) {
    214215        bb_error_msg("you need to specify whom to kill");
    215216        return EXIT_FAILURE;
     
    218219    if (killall) {
    219220        /* Looks like they want to do a killall.  Do that */
    220         while (arg) {
     221        do {
    221222            pid_t* pidList;
    222223
     
    241242            free(pidList);
    242243            arg = *++argv;
    243         }
     244        } while (arg);
    244245        return errors;
    245246    }
  • branches/3.3/mindi-busybox/procps/mpstat.c

    r3232 r3621  
    523523    char buf[1024];
    524524
    525     fp = fopen_for_read(PROCFS_STAT);
    526     if (!fp)
    527         return;
     525    fp = xfopen_for_read(PROCFS_STAT);
    528526
    529527    while (fgets(buf, sizeof(buf), fp)) {
    530528        //bb_error_msg("/proc/stat:'%s'", buf);
    531         if (strncmp(buf, "intr ", 5) == 0) {
     529        if (is_prefixed_with(buf, "intr ")) {
    532530            /* Read total number of IRQs since system boot */
    533531            sscanf(buf + 5, "%"FMT_DATA"u", &irq->irq_nr);
     
    645643    unsigned long uptime_sec, decimal;
    646644
    647     fp = fopen_for_read(PROCFS_UPTIME);
    648     if (!fp)
    649         return;
     645    fp = xfopen_for_read(PROCFS_UPTIME);
    650646    if (fgets(buf, sizeof(buf), fp)) {
    651647        if (sscanf(buf, "%lu.%lu", &uptime_sec, &decimal) == 2) {
     
    776772/* Initialization */
    777773
    778 /* Get number of clock ticks per sec */
    779 static ALWAYS_INLINE unsigned get_hz(void)
    780 {
    781     return sysconf(_SC_CLK_TCK);
    782 }
    783 
    784774static void alloc_struct(int cpus)
    785775{
     
    874864
    875865    /* Get number of clock ticks per sec */
    876     G.hz = get_hz();
     866    G.hz = bb_clk_tck();
    877867
    878868    /* Calculate number of interrupts per processor */
  • branches/3.3/mindi-busybox/procps/nmeter.c

    r3232 r3621  
    2222//usage:       "Monitor system in real time"
    2323//usage:     "\n"
    24 //usage:     "\n -d MSEC    Milliseconds between updates (default:1000)"
     24//usage:     "\n -d MSEC    Milliseconds between updates, default:1000, none:-1"
    2525//usage:     "\n"
    2626//usage:     "\nFormat specifiers:"
     
    5454
    5555#include "libbb.h"
     56#include "common_bufsiz.h"
    5657
    5758typedef unsigned long long ullong;
     
    8485    // 1 if sample delay is not an integer fraction of a second
    8586    smallint need_seconds;
     87    char final_char;
    8688    char *cur_outbuf;
    87     const char *final_str;
    8889    int delta;
    89     int deltanz;
     90    unsigned deltanz;
    9091    struct timeval tv;
    9192#define first_proc_file proc_stat
     
    102103#define need_seconds       (G.need_seconds      )
    103104#define cur_outbuf         (G.cur_outbuf        )
    104 #define final_str          (G.final_str         )
    105 #define delta              (G.delta             )
    106 #define deltanz            (G.deltanz           )
    107105#define tv                 (G.tv                )
    108106#define proc_stat          (G.proc_stat         )
     
    112110#define proc_diskstats     (G.proc_diskstats    )
    113111#define proc_sys_fs_filenr (G.proc_sys_fs_filenr)
     112#define outbuf bb_common_bufsiz1
    114113#define INIT_G() do { \
     114    setup_common_bufsiz(); \
    115115    SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
    116116    cur_outbuf = outbuf; \
    117     final_str = "\n"; \
    118     deltanz = delta = 1000000; \
     117    G.final_char = '\n'; \
     118    G.deltanz = G.delta = 1000000; \
    119119} while (0)
    120 
    121 // We depend on this being a char[], not char* - we take sizeof() of it
    122 #define outbuf bb_common_bufsiz1
    123120
    124121static inline void reset_outbuf(void)
     
    143140static void put(const char *s)
    144141{
    145     int sz = strlen(s);
    146     if (sz > outbuf + sizeof(outbuf) - cur_outbuf)
    147         sz = outbuf + sizeof(outbuf) - cur_outbuf;
    148     memcpy(cur_outbuf, s, sz);
    149     cur_outbuf += sz;
     142    char *p = cur_outbuf;
     143    int sz = outbuf + COMMON_BUFSIZE - p;
     144    while (*s && --sz >= 0)
     145        *p++ = *s++;
     146    cur_outbuf = p;
    150147}
    151148
    152149static void put_c(char c)
    153150{
    154     if (cur_outbuf < outbuf + sizeof(outbuf))
     151    if (cur_outbuf < outbuf + COMMON_BUFSIZE)
    155152        *cur_outbuf++ = c;
    156153}
     
    209206}
    210207
    211 enum conv_type { conv_decimal, conv_slash };
     208enum conv_type {
     209    conv_decimal = 0,
     210    conv_slash = 1
     211};
    212212
    213213// Reads decimal values from line. Values start after key, for example:
    214214// "cpu  649369 0 341297 4336769..." - key is "cpu" here.
    215 // Values are stored in vec[]. arg_ptr has list of positions
    216 // we are interested in: for example: 1,2,5 - we want 1st, 2nd and 5th value.
    217 static int vrdval(const char* p, const char* key,
    218     enum conv_type conv, ullong *vec, va_list arg_ptr)
    219 {
    220     int indexline;
    221     int indexnext;
     215// Values are stored in vec[].
     216// posbits is a bit lit of positions we are interested in.
     217// for example: 00100110 - we want 1st, 2nd and 5th value.
     218// posbits.bit0 encodes conversion type.
     219static int rdval(const char* p, const char* key, ullong *vec, long posbits)
     220{
     221    unsigned curpos;
    222222
    223223    p = strstr(p, key);
     
    225225
    226226    p += strlen(key);
    227     indexline = 1;
    228     indexnext = va_arg(arg_ptr, int);
     227    curpos = 1 << 1;
    229228    while (1) {
    230229        while (*p == ' ' || *p == '\t') p++;
    231230        if (*p == '\n' || *p == '\0') break;
    232231
    233         if (indexline == indexnext) { // read this value
    234             *vec++ = conv==conv_decimal ?
     232        if (curpos & posbits) { // read this value
     233            *vec++ = (posbits & 1) == conv_decimal ?
    235234                strtoull(p, NULL, 10) :
    236235                read_after_slash(p);
    237             indexnext = va_arg(arg_ptr, int);
     236            posbits -= curpos;
     237            if (posbits <= 1)
     238                return 0;
    238239        }
    239         while (*p > ' ') p++; // skip over value
    240         indexline++;
     240        while (*p > ' ') // skip over the value
     241            p++;
     242        curpos <<= 1;
    241243    }
    242244    return 0;
    243245}
    244246
    245 // Parses files with lines like "cpu0 21727 0 15718 1813856 9461 10485 0 0":
    246 // rdval(file_contents, "string_to_find", result_vector, value#, value#...)
    247 // value# start with 1
    248 static int rdval(const char* p, const char* key, ullong *vec, ...)
    249 {
    250     va_list arg_ptr;
     247// Parses files with lines like "... ... ... 3/148 ...."
     248static int rdval_loadavg(const char* p, ullong *vec, long posbits)
     249{
    251250    int result;
    252 
    253     va_start(arg_ptr, vec);
    254     result = vrdval(p, key, conv_decimal, vec, arg_ptr);
    255     va_end(arg_ptr);
    256 
    257     return result;
    258 }
    259 
    260 // Parses files with lines like "... ... ... 3/148 ...."
    261 static int rdval_loadavg(const char* p, ullong *vec, ...)
    262 {
    263     va_list arg_ptr;
    264     int result;
    265 
    266     va_start(arg_ptr, vec);
    267     result = vrdval(p, "", conv_slash, vec, arg_ptr);
    268     va_end(arg_ptr);
    269 
     251    result = rdval(p, "", vec, posbits | conv_slash);
    270252    return result;
    271253}
     
    334316
    335317    /* see http://en.wikipedia.org/wiki/Tera */
    336     smart_ulltoa4(ul, buf, " kmgtpezy");
    337     buf[4] = '\0';
     318    smart_ulltoa4(ul, buf, " kmgtpezy")[0] = '\0';
    338319    put(buf);
    339320}
    340 
    341321
    342322#define S_STAT(a) \
     
    361341}
    362342
    363 static s_stat* init_delay(const char *param)
    364 {
    365     delta = strtoul(param, NULL, 0) * 1000; /* param can be "" */
    366     deltanz = delta > 0 ? delta : 1;
    367     need_seconds = (1000000%deltanz) != 0;
     343static s_stat* init_cr(const char *param UNUSED_PARAM)
     344{
     345    G.final_char = '\r';
    368346    return NULL;
    369347}
    370 
    371 static s_stat* init_cr(const char *param UNUSED_PARAM)
    372 {
    373     final_str = "\r";
    374     return (s_stat*)0;
    375 }
    376 
    377348
    378349//     user nice system idle  iowait irq  softirq (last 3 only in 2.6)
     
    383354    ullong old[CPU_FIELDCNT];
    384355    int bar_sz;
    385     char *bar;
     356    char bar[1];
    386357S_STAT_END(cpu_stat)
    387 
    388358
    389359static void FAST_FUNC collect_cpu(cpu_stat *s)
     
    397367    int i;
    398368
    399     if (rdval(get_file(&proc_stat), "cpu ", data, 1, 2, 3, 4, 5, 6, 7)) {
     369    if (rdval(get_file(&proc_stat), "cpu ", data, 0
     370        | (1 << 1)
     371        | (1 << 2)
     372        | (1 << 3)
     373        | (1 << 4)
     374        | (1 << 5)
     375        | (1 << 6)
     376        | (1 << 7))
     377    ) {
    400378        put_question_marks(bar_sz);
    401379        return;
     
    440418}
    441419
    442 
    443420static s_stat* init_cpu(const char *param)
    444421{
    445422    int sz;
    446     cpu_stat *s = xzalloc(sizeof(*s));
    447     s->collect = collect_cpu;
     423    cpu_stat *s;
    448424    sz = strtoul(param, NULL, 0); /* param can be "" */
    449425    if (sz < 10) sz = 10;
    450426    if (sz > 1000) sz = 1000;
    451     s->bar = xzalloc(sz+1);
     427    s = xzalloc(sizeof(*s) + sz);
    452428    /*s->bar[sz] = '\0'; - xzalloc did it */
    453429    s->bar_sz = sz;
    454     return (s_stat*)s;
    455 }
    456 
     430    s->collect = collect_cpu;
     431    return (s_stat*)s;
     432}
    457433
    458434S_STAT(int_stat)
     
    466442    ullong old;
    467443
    468     if (rdval(get_file(&proc_stat), "intr", data, s->no)) {
     444    if (rdval(get_file(&proc_stat), "intr", data, 1 << s->no)) {
    469445        put_question_marks(4);
    470446        return;
     
    490466}
    491467
    492 
    493468S_STAT(ctx_stat)
    494469    ullong old;
     
    500475    ullong old;
    501476
    502     if (rdval(get_file(&proc_stat), "ctxt", data, 1)) {
     477    if (rdval(get_file(&proc_stat), "ctxt", data, 1 << 1)) {
    503478        put_question_marks(4);
    504479        return;
     
    518493}
    519494
    520 
    521495S_STAT(blk_stat)
    522496    const char* lookfor;
     
    532506        i = rdval_diskstats(get_file(&proc_diskstats), data);
    533507    } else {
    534         i = rdval(get_file(&proc_stat), s->lookfor, data, 1, 2);
     508        i = rdval(get_file(&proc_stat), s->lookfor, data, 0
     509                | (1 << 1)
     510                | (1 << 2)
     511        );
    535512        // Linux 2.4 reports bio in Kbytes, convert to sectors:
    536513        data[0] *= 2;
     
    561538}
    562539
    563 
    564540S_STAT(fork_stat)
    565541    ullong old;
     
    570546    ullong data[1];
    571547
    572     if (rdval_loadavg(get_file(&proc_loadavg), data, 4)) {
     548    if (rdval_loadavg(get_file(&proc_loadavg), data, 1 << 4)) {
    573549        put_question_marks(4);
    574550        return;
     
    582558    ullong old;
    583559
    584     if (rdval(get_file(&proc_stat), "processes", data, 1)) {
     560    if (rdval(get_file(&proc_stat), "processes", data, 1 << 1)) {
    585561        put_question_marks(4);
    586562        return;
     
    604580}
    605581
    606 
    607582S_STAT(if_stat)
    608583    ullong old[4];
     
    616591    int i;
    617592
    618     if (rdval(get_file(&proc_net_dev), s->device_colon, data, 1, 3, 9, 11)) {
     593    if (rdval(get_file(&proc_net_dev), s->device_colon, data, 0
     594        | (1 << 1)
     595        | (1 << 3)
     596        | (1 << 9)
     597        | (1 << 11))
     598    ) {
    619599        put_question_marks(10);
    620600        return;
     
    645625    return (s_stat*)s;
    646626}
    647 
    648627
    649628S_STAT(mem_stat)
     
    694673    ullong m_slab = 0;
    695674
    696     if (rdval(get_file(&proc_meminfo), "MemTotal:", &m_total, 1)) {
     675    if (rdval(get_file(&proc_meminfo), "MemTotal:", &m_total, 1 << 1)) {
    697676        put_question_marks(4);
    698677        return;
     
    703682    }
    704683
    705     if (rdval(proc_meminfo.file, "MemFree:", &m_free  , 1)
    706      || rdval(proc_meminfo.file, "Buffers:", &m_bufs  , 1)
    707      || rdval(proc_meminfo.file, "Cached:",  &m_cached, 1)
    708      || rdval(proc_meminfo.file, "Slab:",    &m_slab  , 1)
     684    if (rdval(proc_meminfo.file, "MemFree:", &m_free  , 1 << 1)
     685     || rdval(proc_meminfo.file, "Buffers:", &m_bufs  , 1 << 1)
     686     || rdval(proc_meminfo.file, "Cached:",  &m_cached, 1 << 1)
     687     || rdval(proc_meminfo.file, "Slab:",    &m_slab  , 1 << 1)
    709688    ) {
    710689        put_question_marks(4);
     
    729708}
    730709
    731 
    732710S_STAT(swp_stat)
    733711S_STAT_END(swp_stat)
     
    737715    ullong s_total[1];
    738716    ullong s_free[1];
    739     if (rdval(get_file(&proc_meminfo), "SwapTotal:", s_total, 1)
    740      || rdval(proc_meminfo.file,       "SwapFree:" , s_free,  1)
     717    if (rdval(get_file(&proc_meminfo), "SwapTotal:", s_total, 1 << 1)
     718     || rdval(proc_meminfo.file,       "SwapFree:" , s_free,  1 << 1)
    741719    ) {
    742720        put_question_marks(4);
     
    753731}
    754732
    755 
    756733S_STAT(fd_stat)
    757734S_STAT_END(fd_stat)
     
    761738    ullong data[2];
    762739
    763     if (rdval(get_file(&proc_sys_fs_filenr), "", data, 1, 2)) {
     740    if (rdval(get_file(&proc_sys_fs_filenr), "", data, 0
     741        | (1 << 1)
     742        | (1 << 2))
     743    ) {
    764744        put_question_marks(4);
    765745        return;
     
    776756}
    777757
    778 
    779758S_STAT(time_stat)
    780     int prec;
    781     int scale;
     759    unsigned prec;
     760    unsigned scale;
    782761S_STAT_END(time_stat)
    783762
     
    786765    char buf[sizeof("12:34:56.123456")];
    787766    struct tm* tm;
    788     int us = tv.tv_usec + s->scale/2;
     767    unsigned us = tv.tv_usec + s->scale/2;
    789768    time_t t = tv.tv_sec;
    790769
     
    827806}
    828807
    829 
    830808typedef s_stat* init_func(const char *param);
    831809
    832 // Deprecated %NNNd is to be removed, -d MSEC supersedes it
    833 static const char options[] ALIGN1 = "ncmsfixptbdr";
     810static const char options[] ALIGN1 = "ncmsfixptbr";
    834811static init_func *const init_functions[] = {
    835812    init_if,
     
    843820    init_time,
    844821    init_blk,
    845     init_delay,
    846822    init_cr
    847823};
     
    866842    }
    867843
    868     if (getopt32(argv, "d:", &opt_d))
    869         init_delay(opt_d);
     844    if (getopt32(argv, "d:", &opt_d)) {
     845        G.delta = xatoi(opt_d) * 1000;
     846        G.deltanz = G.delta > 0 ? G.delta : 1;
     847        need_seconds = (1000000 % G.deltanz) != 0;
     848    }
    870849    argv += optind;
    871850
     
    922901            last = s;
    923902        } else {
    924             // %NNNNd or %r option. remove it from string
    925             strcpy(prev + strlen(prev), cur);
     903            // %r option. remove it from string
     904            overlapping_strcpy(prev + strlen(prev), cur);
    926905            cur = prev;
    927906        }
     
    941920    collect_info(first);
    942921    reset_outbuf();
    943     if (delta >= 0) {
     922    if (G.delta >= 0) {
    944923        gettimeofday(&tv, NULL);
    945         usleep(delta > 1000000 ? 1000000 : delta - tv.tv_usec%deltanz);
     924        usleep(G.delta > 1000000 ? 1000000 : G.delta - tv.tv_usec % G.deltanz);
    946925    }
    947926
     
    949928        gettimeofday(&tv, NULL);
    950929        collect_info(first);
    951         put(final_str);
     930        put_c(G.final_char);
    952931        print_outbuf();
    953932
     
    957936        // TODO: detect and avoid useless updates
    958937        // (like: nothing happens except time)
    959         if (delta >= 0) {
     938        if (G.delta >= 0) {
    960939            int rem;
    961940            // can be commented out, will sacrifice sleep time precision a bit
    962941            gettimeofday(&tv, NULL);
    963942            if (need_seconds)
    964                 rem = delta - ((ullong)tv.tv_sec*1000000 + tv.tv_usec) % deltanz;
     943                rem = G.delta - ((ullong)tv.tv_sec*1000000 + tv.tv_usec) % G.deltanz;
    965944            else
    966                 rem = delta - tv.tv_usec%deltanz;
     945                rem = G.delta - (unsigned)tv.tv_usec % G.deltanz;
    967946            // Sometimes kernel wakes us up just a tiny bit earlier than asked
    968947            // Do not go to very short sleep in this case
    969             if (rem < delta/128) {
    970                 rem += delta;
     948            if (rem < (unsigned)G.delta / 128) {
     949                rem += G.delta;
    971950            }
    972951            usleep(rem);
  • branches/3.3/mindi-busybox/procps/pgrep.c

    r3232 r3621  
    6666    if (pgrep) {
    6767        if (option_mask32 & (1 << OPTBIT_L)) /* OPT_LIST */
    68             printf("%d %s\n", pid, cmd);
     68            printf("%u %s\n", pid, cmd);
    6969        else
    70             printf("%d\n", pid);
     70            printf("%u\n", pid);
    7171    } else
    7272        kill(pid, signo);
     
    129129
    130130    if (argv[0])
    131         xregcomp(&re_buffer, argv[0], REG_EXTENDED | REG_NOSUB);
     131        xregcomp(&re_buffer, argv[0], OPT_ANCHOR ? REG_EXTENDED : (REG_EXTENDED|REG_NOSUB));
    132132
    133133    matched_pid = 0;
  • branches/3.3/mindi-busybox/procps/pmap.c

    r3232 r3621  
    2121//usage:       "[-xq] PID"
    2222//usage:#define pmap_full_usage "\n\n"
    23 //usage:       "Display detailed process memory usage"
     23//usage:       "Display process memory usage"
    2424//usage:     "\n"
    2525//usage:     "\n    -x  Show details"
     
    6767    char buf[256];
    6868
    69     read_cmdline(buf, sizeof(buf), pid, "no such process");
     69    read_cmdline(buf, sizeof(buf), pid, NULL);
    7070    printf("%u: %s\n", (int)pid, buf);
    7171
  • branches/3.3/mindi-busybox/procps/powertop.c

    r3232 r3621  
    361361
    362362        name = p;
    363         strchrnul(name, '\n')[0] = '\0';
     363        chomp(p);
    364364        /* Save description of the interrupt */
    365365        if (nr >= 20000)
     
    459459            //}
    460460
    461             if (strncmp(func, "tick_nohz_", 10) == 0)
    462                 continue;
    463             if (strncmp(func, "tick_setup_sched_timer", 20) == 0)
     461            if (is_prefixed_with(func, "tick_nohz_"))
     462                continue;
     463            if (is_prefixed_with(func, "tick_setup_sched_timer"))
    464464                continue;
    465465            //if (strcmp(process, "powertop") == 0)
     
    471471            }
    472472
    473             strchrnul(p, '\n')[0] = '\0';
     473            chomp(p);
    474474
    475475            // 46D\01136\0kondemand/1\0do_dbs_timer (delayed_work_timer_fn)
     
    592592        return;
    593593
    594     printf("Your CPU supports the following C-states: ");
     594    printf("Your %s the following C-states: ", "CPU supports");
    595595    i = 0;
    596596    while (edx) {
     
    603603
    604604    /* Print BIOS C-States */
    605     printf("Your BIOS reports the following C-states: ");
     605    printf("Your %s the following C-states: ", "BIOS reports");
    606606    for (i = 0; i < ARRAY_SIZE(bios_table); i++)
    607607        if (bios_table[i])
     
    628628        char strbuf6[6];
    629629
    630         strbuf6[5] = '\0';
    631630        puts("\nTop causes for wakeups:");
    632631        for (i = 0; i < G.lines_cnt; i++) {
     
    640639                if (G.lines[i].disk_count)
    641640                    c = 'D';*/
    642                 smart_ulltoa5(G.lines[i].count, strbuf6, " KMGTPEZY");
     641                smart_ulltoa5(G.lines[i].count, strbuf6, " KMGTPEZY")[0] = '\0';
    643642                printf(/*" %5.1f%% (%s)%c  %s\n"*/
    644643                    " %5.1f%% (%s)   %s\n",
     
    676675//usage:       ""
    677676//usage:#define powertop_full_usage "\n\n"
    678 //usage:       "Analyze power consumption on Intel-based laptops\n"
     677//usage:       "Analyze power consumption on Intel-based laptops"
    679678
    680679int powertop_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     
    706705    G.total_cpus = get_cpu_count();
    707706
    708     printf("Collecting data for "DEFAULT_SLEEP_STR" seconds\n");
     707    puts("Collecting data for "DEFAULT_SLEEP_STR" seconds");
    709708
    710709#if ENABLE_FEATURE_USE_TERMIOS
  • branches/3.3/mindi-busybox/procps/ps.c

    r3232 r3621  
    6363
    6464#include "libbb.h"
     65#include "common_bufsiz.h"
    6566#ifdef __linux__
    6667# include <sys/sysinfo.h>
     
    7172
    7273#if ENABLE_FEATURE_PS_TIME || ENABLE_FEATURE_PS_LONG
    73 static long get_uptime(void)
     74static unsigned long get_uptime(void)
    7475{
    7576#ifdef __linux__
     
    7980    return info.uptime;
    8081#elif 1
    81     char buf[64];
    82     long uptime;
     82    unsigned long uptime;
     83    char buf[sizeof(uptime)*3 + 2];
     84    /* /proc/uptime is "UPTIME_SEC.NN IDLE_SEC.NN\n"
     85     * (where IDLE is cumulative over all CPUs)
     86     */
    8387    if (open_read_close("/proc/uptime", buf, sizeof(buf)) <= 0)
    84         bb_perror_msg_and_die("can't read %s", "/proc/uptime");
     88        bb_perror_msg_and_die("can't read '%s'", "/proc/uptime");
    8589    buf[sizeof(buf)-1] = '\0';
    86     sscanf(buf, "%l", &uptime);
     90    sscanf(buf, "%lu", &uptime);
    8791    return uptime;
    8892#else
     
    139143#if ENABLE_FEATURE_PS_TIME
    140144    unsigned kernel_HZ;
    141     unsigned long long seconds_since_boot;
     145    unsigned long seconds_since_boot;
    142146#endif
    143147} FIX_ALIASING;
    144 #define G (*(struct globals*)&bb_common_bufsiz1)
     148#define G (*(struct globals*)bb_common_bufsiz1)
    145149#define out                (G.out               )
    146150#define out_cnt            (G.out_cnt           )
     
    150154#define terminal_width     (G.terminal_width    )
    151155#define kernel_HZ          (G.kernel_HZ         )
    152 #define seconds_since_boot (G.seconds_since_boot)
    153 #define INIT_G() do { } while (0)
     156#define INIT_G() do { setup_common_bufsiz(); } while (0)
    154157
    155158#if ENABLE_FEATURE_PS_TIME
    156159/* for ELF executables, notes are pushed before environment and args */
    157 static ptrdiff_t find_elf_note(ptrdiff_t findme)
    158 {
    159     ptrdiff_t *ep = (ptrdiff_t *) environ;
     160static uintptr_t find_elf_note(uintptr_t findme)
     161{
     162    uintptr_t *ep = (uintptr_t *) environ;
    160163
    161164    while (*ep++)
     
    223226static unsigned get_kernel_HZ(void)
    224227{
    225 
    226228    if (kernel_HZ)
    227229        return kernel_HZ;
     
    232234        kernel_HZ = get_HZ_by_waiting();
    233235
    234     seconds_since_boot = get_uptime();
     236    G.seconds_since_boot = get_uptime();
    235237
    236238    return kernel_HZ;
     
    299301
    300302    /* see http://en.wikipedia.org/wiki/Tera */
    301     smart_ulltoa4(u, buf4, " mgtpezy");
    302     buf4[4] = '\0';
     303    smart_ulltoa4(u, buf4, " mgtpezy")[0] = '\0';
    303304    sprintf(buf, "%.*s", size, buf4);
    304305}
     
    351352    mm = ps->start_time / get_kernel_HZ();
    352353    /* must be after get_kernel_HZ()! */
    353     mm = seconds_since_boot - mm;
     354    mm = G.seconds_since_boot - mm;
    354355    ss = mm % 60;
    355356    mm /= 60;
     
    589590    //     Select which columns to display
    590591    /* We allow (and ignore) most of the above. FIXME.
    591      * -T is picked for threads (POSIX hasn't it standardized).
     592     * -T is picked for threads (POSIX hasn't standardized it).
    592593     * procps v3.2.7 supports -T and shows tids as SPID column,
    593594     * it also supports -L where it shows tids as LWP column.
     
    600601        } while (opt_o);
    601602    } else {
    602         /* Below: parse_o() needs char*, NOT const char*, can't give it default_o */
     603        /* Below: parse_o() needs char*, NOT const char*,
     604         * can't pass it constant string. Need to make a copy first.
     605         */
    603606#if ENABLE_SELINUX
    604607        if (!(opt & OPT_Z) || !is_selinux_enabled()) {
     
    621624    terminal_width = MAX_WIDTH;
    622625    if (isatty(1)) {
    623         get_terminal_width_height(0, &terminal_width, NULL);
     626        terminal_width = get_terminal_width(0);
    624627        if (--terminal_width > MAX_WIDTH)
    625628            terminal_width = MAX_WIDTH;
     
    653656    };
    654657#if ENABLE_FEATURE_PS_LONG
    655     time_t now = now;
    656     long uptime;
     658    time_t now = now; /* for compiler */
     659    unsigned long uptime = uptime;
    657660#endif
    658661    /* If we support any options, parse argv */
     
    671674        terminal_width = (w_count == 1) ? 132 : MAX_WIDTH;
    672675    } else {
    673         get_terminal_width_height(0, &terminal_width, NULL);
     676        terminal_width = get_terminal_width(0);
    674677        /* Go one less... */
    675678        if (--terminal_width > MAX_WIDTH)
     
    738741        {
    739742            char buf6[6];
    740             smart_ulltoa5(p->vsz, buf6, " mgtpezy");
    741             buf6[5] = '\0';
     743            smart_ulltoa5(p->vsz, buf6, " mgtpezy")[0] = '\0';
    742744#if ENABLE_FEATURE_PS_LONG
    743745            if (opts & OPT_l) {
     
    750752                struct tm *tm = localtime(&start);
    751753
    752                 smart_ulltoa5(p->rss, bufr, " mgtpezy");
    753                 bufr[5] = '\0';
     754                smart_ulltoa5(p->rss, bufr, " mgtpezy")[0] = '\0';
    754755
    755756                if (p->tty_major == 136)
     
    787788        {
    788789            int sz = terminal_width - len;
    789             char buf[sz + 1];
    790             read_cmdline(buf, sz, p->pid, p->comm);
    791             puts(buf);
     790            if (sz >= 0) {
     791                char buf[sz + 1];
     792                read_cmdline(buf, sz, p->pid, p->comm);
     793                puts(buf);
     794            }
    792795        }
    793796    }
  • branches/3.3/mindi-busybox/procps/renice.c

    r3232 r3621  
    2121
    2222//usage:#define renice_trivial_usage
    23 //usage:       "{{-n INCREMENT} | PRIORITY} [[-p | -g | -u] ID...]"
     23//usage:       "[-n] PRIORITY [[-p | -g | -u] ID...]..."
    2424//usage:#define renice_full_usage "\n\n"
    25 //usage:       "Change scheduling priority for a running process\n"
    26 //usage:     "\n    -n  Adjust current nice value (smaller is faster)"
    27 //usage:     "\n    -p  Process id(s) (default)"
    28 //usage:     "\n    -g  Process group id(s)"
    29 //usage:     "\n    -u  Process user name(s) and/or id(s)"
     25//usage:       "Change scheduling priority of a running process\n"
     26//usage:     "\n    -n  Add PRIORITY to current nice value"
     27//usage:     "\n        Without -n, nice value is set to PRIORITY"
     28//usage:     "\n    -p  Process ids (default)"
     29//usage:     "\n    -g  Process group ids"
     30//usage:     "\n    -u  Process user names"
    3031
    3132#include "libbb.h"
  • branches/3.3/mindi-busybox/procps/sysctl.c

    r3232 r3621  
    130130    if (fd < 0) {
    131131        switch (errno) {
     132        case EACCES:
     133            /* Happens for write-only settings, e.g. net.ipv6.route.flush */
     134            goto end;
    132135        case ENOENT:
    133136            if (option_mask32 & FLAG_SHOW_KEY_ERRORS)
  • branches/3.3/mindi-busybox/procps/top.c

    r3232 r3621  
    106106
    107107#include "libbb.h"
     108#include "common_bufsiz.h"
    108109
    109110
     
    184185}; //FIX_ALIASING; - large code growth
    185186enum { LINE_BUF_SIZE = COMMON_BUFSIZE - offsetof(struct globals, line_buf) };
    186 #define G (*(struct globals*)&bb_common_bufsiz1)
    187 struct BUG_bad_size {
    188     char BUG_G_too_big[sizeof(G) <= COMMON_BUFSIZE ? 1 : -1];
    189     char BUG_line_buf_too_small[LINE_BUF_SIZE > 80 ? 1 : -1];
    190 };
     187#define G (*(struct globals*)bb_common_bufsiz1)
    191188#define top              (G.top               )
    192189#define ntop             (G.ntop              )
     
    205202#define total_pcpu       (G.total_pcpu        )
    206203#define line_buf         (G.line_buf          )
    207 #define INIT_G() do { } while (0)
     204#define INIT_G() do { \
     205    setup_common_bufsiz(); \
     206    BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
     207    BUILD_BUG_ON(LINE_BUF_SIZE <= 80); \
     208} while (0)
    208209
    209210enum {
     
    265266{
    266267#if !ENABLE_FEATURE_TOP_SMP_CPU
    267     static const char fmt[] = "cpu %llu %llu %llu %llu %llu %llu %llu %llu";
     268    static const char fmt[] ALIGN1 = "cpu %llu %llu %llu %llu %llu %llu %llu %llu";
    268269#else
    269     static const char fmt[] = "cp%*s %llu %llu %llu %llu %llu %llu %llu %llu";
     270    static const char fmt[] ALIGN1 = "cp%*s %llu %llu %llu %llu %llu %llu %llu %llu";
    270271#endif
    271272    int ret;
     
    295296    prev_jif = cur_jif;
    296297    if (read_cpu_jiffy(fp, &cur_jif) < 4)
    297         bb_error_msg_and_die("can't read /proc/stat");
     298        bb_error_msg_and_die("can't read '%s'", "/proc/stat");
    298299
    299300#if !ENABLE_FEATURE_TOP_SMP_CPU
     
    500501#endif
    501502
     503enum {
     504    MI_MEMTOTAL,
     505    MI_MEMFREE,
     506    MI_MEMSHARED,
     507    MI_SHMEM,
     508    MI_BUFFERS,
     509    MI_CACHED,
     510    MI_SWAPTOTAL,
     511    MI_SWAPFREE,
     512    MI_DIRTY,
     513    MI_WRITEBACK,
     514    MI_ANONPAGES,
     515    MI_MAPPED,
     516    MI_SLAB,
     517    MI_MAX
     518};
     519
     520static void parse_meminfo(unsigned long meminfo[MI_MAX])
     521{
     522    static const char fields[] ALIGN1 =
     523        "MemTotal\0"
     524        "MemFree\0"
     525        "MemShared\0"
     526        "Shmem\0"
     527        "Buffers\0"
     528        "Cached\0"
     529        "SwapTotal\0"
     530        "SwapFree\0"
     531        "Dirty\0"
     532        "Writeback\0"
     533        "AnonPages\0"
     534        "Mapped\0"
     535        "Slab\0";
     536    char buf[60]; /* actual lines we expect are ~30 chars or less */
     537    FILE *f;
     538    int i;
     539
     540    memset(meminfo, 0, sizeof(meminfo[0]) * MI_MAX);
     541    f = xfopen_for_read("meminfo");
     542    while (fgets(buf, sizeof(buf), f) != NULL) {
     543        char *c = strchr(buf, ':');
     544        if (!c)
     545            continue;
     546        *c = '\0';
     547        i = index_in_strings(fields, buf);
     548        if (i >= 0)
     549            meminfo[i] = strtoul(c+1, NULL, 10);
     550    }
     551    fclose(f);
     552}
     553
    502554static unsigned long display_header(int scr_width, int *lines_rem_p)
    503555{
    504     FILE *fp;
    505     char buf[80];
    506     char scrbuf[80];
    507     unsigned long total, used, mfree, shared, buffers, cached;
    508 
    509     /* read memory info */
    510     fp = xfopen_for_read("meminfo");
    511 
    512     /*
    513      * Old kernels (such as 2.4.x) had a nice summary of memory info that
    514      * we could parse, however this is gone entirely in 2.6. Try parsing
    515      * the old way first, and if that fails, parse each field manually.
    516      *
    517      * First, we read in the first line. Old kernels will have bogus
    518      * strings we don't care about, whereas new kernels will start right
    519      * out with MemTotal:
    520      *                              -- PFM.
    521      */
    522     if (fscanf(fp, "MemTotal: %lu %s\n", &total, buf) != 2) {
    523         fgets(buf, sizeof(buf), fp);    /* skip first line */
    524 
    525         fscanf(fp, "Mem: %lu %lu %lu %lu %lu %lu",
    526             &total, &used, &mfree, &shared, &buffers, &cached);
    527         /* convert to kilobytes */
    528         used /= 1024;
    529         mfree /= 1024;
    530         shared /= 1024;
    531         buffers /= 1024;
    532         cached /= 1024;
    533         total /= 1024;
    534     } else {
    535         /*
    536          * Revert to manual parsing, which incidentally already has the
    537          * sizes in kilobytes. This should be safe for both 2.4 and
    538          * 2.6.
    539          */
    540         fscanf(fp, "MemFree: %lu %s\n", &mfree, buf);
    541 
    542         /*
    543          * MemShared: is no longer present in 2.6. Report this as 0,
    544          * to maintain consistent behavior with normal procps.
    545          */
    546         if (fscanf(fp, "MemShared: %lu %s\n", &shared, buf) != 2)
    547             shared = 0;
    548 
    549         fscanf(fp, "Buffers: %lu %s\n", &buffers, buf);
    550         fscanf(fp, "Cached: %lu %s\n", &cached, buf);
    551 
    552         used = total - mfree;
    553     }
    554     fclose(fp);
    555 
    556     /* output memory info */
     556    char scrbuf[100]; /* [80] was a bit too low on 8Gb ram box */
     557    char *buf;
     558    unsigned long meminfo[MI_MAX];
     559
     560    parse_meminfo(meminfo);
     561
     562    /* Output memory info */
    557563    if (scr_width > (int)sizeof(scrbuf))
    558564        scr_width = sizeof(scrbuf);
    559565    snprintf(scrbuf, scr_width,
    560566        "Mem: %luK used, %luK free, %luK shrd, %luK buff, %luK cached",
    561         used, mfree, shared, buffers, cached);
    562     /* go to top & clear to the end of screen */
     567        meminfo[MI_MEMTOTAL] - meminfo[MI_MEMFREE],
     568        meminfo[MI_MEMFREE],
     569        meminfo[MI_MEMSHARED] + meminfo[MI_SHMEM],
     570        meminfo[MI_BUFFERS],
     571        meminfo[MI_CACHED]);
     572    /* Go to top & clear to the end of screen */
    563573    printf(OPT_BATCH_MODE ? "%s\n" : "\033[H\033[J%s\n", scrbuf);
    564574    (*lines_rem_p)--;
    565575
    566     /* Display CPU time split as percentage of total time
    567      * This displays either a cumulative line or one line per CPU
     576    /* Display CPU time split as percentage of total time.
     577     * This displays either a cumulative line or one line per CPU.
    568578     */
    569579    display_cpus(scr_width, scrbuf, lines_rem_p);
    570580
    571     /* read load average as a string */
    572     buf[0] = '\0';
    573     open_read_close("loadavg", buf, sizeof(buf) - 1);
    574     buf[sizeof(buf) - 1] = '\n';
    575     *strchr(buf, '\n') = '\0';
    576     snprintf(scrbuf, scr_width, "Load average: %s", buf);
     581    /* Read load average as a string */
     582    buf = stpcpy(scrbuf, "Load average: ");
     583    open_read_close("loadavg", buf, sizeof(scrbuf) - sizeof("Load average: "));
     584    scrbuf[scr_width - 1] = '\0';
     585    strchrnul(buf, '\n')[0] = '\0';
    577586    puts(scrbuf);
    578587    (*lines_rem_p)--;
    579588
    580     return total;
     589    return meminfo[MI_MEMTOTAL];
    581590}
    582591
     
    678687            sprintf(vsz_str_buf, "%6ldm", s->vsz/1024);
    679688        else
    680             sprintf(vsz_str_buf, "%7ld", s->vsz);
     689            sprintf(vsz_str_buf, "%7lu", s->vsz);
    681690        /* PID PPID USER STAT VSZ %VSZ [%CPU] COMMAND */
    682691        col = snprintf(line_buf, scr_width,
     
    782791static void display_topmem_header(int scr_width, int *lines_rem_p)
    783792{
    784     enum {
    785         TOTAL = 0, MFREE, BUF, CACHE,
    786         SWAPTOTAL, SWAPFREE, DIRTY,
    787         MWRITE, ANON, MAP, SLAB,
    788         NUM_FIELDS
    789     };
    790     static const char match[NUM_FIELDS][12] = {
    791         "\x09" "MemTotal:",  // TOTAL
    792         "\x08" "MemFree:",   // MFREE
    793         "\x08" "Buffers:",   // BUF
    794         "\x07" "Cached:",    // CACHE
    795         "\x0a" "SwapTotal:", // SWAPTOTAL
    796         "\x09" "SwapFree:",  // SWAPFREE
    797         "\x06" "Dirty:",     // DIRTY
    798         "\x0a" "Writeback:", // MWRITE
    799         "\x0a" "AnonPages:", // ANON
    800         "\x07" "Mapped:",    // MAP
    801         "\x05" "Slab:",      // SLAB
    802     };
    803     char meminfo_buf[4 * 1024];
    804     const char *Z[NUM_FIELDS];
    805     unsigned i;
    806     int sz;
    807 
    808     for (i = 0; i < NUM_FIELDS; i++)
    809         Z[i] = "?";
    810 
    811     /* read memory info */
    812     sz = open_read_close("meminfo", meminfo_buf, sizeof(meminfo_buf) - 1);
    813     if (sz >= 0) {
    814         char *p = meminfo_buf;
    815         meminfo_buf[sz] = '\0';
    816         /* Note that fields always appear in the match[] order */
    817         for (i = 0; i < NUM_FIELDS; i++) {
    818             char *found = strstr(p, match[i] + 1);
    819             if (found) {
    820                 /* Cut "NNNN" out of "    NNNN kb" */
    821                 char *s = skip_whitespace(found + match[i][0]);
    822                 p = skip_non_whitespace(s);
    823                 *p++ = '\0';
    824                 Z[i] = s;
    825             }
    826         }
    827     }
     793    unsigned long meminfo[MI_MAX];
     794
     795    parse_meminfo(meminfo);
    828796
    829797    snprintf(line_buf, LINE_BUF_SIZE,
    830         "Mem total:%s anon:%s map:%s free:%s",
    831         Z[TOTAL], Z[ANON], Z[MAP], Z[MFREE]);
     798        "Mem total:%lu anon:%lu map:%lu free:%lu",
     799        meminfo[MI_MEMTOTAL],
     800        meminfo[MI_ANONPAGES],
     801        meminfo[MI_MAPPED],
     802        meminfo[MI_MEMFREE]);
    832803    printf(OPT_BATCH_MODE ? "%.*s\n" : "\033[H\033[J%.*s\n", scr_width, line_buf);
    833804
    834805    snprintf(line_buf, LINE_BUF_SIZE,
    835         " slab:%s buf:%s cache:%s dirty:%s write:%s",
    836         Z[SLAB], Z[BUF], Z[CACHE], Z[DIRTY], Z[MWRITE]);
     806        " slab:%lu buf:%lu cache:%lu dirty:%lu write:%lu",
     807        meminfo[MI_SLAB],
     808        meminfo[MI_BUFFERS],
     809        meminfo[MI_CACHED],
     810        meminfo[MI_DIRTY],
     811        meminfo[MI_WRITEBACK]);
    837812    printf("%.*s\n", scr_width, line_buf);
    838813
    839814    snprintf(line_buf, LINE_BUF_SIZE,
    840         "Swap total:%s free:%s", // TODO: % used?
    841         Z[SWAPTOTAL], Z[SWAPFREE]);
     815        "Swap total:%lu free:%lu", // TODO: % used?
     816        meminfo[MI_SWAPTOTAL],
     817        meminfo[MI_SWAPFREE]);
    842818    printf("%.*s\n", scr_width, line_buf);
    843819
     
    848824{
    849825    /* see http://en.wikipedia.org/wiki/Tera */
    850     smart_ulltoa5(ul, buf, " mgtpezy");
    851     buf[5] = ' ';
     826    smart_ulltoa5(ul, buf, " mgtpezy")[0] = ' ';
    852827}
    853828
     
    857832#define MIN_WIDTH sizeof(HDR_STR)
    858833    const topmem_status_t *s = topmem + G_scroll_ofs;
     834    char *cp, ch;
    859835
    860836    display_topmem_header(scr_width, &lines_rem);
     837
    861838    strcpy(line_buf, HDR_STR " COMMAND");
    862     line_buf[11 + sort_field * 6] = "^_"[inverted];
     839    /* Mark the ^FIELD^ we sort by */
     840    cp = &line_buf[5 + sort_field * 6];
     841    ch = "^_"[inverted];
     842    cp[6] = ch;
     843    do *cp++ = ch; while (*cp == ' ');
     844
    863845    printf(OPT_BATCH_MODE ? "%.*s" : "\e[7m%.*s\e[0m", scr_width, line_buf);
    864846    lines_rem--;
     
    919901static unsigned handle_input(unsigned scan_mask, unsigned interval)
    920902{
    921     struct pollfd pfd[1];
    922 
    923903    if (option_mask32 & OPT_EOF) {
    924904        /* EOF on stdin ("top </dev/null") */
     
    926906        return scan_mask;
    927907    }
    928 
    929     pfd[0].fd = 0;
    930     pfd[0].events = POLLIN;
    931908
    932909    while (1) {
     
    12051182        while ((p = procps_scan(p, scan_mask)) != NULL) {
    12061183            int n;
    1207 #if ENABLE_FEATURE_TOPMEM
    1208             if (scan_mask != TOPMEM_MASK)
    1209 #endif
    1210             {
     1184
     1185            IF_FEATURE_TOPMEM(if (scan_mask != TOPMEM_MASK)) {
    12111186                n = ntop;
    12121187                top = xrealloc_vector(top, 6, ntop++);
     
    12481223        }
    12491224
    1250         if (scan_mask != TOPMEM_MASK) {
     1225        IF_FEATURE_TOPMEM(if (scan_mask != TOPMEM_MASK)) {
    12511226#if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
    12521227            if (!prev_hist_count) {
     
    12621237            qsort(top, ntop, sizeof(top_status_t), (void*)(sort_function[0]));
    12631238#endif
     1239            display_process_list(G.lines, col);
    12641240        }
    12651241#if ENABLE_FEATURE_TOPMEM
    12661242        else { /* TOPMEM */
    12671243            qsort(topmem, ntop, sizeof(topmem_status_t), (void*)topmem_sort);
    1268         }
    1269 #endif
    1270         if (scan_mask != TOPMEM_MASK)
    1271             display_process_list(G.lines, col);
    1272 #if ENABLE_FEATURE_TOPMEM
    1273         else
    12741244            display_topmem_process_list(G.lines, col);
     1245        }
    12751246#endif
    12761247        clearmems();
     
    12811252#else
    12821253        scan_mask = handle_input(scan_mask, interval);
    1283 #endif /* FEATURE_USE_TERMIOS */
     1254#endif
    12841255    } /* end of "while (not Q)" */
    12851256
  • branches/3.3/mindi-busybox/procps/uptime.c

    r3232 r3621  
    8282#if ENABLE_FEATURE_UPTIME_UTMP_SUPPORT
    8383    {
    84         struct utmp *ut;
     84        struct utmpx *ut;
    8585        unsigned users = 0;
    86         while ((ut = getutent()) != NULL) {
    87             if ((ut->ut_type == USER_PROCESS) && (ut->ut_name[0] != '\0'))
     86        while ((ut = getutxent()) != NULL) {
     87            if ((ut->ut_type == USER_PROCESS) && (ut->ut_user[0] != '\0'))
    8888                users++;
    8989        }
  • branches/3.3/mindi-busybox/procps/watch.c

    r3232 r3621  
    7070        if (!(opt & 0x2)) { // no -t
    7171            const unsigned time_len = sizeof("1234-67-90 23:56:89");
    72             time_t t;
    7372
    7473            // STDERR_FILENO is procps3 compat:
    7574            // "watch ls 2>/dev/null" does not detect tty size
    76             get_terminal_width_height(STDERR_FILENO, &new_width, NULL);
     75            new_width = get_terminal_width(STDERR_FILENO);
    7776            if (new_width != width) {
    7877                width = new_width;
     
    8079                header = xasprintf("Every %us: %-*s", period, (int)width, cmd);
    8180            }
    82             time(&t);
    83             if (time_len < width)
    84                 strftime(header + width - time_len, time_len,
    85                     "%Y-%m-%d %H:%M:%S", localtime(&t));
     81            if (time_len < width) {
     82                strftime_YYYYMMDDHHMMSS(
     83                    header + width - time_len,
     84                    time_len,
     85                    /*time_t*:*/ NULL
     86                );
     87            }
    8688
    8789            // compat: empty line between header and cmd output
Note: See TracChangeset for help on using the changeset viewer.