From 2856dab4770e521a87c18b04ae8ebc209a9b95f9 Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Sun, 1 Apr 2007 01:18:20 +0000 Subject: tcpsvd: new applet It's a GPL-ed 'clone' of Dan Bernstein's tcpserver. Author: Gerrit Pape http://smarden.sunsite.dk/ipsvd/ size tcpsvd.o text data bss dec hex filename 2571 4 16 2591 a1f tcpsvd.o --- libbb/xconnect.c | 12 +++++------- libbb/xfuncs.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 7 deletions(-) (limited to 'libbb') diff --git a/libbb/xconnect.c b/libbb/xconnect.c index 118fe3e..a331e6b 100644 --- a/libbb/xconnect.c +++ b/libbb/xconnect.c @@ -82,15 +82,15 @@ int xconnect_tcp_v4(struct sockaddr_in *s_addr) /* "New" networking API */ -int get_nport(const len_and_sockaddr *lsa) +int get_nport(const struct sockaddr *sa) { #if ENABLE_FEATURE_IPV6 - if (lsa->sa.sa_family == AF_INET6) { - return lsa->sin6.sin6_port; + if (sa->sa_family == AF_INET6) { + return ((struct sockaddr_in6*)sa)->sin6_port; } #endif - if (lsa->sa.sa_family == AF_INET) { - return lsa->sin.sin_port; + if (sa->sa_family == AF_INET) { + return ((struct sockaddr_in*)sa)->sin_port; } /* What? UNIX socket? IPX?? :) */ return -1; @@ -308,12 +308,10 @@ char* xmalloc_sockaddr2host(const struct sockaddr *sa, socklen_t salen) return sockaddr2str(sa, salen, 0); } -/* Unused char* xmalloc_sockaddr2host_noport(const struct sockaddr *sa, socklen_t salen) { return sockaddr2str(sa, salen, IGNORE_PORT); } -*/ char* xmalloc_sockaddr2hostonly_noport(const struct sockaddr *sa, socklen_t salen) { diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index 68ad3de..b08f92d 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c @@ -205,6 +205,63 @@ int wait4pid(int pid) return 0; } +int wait_nohang(int *wstat) +{ + return waitpid(-1, wstat, WNOHANG); +} + +int wait_pid(int *wstat, int pid) +{ + int r; + + do + r = waitpid(pid, wstat, 0); + while ((r == -1) && (errno == EINTR)); + return r; +} + +void sig_block(int sig) +{ + sigset_t ss; + sigemptyset(&ss); + sigaddset(&ss, sig); + sigprocmask(SIG_BLOCK, &ss, NULL); +} + +void sig_unblock(int sig) +{ + sigset_t ss; + sigemptyset(&ss); + sigaddset(&ss, sig); + sigprocmask(SIG_UNBLOCK, &ss, NULL); +} + +#if 0 +void sig_blocknone(void) +{ + sigset_t ss; + sigemptyset(&ss); + sigprocmask(SIG_SETMASK, &ss, NULL); +} +#endif + +void sig_catch(int sig, void (*f)(int)) +{ + struct sigaction sa; + sa.sa_handler = f; + sa.sa_flags = 0; + sigemptyset(&sa.sa_mask); + sigaction(sig, &sa, NULL); +} + +void sig_pause(void) +{ + sigset_t ss; + sigemptyset(&ss); + sigsuspend(&ss); +} + + void xsetenv(const char *key, const char *value) { if (setenv(key, value, 1)) -- cgit v1.1