From 903abcceb656701cd57a94404f1e13626618b1c9 Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Wed, 15 Sep 2010 09:44:01 +1000 Subject: 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. --- win32/process.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'win32') 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 @@ #include "libbb.h" +#include int waitpid(pid_t pid, int *status, unsigned options) { @@ -284,3 +285,35 @@ mingw_execv(const char *cmd, const char *const *argv) { return mingw_execve(cmd, argv, (const char *const *)environ); } + +/* POSIX version in libbb/procps.c */ +procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags) +{ + PROCESSENTRY32 pe; + + pe.dwSize = sizeof(pe); + if (!sp) { + sp = xzalloc(sizeof(struct procps_status_t)); + sp->snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); + if (sp->snapshot == INVALID_HANDLE_VALUE) { + free(sp); + return NULL; + } + if (!Process32First(sp->snapshot, &pe)) { + CloseHandle(sp->snapshot); + free(sp); + return NULL; + } + } + else { + if (!Process32Next(sp->snapshot, &pe)) { + CloseHandle(sp->snapshot); + free(sp); + return NULL; + } + } + + sp->pid = pe.th32ProcessID; + strncpy(sp->comm, pe.szExeFile, COMM_LEN); + return sp; +} -- cgit v1.2.3-55-g6feb From 507a5a689e7441782fcdbe96d88068dee9a3145e Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Wed, 15 Sep 2010 12:38:10 +1000 Subject: win32: process.c: implement kill(), SIGTERM only --- include/mingw.h | 2 +- win32/process.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) (limited to 'win32') diff --git a/include/mingw.h b/include/mingw.h index 53a0a0d67..a43e8eca2 100644 --- a/include/mingw.h +++ b/include/mingw.h @@ -285,7 +285,7 @@ IMPL(getuid,int,1,void); int fcntl(int fd, int cmd, ...); #define fork() -1 IMPL(fsync,int,0,int fd UNUSED_PARAM); -NOIMPL(kill,pid_t pid UNUSED_PARAM, int sig UNUSED_PARAM); +int kill(pid_t pid, int sig); int link(const char *oldpath, const char *newpath); NOIMPL(mknod,const char *name UNUSED_PARAM, mode_t mode UNUSED_PARAM, dev_t device UNUSED_PARAM); int mingw_open (const char *filename, int oflags, ...); diff --git a/win32/process.c b/win32/process.c index 1b9b61878..cdd71182b 100644 --- a/win32/process.c +++ b/win32/process.c @@ -317,3 +317,20 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags) strncpy(sp->comm, pe.szExeFile, COMM_LEN); return sp; } + +int kill(pid_t pid, int sig) +{ + HANDLE h; + + if (sig != SIGTERM) { + bb_error_msg("kill only supports SIGTERM"); + errno = ENOSYS; + return -1; + } + h = OpenProcess(PROCESS_TERMINATE, FALSE, pid); + if (h == NULL) + return -1; + if (TerminateProcess(h, 0) == 0) + return -1; + return 0; +} -- cgit v1.2.3-55-g6feb