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


Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 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:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • 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    }
Note: See TracChangeset for help on using the changeset viewer.