diff options
author | Ron Yorston <rmy@pobox.com> | 2020-04-05 09:49:57 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2020-04-05 10:04:56 +0100 |
commit | 2b4c25bd2cac034cdc52d29d6bb8c675c87a731c (patch) | |
tree | 5f542026304bb44ce738226acecfb9a9a0c84e8f | |
parent | 1365eb25a7dfd3e42229691355d910ff32b92361 (diff) | |
download | busybox-w32-2b4c25bd2cac034cdc52d29d6bb8c675c87a731c.tar.gz busybox-w32-2b4c25bd2cac034cdc52d29d6bb8c675c87a731c.tar.bz2 busybox-w32-2b4c25bd2cac034cdc52d29d6bb8c675c87a731c.zip |
win32: new functions: getpeername(2), mingw_spawn_detach()
Implement getpeername(2).
Add mingw_spawn_detach() to allow the spawned process to detach from
the console.
-rw-r--r-- | include/mingw.h | 3 | ||||
-rw-r--r-- | win32/net.c | 12 | ||||
-rw-r--r-- | win32/process.c | 18 |
3 files changed, 30 insertions, 3 deletions
diff --git a/include/mingw.h b/include/mingw.h index a5a84cff2..3d0daee38 100644 --- a/include/mingw.h +++ b/include/mingw.h | |||
@@ -228,6 +228,7 @@ int mingw_listen(int sockfd, int backlog); | |||
228 | int mingw_accept(int sockfd1, struct sockaddr *sa, socklen_t *sz); | 228 | int mingw_accept(int sockfd1, struct sockaddr *sa, socklen_t *sz); |
229 | int mingw_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds, | 229 | int mingw_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds, |
230 | struct timeval *timeout); | 230 | struct timeval *timeout); |
231 | int mingw_getpeername(int fd, struct sockaddr *sa, socklen_t *sz); | ||
231 | 232 | ||
232 | NOIMPL(mingw_sendto,SOCKET s UNUSED_PARAM, const char *buf UNUSED_PARAM, int len UNUSED_PARAM, int flags UNUSED_PARAM, const struct sockaddr *sa UNUSED_PARAM, int salen UNUSED_PARAM); | 233 | NOIMPL(mingw_sendto,SOCKET s UNUSED_PARAM, const char *buf UNUSED_PARAM, int len UNUSED_PARAM, int flags UNUSED_PARAM, const struct sockaddr *sa UNUSED_PARAM, int salen UNUSED_PARAM); |
233 | 234 | ||
@@ -240,6 +241,7 @@ NOIMPL(mingw_sendto,SOCKET s UNUSED_PARAM, const char *buf UNUSED_PARAM, int len | |||
240 | #define shutdown mingw_shutdown | 241 | #define shutdown mingw_shutdown |
241 | #define accept mingw_accept | 242 | #define accept mingw_accept |
242 | #define select mingw_select | 243 | #define select mingw_select |
244 | #define getpeername mingw_getpeername | ||
243 | 245 | ||
244 | /* | 246 | /* |
245 | * sys/time.h | 247 | * sys/time.h |
@@ -472,6 +474,7 @@ DIR *mingw_opendir(const char *path); | |||
472 | #define is_dir_sep(c) ((c) == '/' || (c) == '\\') | 474 | #define is_dir_sep(c) ((c) == '/' || (c) == '\\') |
473 | 475 | ||
474 | pid_t FAST_FUNC mingw_spawn(char **argv); | 476 | pid_t FAST_FUNC mingw_spawn(char **argv); |
477 | pid_t FAST_FUNC mingw_spawn_detach(char **argv); | ||
475 | intptr_t FAST_FUNC mingw_spawn_proc(const char **argv); | 478 | intptr_t FAST_FUNC mingw_spawn_proc(const char **argv); |
476 | int mingw_execv(const char *cmd, char *const *argv); | 479 | int mingw_execv(const char *cmd, char *const *argv); |
477 | int mingw_execvp(const char *cmd, char *const *argv); | 480 | int mingw_execvp(const char *cmd, char *const *argv); |
diff --git a/win32/net.c b/win32/net.c index 2341119b0..01fa16a4e 100644 --- a/win32/net.c +++ b/win32/net.c | |||
@@ -99,3 +99,15 @@ int mingw_accept(int sockfd1, struct sockaddr *sa, socklen_t *sz) | |||
99 | } | 99 | } |
100 | return sockfd2; | 100 | return sockfd2; |
101 | } | 101 | } |
102 | |||
103 | #undef getpeername | ||
104 | int mingw_getpeername(int fd, struct sockaddr *sa, socklen_t *sz) | ||
105 | { | ||
106 | SOCKET sock = (SOCKET)_get_osfhandle(fd); | ||
107 | |||
108 | if (sock == INVALID_SOCKET) { | ||
109 | errno = EBADF; | ||
110 | return -1; | ||
111 | } | ||
112 | return getpeername(sock, sa, sz); | ||
113 | } | ||
diff --git a/win32/process.c b/win32/process.c index 4257fd689..67ce3c100 100644 --- a/win32/process.c +++ b/win32/process.c | |||
@@ -334,16 +334,28 @@ mingw_spawn_1(int mode, const char *cmd, char *const *argv, char *const *envp) | |||
334 | return -1; | 334 | return -1; |
335 | } | 335 | } |
336 | 336 | ||
337 | pid_t FAST_FUNC | 337 | static pid_t |
338 | mingw_spawn(char **argv) | 338 | mingw_spawn_pid(int mode, char **argv) |
339 | { | 339 | { |
340 | intptr_t ret; | 340 | intptr_t ret; |
341 | 341 | ||
342 | ret = mingw_spawn_proc((const char **)argv); | 342 | ret = mingw_spawn_1(mode, argv[0], (char *const *)argv, environ); |
343 | 343 | ||
344 | return ret == -1 ? -1 : GetProcessId((HANDLE)ret); | 344 | return ret == -1 ? -1 : GetProcessId((HANDLE)ret); |
345 | } | 345 | } |
346 | 346 | ||
347 | pid_t FAST_FUNC | ||
348 | mingw_spawn(char **argv) | ||
349 | { | ||
350 | return mingw_spawn_pid(P_NOWAIT, argv); | ||
351 | } | ||
352 | |||
353 | pid_t FAST_FUNC | ||
354 | mingw_spawn_detach(char **argv) | ||
355 | { | ||
356 | return mingw_spawn_pid(P_DETACH, argv); | ||
357 | } | ||
358 | |||
347 | intptr_t FAST_FUNC | 359 | intptr_t FAST_FUNC |
348 | mingw_spawn_proc(const char **argv) | 360 | mingw_spawn_proc(const char **argv) |
349 | { | 361 | { |