aboutsummaryrefslogtreecommitdiff
path: root/procps
diff options
context:
space:
mode:
Diffstat (limited to 'procps')
-rw-r--r--procps/free.c9
-rw-r--r--procps/iostat.c2
-rw-r--r--procps/kill.c2
-rw-r--r--procps/mpstat.c2
-rw-r--r--procps/pgrep.c55
-rw-r--r--procps/ps.c16
-rw-r--r--procps/smemcap.c1
-rw-r--r--procps/watch.c7
8 files changed, 91 insertions, 3 deletions
diff --git a/procps/free.c b/procps/free.c
index d0c849b79..90b4af702 100644
--- a/procps/free.c
+++ b/procps/free.c
@@ -77,6 +77,7 @@ static const char *scale(struct globals *g, unsigned long d)
77 return make_human_readable_str(d, g->mem_unit, G_unit); 77 return make_human_readable_str(d, g->mem_unit, G_unit);
78} 78}
79 79
80#if !ENABLE_PLATFORM_MINGW32
80/* NOINLINE reduces main() stack usage, which makes code smaller (on x86 at least) */ 81/* NOINLINE reduces main() stack usage, which makes code smaller (on x86 at least) */
81static NOINLINE unsigned int parse_meminfo(struct globals *g) 82static NOINLINE unsigned int parse_meminfo(struct globals *g)
82{ 83{
@@ -103,6 +104,14 @@ static NOINLINE unsigned int parse_meminfo(struct globals *g)
103 104
104 return seen_cached_and_available_and_reclaimable == 0; 105 return seen_cached_and_available_and_reclaimable == 0;
105} 106}
107#else
108static unsigned int parse_meminfo(struct globals *g)
109{
110 g->cached_kb = g->available_kb = g->reclaimable_kb = 0;
111
112 return 1;
113}
114#endif
106 115
107int free_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 116int free_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
108int free_main(int argc UNUSED_PARAM, char **argv IF_NOT_DESKTOP(UNUSED_PARAM)) 117int free_main(int argc UNUSED_PARAM, char **argv IF_NOT_DESKTOP(UNUSED_PARAM))
diff --git a/procps/iostat.c b/procps/iostat.c
index d3157757f..2feb02456 100644
--- a/procps/iostat.c
+++ b/procps/iostat.c
@@ -28,7 +28,7 @@
28#if 1 28#if 1
29typedef unsigned long long cputime_t; 29typedef unsigned long long cputime_t;
30typedef long long icputime_t; 30typedef long long icputime_t;
31# define FMT_DATA "ll" 31# define FMT_DATA LL_FMT
32# define CPUTIME_MAX (~0ULL) 32# define CPUTIME_MAX (~0ULL)
33#else 33#else
34typedef unsigned long cputime_t; 34typedef unsigned long cputime_t;
diff --git a/procps/kill.c b/procps/kill.c
index d4be18dd8..6be11296e 100644
--- a/procps/kill.c
+++ b/procps/kill.c
@@ -207,6 +207,7 @@ int kill_main(int argc UNUSED_PARAM, char **argv)
207 do_it_now: 207 do_it_now:
208 pid = getpid(); 208 pid = getpid();
209 209
210#if ENABLE_KILLALL5
210 if (is_killall5) { 211 if (is_killall5) {
211 pid_t sid; 212 pid_t sid;
212 procps_status_t* p = NULL; 213 procps_status_t* p = NULL;
@@ -264,6 +265,7 @@ int kill_main(int argc UNUSED_PARAM, char **argv)
264 kill(-1, SIGCONT); 265 kill(-1, SIGCONT);
265 return errors; 266 return errors;
266 } 267 }
268#endif
267 269
268#if ENABLE_KILL || ENABLE_KILLALL 270#if ENABLE_KILL || ENABLE_KILLALL
269 /* Pid or name is required for kill/killall */ 271 /* Pid or name is required for kill/killall */
diff --git a/procps/mpstat.c b/procps/mpstat.c
index 795b4ccb7..d8158ef8f 100644
--- a/procps/mpstat.c
+++ b/procps/mpstat.c
@@ -49,7 +49,7 @@
49#if 1 49#if 1
50typedef unsigned long long data_t; 50typedef unsigned long long data_t;
51typedef long long idata_t; 51typedef long long idata_t;
52#define FMT_DATA "ll" 52#define FMT_DATA LL_FMT
53#define DATA_MAX ULLONG_MAX 53#define DATA_MAX ULLONG_MAX
54#else 54#else
55typedef unsigned long data_t; 55typedef unsigned long data_t;
diff --git a/procps/pgrep.c b/procps/pgrep.c
index 04ae92a67..9773a72c4 100644
--- a/procps/pgrep.c
+++ b/procps/pgrep.c
@@ -30,31 +30,49 @@
30//kbuild:lib-$(CONFIG_PKILL) += pgrep.o 30//kbuild:lib-$(CONFIG_PKILL) += pgrep.o
31 31
32//usage:#define pgrep_trivial_usage 32//usage:#define pgrep_trivial_usage
33//usage: IF_NOT_PLATFORM_MINGW32(
33//usage: "[-flanovx] [-s SID|-P PPID|PATTERN]" 34//usage: "[-flanovx] [-s SID|-P PPID|PATTERN]"
35//usage: )
36//usage: IF_PLATFORM_MINGW32(
37//usage: "[-lvx] [-P PPID|PATTERN]"
38//usage: )
34//usage:#define pgrep_full_usage "\n\n" 39//usage:#define pgrep_full_usage "\n\n"
35//usage: "Display process(es) selected by regex PATTERN\n" 40//usage: "Display process(es) selected by regex PATTERN\n"
36//usage: "\n -l Show command name too" 41//usage: "\n -l Show command name too"
42//usage: IF_NOT_PLATFORM_MINGW32(
37//usage: "\n -a Show command line too" 43//usage: "\n -a Show command line too"
38//usage: "\n -f Match against entire command line" 44//usage: "\n -f Match against entire command line"
39//usage: "\n -n Show the newest process only" 45//usage: "\n -n Show the newest process only"
40//usage: "\n -o Show the oldest process only" 46//usage: "\n -o Show the oldest process only"
47//usage: )
41//usage: "\n -v Negate the match" 48//usage: "\n -v Negate the match"
42//usage: "\n -x Match whole name (not substring)" 49//usage: "\n -x Match whole name (not substring)"
50//usage: IF_NOT_PLATFORM_MINGW32(
43//usage: "\n -s Match session ID (0 for current)" 51//usage: "\n -s Match session ID (0 for current)"
52//usage: )
44//usage: "\n -P Match parent process ID" 53//usage: "\n -P Match parent process ID"
45//usage: 54//usage:
46//usage:#define pkill_trivial_usage 55//usage:#define pkill_trivial_usage
56//usage: IF_NOT_PLATFORM_MINGW32(
47//usage: "[-l|-SIGNAL] [-xfvnoe] [-s SID|-P PPID|PATTERN]" 57//usage: "[-l|-SIGNAL] [-xfvnoe] [-s SID|-P PPID|PATTERN]"
58//usage: )
59//usage: IF_PLATFORM_MINGW32(
60//usage: "[-l|-SIGNAL] [-xve] [-P PPID|PATTERN]"
61//usage: )
48//usage:#define pkill_full_usage "\n\n" 62//usage:#define pkill_full_usage "\n\n"
49//usage: "Send signal to processes selected by regex PATTERN\n" 63//usage: "Send signal to processes selected by regex PATTERN\n"
50//usage: "\n -l List all signals" 64//usage: "\n -l List all signals"
51//usage: "\n -x Match whole name (not substring)" 65//usage: "\n -x Match whole name (not substring)"
66//usage: IF_NOT_PLATFORM_MINGW32(
52//usage: "\n -f Match against entire command line" 67//usage: "\n -f Match against entire command line"
53//usage: "\n -s SID Match session ID (0 for current)" 68//usage: "\n -s SID Match session ID (0 for current)"
69//usage: )
54//usage: "\n -P PPID Match parent process ID" 70//usage: "\n -P PPID Match parent process ID"
55//usage: "\n -v Negate the match" 71//usage: "\n -v Negate the match"
72//usage: IF_NOT_PLATFORM_MINGW32(
56//usage: "\n -n Signal the newest process only" 73//usage: "\n -n Signal the newest process only"
57//usage: "\n -o Signal the oldest process only" 74//usage: "\n -o Signal the oldest process only"
75//usage: )
58//usage: "\n -e Display name and PID of the process being killed" 76//usage: "\n -e Display name and PID of the process being killed"
59 77
60#include "libbb.h" 78#include "libbb.h"
@@ -68,25 +86,47 @@ enum {
68 /* "vlafxones:+P:+" */ 86 /* "vlafxones:+P:+" */
69 OPTBIT_V = 0, /* must be first, we need OPT_INVERT = 0/1 */ 87 OPTBIT_V = 0, /* must be first, we need OPT_INVERT = 0/1 */
70 OPTBIT_L, 88 OPTBIT_L,
89#if !ENABLE_PLATFORM_MINGW32
71 OPTBIT_A, 90 OPTBIT_A,
72 OPTBIT_F, 91 OPTBIT_F,
92#else
93#define OPTBIT_A OPTBIT_L
94#endif
73 OPTBIT_X, 95 OPTBIT_X,
96#if !ENABLE_PLATFORM_MINGW32
74 OPTBIT_O, 97 OPTBIT_O,
75 OPTBIT_N, 98 OPTBIT_N,
99#endif
76 OPTBIT_E, /* should be pkill-only, do we care? */ 100 OPTBIT_E, /* should be pkill-only, do we care? */
101#if !ENABLE_PLATFORM_MINGW32
77 OPTBIT_S, 102 OPTBIT_S,
103#endif
78 OPTBIT_P, 104 OPTBIT_P,
79}; 105};
80 106
81#define OPT_INVERT (opt & (1 << OPTBIT_V)) 107#define OPT_INVERT (opt & (1 << OPTBIT_V))
82#define OPT_LIST (opt & (1 << OPTBIT_L)) 108#define OPT_LIST (opt & (1 << OPTBIT_L))
109#if ENABLE_PLATFORM_MINGW32
110#define OPT_LISTFULL (0)
111#define OPT_FULL (0)
112#else
83#define OPT_LISTFULL (opt & (1 << OPTBIT_A)) 113#define OPT_LISTFULL (opt & (1 << OPTBIT_A))
84#define OPT_FULL (opt & (1 << OPTBIT_F)) 114#define OPT_FULL (opt & (1 << OPTBIT_F))
115#endif
85#define OPT_ANCHOR (opt & (1 << OPTBIT_X)) 116#define OPT_ANCHOR (opt & (1 << OPTBIT_X))
117#if ENABLE_PLATFORM_MINGW32
118#define OPT_FIRST (0)
119#define OPT_LAST (0)
120#else
86#define OPT_FIRST (opt & (1 << OPTBIT_O)) 121#define OPT_FIRST (opt & (1 << OPTBIT_O))
87#define OPT_LAST (opt & (1 << OPTBIT_N)) 122#define OPT_LAST (opt & (1 << OPTBIT_N))
123#endif
88#define OPT_ECHO (opt & (1 << OPTBIT_E)) 124#define OPT_ECHO (opt & (1 << OPTBIT_E))
125#if ENABLE_PLATFORM_MINGW32
126#define OPT_SID (0)
127#else
89#define OPT_SID (opt & (1 << OPTBIT_S)) 128#define OPT_SID (opt & (1 << OPTBIT_S))
129#endif
90#define OPT_PPID (opt & (1 << OPTBIT_P)) 130#define OPT_PPID (opt & (1 << OPTBIT_P))
91 131
92static void act(unsigned pid, char *cmd, int signo) 132static void act(unsigned pid, char *cmd, int signo)
@@ -112,7 +152,12 @@ int pgrep_main(int argc UNUSED_PARAM, char **argv)
112 unsigned opt; 152 unsigned opt;
113 int scan_mask; 153 int scan_mask;
114 int matched_pid; 154 int matched_pid;
155#if ENABLE_PLATFORM_MINGW32
156 const int sid2match = -1;
157 int ppid2match;
158#else
115 int sid2match, ppid2match; 159 int sid2match, ppid2match;
160#endif
116 char *cmd_last; 161 char *cmd_last;
117 procps_status_t *proc; 162 procps_status_t *proc;
118 /* These are initialized to 0 */ 163 /* These are initialized to 0 */
@@ -137,8 +182,12 @@ int pgrep_main(int argc UNUSED_PARAM, char **argv)
137 182
138 /* Parse remaining options */ 183 /* Parse remaining options */
139 ppid2match = -1; 184 ppid2match = -1;
185#if !ENABLE_PLATFORM_MINGW32
140 sid2match = -1; 186 sid2match = -1;
141 opt = getopt32(argv, "vlafxones:+P:+", &sid2match, &ppid2match); 187 opt = getopt32(argv, "vlafxones:+P:+", &sid2match, &ppid2match);
188#else
189 opt = getopt32(argv, "vlxeP:+", &ppid2match);
190#endif
142 argv += optind; 191 argv += optind;
143 192
144 if (pkill && OPT_LIST) { /* -l: print the whole signal list */ 193 if (pkill && OPT_LIST) { /* -l: print the whole signal list */
@@ -147,8 +196,10 @@ int pgrep_main(int argc UNUSED_PARAM, char **argv)
147 } 196 }
148 197
149 pid = getpid(); 198 pid = getpid();
199#if !ENABLE_PLATFORM_MINGW32
150 if (sid2match == 0) 200 if (sid2match == 0)
151 sid2match = getsid(pid); 201 sid2match = getsid(pid);
202#endif
152 203
153 scan_mask = PSSCAN_COMM | PSSCAN_ARGV0; 204 scan_mask = PSSCAN_COMM | PSSCAN_ARGV0;
154 if (OPT_FULL) 205 if (OPT_FULL)
@@ -180,6 +231,9 @@ int pgrep_main(int argc UNUSED_PARAM, char **argv)
180 } 231 }
181 232
182 cmdlen = -1; 233 cmdlen = -1;
234#if ENABLE_PLATFORM_MINGW32
235 cmd = proc->comm;
236#else
183 cmd = proc->argv0; 237 cmd = proc->argv0;
184 if (!cmd) { 238 if (!cmd) {
185 cmd = proc->comm; 239 cmd = proc->comm;
@@ -199,6 +253,7 @@ int pgrep_main(int argc UNUSED_PARAM, char **argv)
199 cmd[i] = ' '; 253 cmd[i] = ' ';
200 } 254 }
201 } 255 }
256#endif
202 257
203 if (OPT_INVERT) { 258 if (OPT_INVERT) {
204 /* "pgrep -v -P1 firefox" means "not (ppid=1 AND name=firefox)" 259 /* "pgrep -v -P1 firefox" means "not (ppid=1 AND name=firefox)"
diff --git a/procps/ps.c b/procps/ps.c
index 5b521aebd..329576eb8 100644
--- a/procps/ps.c
+++ b/procps/ps.c
@@ -120,7 +120,7 @@ enum { MAX_WIDTH = 2*1024 };
120#if ENABLE_FEATURE_PS_TIME || ENABLE_FEATURE_PS_LONG 120#if ENABLE_FEATURE_PS_TIME || ENABLE_FEATURE_PS_LONG
121static unsigned long get_uptime(void) 121static unsigned long get_uptime(void)
122{ 122{
123#ifdef __linux__ 123#if defined __linux__ || ENABLE_PLATFORM_MINGW32
124 struct sysinfo info; 124 struct sysinfo info;
125 if (sysinfo(&info) < 0) 125 if (sysinfo(&info) < 0)
126 return 0; 126 return 0;
@@ -237,10 +237,12 @@ static void func_comm(char *buf, int size, const procps_status_t *ps)
237 safe_strncpy(buf, ps->comm, size+1); 237 safe_strncpy(buf, ps->comm, size+1);
238} 238}
239 239
240#if !ENABLE_PLATFORM_MINGW32
240static void func_state(char *buf, int size, const procps_status_t *ps) 241static void func_state(char *buf, int size, const procps_status_t *ps)
241{ 242{
242 safe_strncpy(buf, ps->state, size+1); 243 safe_strncpy(buf, ps->state, size+1);
243} 244}
245#endif
244 246
245static void func_args(char *buf, int size, const procps_status_t *ps) 247static void func_args(char *buf, int size, const procps_status_t *ps)
246{ 248{
@@ -257,6 +259,7 @@ static void func_ppid(char *buf, int size, const procps_status_t *ps)
257 sprintf(buf, "%*u", size, ps->ppid); 259 sprintf(buf, "%*u", size, ps->ppid);
258} 260}
259 261
262#if !ENABLE_PLATFORM_MINGW32
260static void func_pgid(char *buf, int size, const procps_status_t *ps) 263static void func_pgid(char *buf, int size, const procps_status_t *ps)
261{ 264{
262 sprintf(buf, "%*u", size, ps->pgid); 265 sprintf(buf, "%*u", size, ps->pgid);
@@ -293,6 +296,7 @@ static void func_tty(char *buf, int size, const procps_status_t *ps)
293 if (ps->tty_major) /* tty field of "0" means "no tty" */ 296 if (ps->tty_major) /* tty field of "0" means "no tty" */
294 snprintf(buf, size+1, "%u,%u", ps->tty_major, ps->tty_minor); 297 snprintf(buf, size+1, "%u,%u", ps->tty_major, ps->tty_minor);
295} 298}
299#endif
296 300
297#if ENABLE_FEATURE_PS_ADDITIONAL_COLUMNS 301#if ENABLE_FEATURE_PS_ADDITIONAL_COLUMNS
298static void func_rgroup(char *buf, int size, const procps_status_t *ps) 302static void func_rgroup(char *buf, int size, const procps_status_t *ps)
@@ -379,11 +383,17 @@ static const ps_out_t out_spec[] ALIGN_PTR = {
379/* Mandated by http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ps.html: */ 383/* Mandated by http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ps.html: */
380 { 8 , "user" ,"USER" ,func_user ,PSSCAN_UIDGID }, 384 { 8 , "user" ,"USER" ,func_user ,PSSCAN_UIDGID },
381 { 8 , "group" ,"GROUP" ,func_group ,PSSCAN_UIDGID }, 385 { 8 , "group" ,"GROUP" ,func_group ,PSSCAN_UIDGID },
386#if ENABLE_PLATFORM_MINGW32
387 { COMM_LEN , "comm" ,"COMMAND",func_comm ,PSSCAN_COMM },
388#else
382 { 16 , "comm" ,"COMMAND",func_comm ,PSSCAN_COMM }, 389 { 16 , "comm" ,"COMMAND",func_comm ,PSSCAN_COMM },
390#endif
383 { MAX_WIDTH , "args" ,"COMMAND",func_args ,PSSCAN_COMM }, 391 { MAX_WIDTH , "args" ,"COMMAND",func_args ,PSSCAN_COMM },
384 { 5 , "pid" ,"PID" ,func_pid ,PSSCAN_PID }, 392 { 5 , "pid" ,"PID" ,func_pid ,PSSCAN_PID },
385 { 5 , "ppid" ,"PPID" ,func_ppid ,PSSCAN_PPID }, 393 { 5 , "ppid" ,"PPID" ,func_ppid ,PSSCAN_PPID },
394#if !ENABLE_PLATFORM_MINGW32
386 { 5 , "pgid" ,"PGID" ,func_pgid ,PSSCAN_PGID }, 395 { 5 , "pgid" ,"PGID" ,func_pgid ,PSSCAN_PGID },
396#endif
387#if ENABLE_FEATURE_PS_TIME 397#if ENABLE_FEATURE_PS_TIME
388 { sizeof("ELAPSED")-1, "etime" ,"ELAPSED",func_etime ,PSSCAN_START_TIME }, 398 { sizeof("ELAPSED")-1, "etime" ,"ELAPSED",func_etime ,PSSCAN_START_TIME },
389#endif 399#endif
@@ -396,12 +406,14 @@ static const ps_out_t out_spec[] ALIGN_PTR = {
396#if ENABLE_FEATURE_PS_TIME 406#if ENABLE_FEATURE_PS_TIME
397 { 5 , "time" ,"TIME" ,func_time ,PSSCAN_STIME | PSSCAN_UTIME }, 407 { 5 , "time" ,"TIME" ,func_time ,PSSCAN_STIME | PSSCAN_UTIME },
398#endif 408#endif
409#if !ENABLE_PLATFORM_MINGW32
399 { 6 , "tty" ,"TT" ,func_tty ,PSSCAN_TTY }, 410 { 6 , "tty" ,"TT" ,func_tty ,PSSCAN_TTY },
400 { 4 , "vsz" ,"VSZ" ,func_vsz ,PSSCAN_VSZ }, 411 { 4 , "vsz" ,"VSZ" ,func_vsz ,PSSCAN_VSZ },
401/* Not mandated, but useful: */ 412/* Not mandated, but useful: */
402 { 5 , "sid" ,"SID" ,func_sid ,PSSCAN_SID }, 413 { 5 , "sid" ,"SID" ,func_sid ,PSSCAN_SID },
403 { 4 , "stat" ,"STAT" ,func_state ,PSSCAN_STATE }, 414 { 4 , "stat" ,"STAT" ,func_state ,PSSCAN_STATE },
404 { 4 , "rss" ,"RSS" ,func_rss ,PSSCAN_RSS }, 415 { 4 , "rss" ,"RSS" ,func_rss ,PSSCAN_RSS },
416#endif
405#if ENABLE_SELINUX 417#if ENABLE_SELINUX
406 { 35 , "label" ,"LABEL" ,func_label ,PSSCAN_CONTEXT }, 418 { 35 , "label" ,"LABEL" ,func_label ,PSSCAN_CONTEXT },
407#endif 419#endif
@@ -544,6 +556,8 @@ static void format_process(const procps_status_t *ps)
544#if ENABLE_SELINUX 556#if ENABLE_SELINUX
545# define SELINUX_O_PREFIX "label," 557# define SELINUX_O_PREFIX "label,"
546# define DEFAULT_O_STR (SELINUX_O_PREFIX "pid,user" IF_FEATURE_PS_TIME(",time") ",args") 558# define DEFAULT_O_STR (SELINUX_O_PREFIX "pid,user" IF_FEATURE_PS_TIME(",time") ",args")
559#elif ENABLE_PLATFORM_MINGW32
560# define DEFAULT_O_STR ("pid,ppid,user" IF_FEATURE_PS_TIME(",time,etime") ",args")
547#else 561#else
548# define DEFAULT_O_STR ("pid,user" IF_FEATURE_PS_TIME(",time") ",args") 562# define DEFAULT_O_STR ("pid,user" IF_FEATURE_PS_TIME(",time") ",args")
549#endif 563#endif
diff --git a/procps/smemcap.c b/procps/smemcap.c
index a2231788b..6839c9de0 100644
--- a/procps/smemcap.c
+++ b/procps/smemcap.c
@@ -19,6 +19,7 @@
19//kbuild:lib-$(CONFIG_SMEMCAP) += smemcap.o 19//kbuild:lib-$(CONFIG_SMEMCAP) += smemcap.o
20 20
21#include "libbb.h" 21#include "libbb.h"
22#define BB_ARCHIVE_PUBLIC
22#include "bb_archive.h" 23#include "bb_archive.h"
23 24
24struct fileblock { 25struct fileblock {
diff --git a/procps/watch.c b/procps/watch.c
index 05b72723c..d7c3ad55e 100644
--- a/procps/watch.c
+++ b/procps/watch.c
@@ -71,9 +71,16 @@ int watch_main(int argc UNUSED_PARAM, char **argv)
71 71
72 // watch from both procps 2.x and 3.x does concatenation. Example: 72 // watch from both procps 2.x and 3.x does concatenation. Example:
73 // watch ls -l "a /tmp" "2>&1" - ls won't see "a /tmp" as one param 73 // watch ls -l "a /tmp" "2>&1" - ls won't see "a /tmp" as one param
74#if ENABLE_PLATFORM_MINGW32
75 cmd = NULL;
76 do {
77 cmd = xappendword(cmd, *argv);
78 } while (*++argv);
79#else
74 cmd = *argv; 80 cmd = *argv;
75 while (*++argv) 81 while (*++argv)
76 cmd = xasprintf("%s %s", cmd, *argv); // leaks cmd 82 cmd = xasprintf("%s %s", cmd, *argv); // leaks cmd
83#endif
77 84
78 period = parse_duration_str(period_str); 85 period = parse_duration_str(period_str);
79 width = (unsigned)-1; // make sure first time new_width != width 86 width = (unsigned)-1; // make sure first time new_width != width