diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2010-09-15 09:44:01 +1000 |
---|---|---|
committer | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2010-09-15 16:17:16 +1000 |
commit | 903abcceb656701cd57a94404f1e13626618b1c9 (patch) | |
tree | b8b558a65ea2c23b3a983035d07580d84c80e249 /win32 | |
parent | 42b6a4c89ad8d4f625a3b63b7556929e3a660e90 (diff) | |
download | busybox-w32-903abcceb656701cd57a94404f1e13626618b1c9.tar.gz busybox-w32-903abcceb656701cd57a94404f1e13626618b1c9.tar.bz2 busybox-w32-903abcceb656701cd57a94404f1e13626618b1c9.zip |
win32: reimplement procps_scan()
On Linux, procps_scan() relies on /proc, which is obviously
unavailable on Windows.
This implementation currently supports procps_status_t.{pid,comm} only.
Diffstat (limited to 'win32')
-rw-r--r-- | win32/process.c | 33 |
1 files changed, 33 insertions, 0 deletions
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 | } | ||