diff options
-rw-r--r-- | include/libbb.h | 3 | ||||
-rw-r--r-- | libbb/procps.c | 3 | ||||
-rw-r--r-- | win32/process.c | 33 |
3 files changed, 39 insertions, 0 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 */ |
1471 | enum { | 1474 | enum { |
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 | |||
555 | void FAST_FUNC read_cmdline(char *buf, int col, unsigned pid, const char *comm) | 558 | void FAST_FUNC read_cmdline(char *buf, int col, unsigned pid, const char *comm) |
556 | { | 559 | { |
557 | int sz; | 560 | int sz; |
diff --git a/win32/process.c b/win32/process.c index 13bf81797..1b9b61878 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 | ||
3 | int waitpid(pid_t pid, int *status, unsigned options) | 4 | int waitpid(pid_t pid, int *status, unsigned options) |
4 | { | 5 | { |
@@ -284,3 +285,35 @@ 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 */ | ||
290 | procps_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 | } | ||