aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2010-09-15 16:33:33 +1000
committerNguyễn Thái Ngọc Duy <pclouds@gmail.com>2010-09-15 16:33:33 +1000
commit924d22029b978432c4a65a905a981b4661102edf (patch)
tree469957575269fabe3e8b7ddb412123da22185a4c
parentc5ef3a03d7d111634a1d2e4f72dcb1102049b592 (diff)
parent4fd7461aeaac63edb004696e722bf36e7f6f402c (diff)
downloadbusybox-w32-924d22029b978432c4a65a905a981b4661102edf.tar.gz
busybox-w32-924d22029b978432c4a65a905a981b4661102edf.tar.bz2
busybox-w32-924d22029b978432c4a65a905a981b4661102edf.zip
Merge branch 'procps'
-rw-r--r--include/libbb.h3
-rw-r--r--include/mingw.h2
-rw-r--r--libbb/find_pid_by_name.c4
-rw-r--r--libbb/procps.c3
-rw-r--r--procps/kill.c2
-rw-r--r--procps/ps.c10
-rw-r--r--scripts/defconfig.mingw3214
-rw-r--r--win32/process.c50
8 files changed, 80 insertions, 8 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 31e733d77..e82954fd0 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1466,6 +1466,9 @@ typedef struct procps_status_t {
1466#if ENABLE_FEATURE_TOP_SMP_PROCESS 1466#if ENABLE_FEATURE_TOP_SMP_PROCESS
1467 int last_seen_on_cpu; 1467 int last_seen_on_cpu;
1468#endif 1468#endif
1469#if ENABLE_PLATFORM_MINGW32
1470 HANDLE snapshot;
1471#endif
1469} procps_status_t; 1472} procps_status_t;
1470/* flag bits for procps_scan(xx, flags) calls */ 1473/* flag bits for procps_scan(xx, flags) calls */
1471enum { 1474enum {
diff --git a/include/mingw.h b/include/mingw.h
index e7c385ec6..85c97b702 100644
--- a/include/mingw.h
+++ b/include/mingw.h
@@ -289,7 +289,7 @@ IMPL(getuid,int,1,void);
289int fcntl(int fd, int cmd, ...); 289int fcntl(int fd, int cmd, ...);
290#define fork() -1 290#define fork() -1
291IMPL(fsync,int,0,int fd UNUSED_PARAM); 291IMPL(fsync,int,0,int fd UNUSED_PARAM);
292NOIMPL(kill,pid_t pid UNUSED_PARAM, int sig UNUSED_PARAM); 292int kill(pid_t pid, int sig);
293int link(const char *oldpath, const char *newpath); 293int link(const char *oldpath, const char *newpath);
294NOIMPL(mknod,const char *name UNUSED_PARAM, mode_t mode UNUSED_PARAM, dev_t device UNUSED_PARAM); 294NOIMPL(mknod,const char *name UNUSED_PARAM, mode_t mode UNUSED_PARAM, dev_t device UNUSED_PARAM);
295int mingw_open (const char *filename, int oflags, ...); 295int mingw_open (const char *filename, int oflags, ...);
diff --git a/libbb/find_pid_by_name.c b/libbb/find_pid_by_name.c
index db823d05b..d4bea8ab5 100644
--- a/libbb/find_pid_by_name.c
+++ b/libbb/find_pid_by_name.c
@@ -56,6 +56,7 @@ static int comm_match(procps_status_t *p, const char *procName)
56 * This can be crazily_long_script_name.sh! 56 * This can be crazily_long_script_name.sh!
57 * The telltale sign is basename(argv[1]) == procName */ 57 * The telltale sign is basename(argv[1]) == procName */
58 58
59#if !ENABLE_PLATFORM_MINGW32
59 if (!p->argv0) 60 if (!p->argv0)
60 return 0; 61 return 0;
61 62
@@ -66,6 +67,7 @@ static int comm_match(procps_status_t *p, const char *procName)
66 67
67 if (strcmp(bb_basename(argv1), procName) != 0) 68 if (strcmp(bb_basename(argv1), procName) != 0)
68 return 0; 69 return 0;
70#endif
69 71
70 return 1; 72 return 1;
71} 73}
@@ -88,10 +90,12 @@ pid_t* FAST_FUNC find_pid_by_name(const char *procName)
88 pidList = xzalloc(sizeof(*pidList)); 90 pidList = xzalloc(sizeof(*pidList));
89 while ((p = procps_scan(p, PSSCAN_PID|PSSCAN_COMM|PSSCAN_ARGVN|PSSCAN_EXE))) { 91 while ((p = procps_scan(p, PSSCAN_PID|PSSCAN_COMM|PSSCAN_ARGVN|PSSCAN_EXE))) {
90 if (comm_match(p, procName) 92 if (comm_match(p, procName)
93#if !ENABLE_PLATFORM_MINGW32
91 /* or we require argv0 to match (essential for matching reexeced /proc/self/exe)*/ 94 /* or we require argv0 to match (essential for matching reexeced /proc/self/exe)*/
92 || (p->argv0 && strcmp(bb_basename(p->argv0), procName) == 0) 95 || (p->argv0 && strcmp(bb_basename(p->argv0), procName) == 0)
93 /* or we require /proc/PID/exe link to match */ 96 /* or we require /proc/PID/exe link to match */
94 || (p->exe && strcmp(bb_basename(p->exe), procName) == 0) 97 || (p->exe && strcmp(bb_basename(p->exe), procName) == 0)
98#endif
95 ) { 99 ) {
96 pidList = xrealloc_vector(pidList, 2, i); 100 pidList = xrealloc_vector(pidList, 2, i);
97 pidList[i++] = p->pid; 101 pidList[i++] = p->pid;
diff --git a/libbb/procps.c b/libbb/procps.c
index 14d4481bd..7ffcd8dbc 100644
--- a/libbb/procps.c
+++ b/libbb/procps.c
@@ -75,6 +75,7 @@ const char* FAST_FUNC get_cached_groupname(gid_t gid)
75 return get_cached(&groupname, gid, gid2group_utoa); 75 return get_cached(&groupname, gid, gid2group_utoa);
76} 76}
77 77
78#if !ENABLE_PLATFORM_MINGW32
78 79
79#define PROCPS_BUFSIZE 1024 80#define PROCPS_BUFSIZE 1024
80 81
@@ -552,6 +553,8 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags)
552 return sp; 553 return sp;
553} 554}
554 555
556#endif /* ENABLE_PLATFORM_MINGW32 */
557
555void FAST_FUNC read_cmdline(char *buf, int col, unsigned pid, const char *comm) 558void FAST_FUNC read_cmdline(char *buf, int col, unsigned pid, const char *comm)
556{ 559{
557 int sz; 560 int sz;
diff --git a/procps/kill.c b/procps/kill.c
index b51d44a70..3da39f030 100644
--- a/procps/kill.c
+++ b/procps/kill.c
@@ -50,6 +50,7 @@ int kill_main(int argc, char **argv)
50 goto do_it_now; 50 goto do_it_now;
51 } 51 }
52 52
53#if !ENABLE_PLATFORM_MINGW32
53 /* The -l option, which prints out signal names. 54 /* The -l option, which prints out signal names.
54 * Intended usage in shell: 55 * Intended usage in shell:
55 * echo "Died of SIG`kill -l $?`" 56 * echo "Died of SIG`kill -l $?`"
@@ -115,6 +116,7 @@ int kill_main(int argc, char **argv)
115 } 116 }
116 arg = *++argv; 117 arg = *++argv;
117 argc--; 118 argc--;
119#endif /* ENABLE_PLATFORM_MINGW32 */
118 120
119 do_it_now: 121 do_it_now:
120 pid = getpid(); 122 pid = getpid();
diff --git a/procps/ps.c b/procps/ps.c
index 48b55a785..3f7437b38 100644
--- a/procps/ps.c
+++ b/procps/ps.c
@@ -25,6 +25,8 @@ enum { MAX_WIDTH = 2*1024 };
25#if ENABLE_SELINUX 25#if ENABLE_SELINUX
26#define SELINUX_O_PREFIX "label," 26#define SELINUX_O_PREFIX "label,"
27#define DEFAULT_O_STR (SELINUX_O_PREFIX "pid,user" IF_FEATURE_PS_TIME(",time") ",args") 27#define DEFAULT_O_STR (SELINUX_O_PREFIX "pid,user" IF_FEATURE_PS_TIME(",time") ",args")
28#elif ENABLE_PLATFORM_MINGW32
29#define DEFAULT_O_STR ("pid,comm")
28#else 30#else
29#define DEFAULT_O_STR ("pid,user" IF_FEATURE_PS_TIME(",time") ",args") 31#define DEFAULT_O_STR ("pid,user" IF_FEATURE_PS_TIME(",time") ",args")
30#endif 32#endif
@@ -301,13 +303,19 @@ static void func_pcpu(char *buf, int size, const procps_status_t *ps)
301 303
302static const ps_out_t out_spec[] = { 304static const ps_out_t out_spec[] = {
303// Mandated by POSIX: 305// Mandated by POSIX:
306#if !ENABLE_PLATFORM_MINGW32
304 { 8 , "user" ,"USER" ,func_user ,PSSCAN_UIDGID }, 307 { 8 , "user" ,"USER" ,func_user ,PSSCAN_UIDGID },
305 { 8 , "group" ,"GROUP" ,func_group ,PSSCAN_UIDGID }, 308 { 8 , "group" ,"GROUP" ,func_group ,PSSCAN_UIDGID },
309#endif
306 { 16 , "comm" ,"COMMAND",func_comm ,PSSCAN_COMM }, 310 { 16 , "comm" ,"COMMAND",func_comm ,PSSCAN_COMM },
311#if !ENABLE_PLATFORM_MINGW32
307 { MAX_WIDTH , "args" ,"COMMAND",func_args ,PSSCAN_COMM }, 312 { MAX_WIDTH , "args" ,"COMMAND",func_args ,PSSCAN_COMM },
313#endif
308 { 5 , "pid" ,"PID" ,func_pid ,PSSCAN_PID }, 314 { 5 , "pid" ,"PID" ,func_pid ,PSSCAN_PID },
315#if !ENABLE_PLATFORM_MINGW32
309 { 5 , "ppid" ,"PPID" ,func_ppid ,PSSCAN_PPID }, 316 { 5 , "ppid" ,"PPID" ,func_ppid ,PSSCAN_PPID },
310 { 5 , "pgid" ,"PGID" ,func_pgid ,PSSCAN_PGID }, 317 { 5 , "pgid" ,"PGID" ,func_pgid ,PSSCAN_PGID },
318#endif
311#if ENABLE_FEATURE_PS_TIME 319#if ENABLE_FEATURE_PS_TIME
312 { sizeof("ELAPSED")-1, "etime" ,"ELAPSED",func_etime ,PSSCAN_START_TIME }, 320 { sizeof("ELAPSED")-1, "etime" ,"ELAPSED",func_etime ,PSSCAN_START_TIME },
313#endif 321#endif
@@ -320,10 +328,12 @@ static const ps_out_t out_spec[] = {
320#if ENABLE_FEATURE_PS_TIME 328#if ENABLE_FEATURE_PS_TIME
321 { 6 , "time" ,"TIME" ,func_time ,PSSCAN_STIME | PSSCAN_UTIME }, 329 { 6 , "time" ,"TIME" ,func_time ,PSSCAN_STIME | PSSCAN_UTIME },
322#endif 330#endif
331#if !ENABLE_PLATFORM_MINGW32
323 { 6 , "tty" ,"TT" ,func_tty ,PSSCAN_TTY }, 332 { 6 , "tty" ,"TT" ,func_tty ,PSSCAN_TTY },
324 { 4 , "vsz" ,"VSZ" ,func_vsz ,PSSCAN_VSZ }, 333 { 4 , "vsz" ,"VSZ" ,func_vsz ,PSSCAN_VSZ },
325// Not mandated by POSIX, but useful: 334// Not mandated by POSIX, but useful:
326 { 4 , "rss" ,"RSS" ,func_rss ,PSSCAN_RSS }, 335 { 4 , "rss" ,"RSS" ,func_rss ,PSSCAN_RSS },
336#endif
327#if ENABLE_SELINUX 337#if ENABLE_SELINUX
328 { 35 , "label" ,"LABEL" ,func_label ,PSSCAN_CONTEXT }, 338 { 35 , "label" ,"LABEL" ,func_label ,PSSCAN_CONTEXT },
329#endif 339#endif
diff --git a/scripts/defconfig.mingw32 b/scripts/defconfig.mingw32
index 23ac8b067..1669380ac 100644
--- a/scripts/defconfig.mingw32
+++ b/scripts/defconfig.mingw32
@@ -845,16 +845,16 @@ CONFIG_FEATURE_MIME_CHARSET=""
845# CONFIG_SMEMCAP is not set 845# CONFIG_SMEMCAP is not set
846# CONFIG_FREE is not set 846# CONFIG_FREE is not set
847# CONFIG_FUSER is not set 847# CONFIG_FUSER is not set
848# CONFIG_KILL is not set 848CONFIG_KILL=y
849# CONFIG_KILLALL is not set 849CONFIG_KILLALL=y
850# CONFIG_KILLALL5 is not set 850# CONFIG_KILLALL5 is not set
851# CONFIG_NMETER is not set 851# CONFIG_NMETER is not set
852# CONFIG_PGREP is not set 852CONFIG_PGREP=y
853# CONFIG_PIDOF is not set 853CONFIG_PIDOF=y
854# CONFIG_FEATURE_PIDOF_SINGLE is not set 854CONFIG_FEATURE_PIDOF_SINGLE=y
855# CONFIG_FEATURE_PIDOF_OMIT is not set 855CONFIG_FEATURE_PIDOF_OMIT=y
856# CONFIG_PKILL is not set 856# CONFIG_PKILL is not set
857# CONFIG_PS is not set 857CONFIG_PS=y
858# CONFIG_FEATURE_PS_WIDE is not set 858# CONFIG_FEATURE_PS_WIDE is not set
859# CONFIG_FEATURE_PS_TIME is not set 859# CONFIG_FEATURE_PS_TIME is not set
860# CONFIG_FEATURE_PS_ADDITIONAL_COLUMNS is not set 860# CONFIG_FEATURE_PS_ADDITIONAL_COLUMNS is not set
diff --git a/win32/process.c b/win32/process.c
index 13bf81797..cdd71182b 100644
--- a/win32/process.c
+++ b/win32/process.c
@@ -1,4 +1,5 @@
1#include "libbb.h" 1#include "libbb.h"
2#include <tlhelp32.h>
2 3
3int waitpid(pid_t pid, int *status, unsigned options) 4int waitpid(pid_t pid, int *status, unsigned options)
4{ 5{
@@ -284,3 +285,52 @@ mingw_execv(const char *cmd, const char *const *argv)
284{ 285{
285 return mingw_execve(cmd, argv, (const char *const *)environ); 286 return mingw_execve(cmd, argv, (const char *const *)environ);
286} 287}
288
289/* POSIX version in libbb/procps.c */
290procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags)
291{
292 PROCESSENTRY32 pe;
293
294 pe.dwSize = sizeof(pe);
295 if (!sp) {
296 sp = xzalloc(sizeof(struct procps_status_t));
297 sp->snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
298 if (sp->snapshot == INVALID_HANDLE_VALUE) {
299 free(sp);
300 return NULL;
301 }
302 if (!Process32First(sp->snapshot, &pe)) {
303 CloseHandle(sp->snapshot);
304 free(sp);
305 return NULL;
306 }
307 }
308 else {
309 if (!Process32Next(sp->snapshot, &pe)) {
310 CloseHandle(sp->snapshot);
311 free(sp);
312 return NULL;
313 }
314 }
315
316 sp->pid = pe.th32ProcessID;
317 strncpy(sp->comm, pe.szExeFile, COMM_LEN);
318 return sp;
319}
320
321int kill(pid_t pid, int sig)
322{
323 HANDLE h;
324
325 if (sig != SIGTERM) {
326 bb_error_msg("kill only supports SIGTERM");
327 errno = ENOSYS;
328 return -1;
329 }
330 h = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
331 if (h == NULL)
332 return -1;
333 if (TerminateProcess(h, 0) == 0)
334 return -1;
335 return 0;
336}