From 9c502016dfbcb18722409a1371a633f2903d6051 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20H=C3=BCbinette=20=28Hubbe=29?= <hubbe@hubbe.net> Date: Thu, 26 Mar 1998 18:17:33 -0800 Subject: [PATCH] bugfix Rev: src/configure.in:1.171 Rev: src/fd_control.c:1.16 --- src/configure.in | 5 +- src/fd_control.c | 175 ++++++++--------------------------------------- 2 files changed, 29 insertions(+), 151 deletions(-) diff --git a/src/configure.in b/src/configure.in index 4b939325a0..21423935e4 100644 --- a/src/configure.in +++ b/src/configure.in @@ -1,4 +1,4 @@ -AC_REVISION("$Id: configure.in,v 1.170 1998/03/26 03:10:36 hubbe Exp $") +AC_REVISION("$Id: configure.in,v 1.171 1998/03/27 02:17:32 hubbe Exp $") AC_INIT(interpret.c) AC_CONFIG_HEADER(machine.h) @@ -58,12 +58,10 @@ AC_MINIX LIBDIR=`(cd $srcdir/../lib ; pwd)` BINDIR=`(cd $srcdir/../bin ; pwd)` -DOCDIR=`(cd $srcdir/../doc ; pwd)` BUILDDIR=`pwd` AC_SUBST(LIBDIR) AC_SUBST(BINDIR) AC_SUBST(BUILDDIR) -AC_SUBST(DOCDIR) case $CC in *smartlink*) ;; @@ -998,6 +996,7 @@ AC_CHECK_FUNCS( \ getpwent getpwnam getpwuid \ getgrent getgrnam \ initgroups setgroups \ + socketpair \ ) if test x$pike_cv_sys_os = xWindows_NT ; then diff --git a/src/fd_control.c b/src/fd_control.c index 4e26eef9b9..5bc5fd9024 100644 --- a/src/fd_control.c +++ b/src/fd_control.c @@ -3,15 +3,16 @@ ||| Pike is distributed as GPL (General Public License) ||| See the files COPYING and DISCLAIMER for more information. \*/ -#define _FILE_OFFSET_BITS 64 -#define _LARGEFILE_SOURCE -#include <sys/types.h> #ifndef TESTING #include "global.h" #include "error.h" #include "fdlib.h" #else +#define _FILE_OFFSET_BITS 64 +#define _LARGEFILE_SOURCE 1 +#define _LARGEFILE64_SOURCE 1 +#include <sys/types.h> #undef DEBUG #define fd_ioctl ioctl #endif @@ -119,6 +120,7 @@ int main() #else #include <signal.h> +#include <stdio.h> #include <errno.h> #ifdef HAVE_UNISTD_H #include <unistd.h> @@ -126,156 +128,28 @@ int main() /* a part of the autoconf thingy */ RETSIGTYPE sigalrm_handler0(int tmp) { exit(0); } -RETSIGTYPE sigalrm_handler1(int tmp) { exit(1); } - -/* Protected since errno may expand to a function call. */ -#ifndef errno -extern int errno; -#endif /* !errno */ - +RETSIGTYPE sigalrm_handler1(int tmp) +{ + fprintf(stderr,"Failed in alarm handler 1\n"); + exit(1); +} +#ifdef HAVE_SOCKETPAIR #ifdef HAVE_NETINET_IN_H #include <netinet/in.h> #endif - - - -int my_socketpair(int family, int type, int protocol, int sv[2]) -{ - static int fd=-1; - static struct sockaddr_in my_addr; - struct sockaddr_in addr,addr2; - int len; - - for(len=0;len<sizeof(struct sockaddr_in);len++) - ((char *)&addr)[len]=0; - - /* We lie, we actually create an AF_INET socket... */ - if(family != AF_UNIX || type != SOCK_STREAM) - { - errno=EINVAL; - return -1; - } - - if(fd==-1) - { - if((fd=socket(AF_INET, SOCK_STREAM, 0)) < 0) return -1; - - /* I wonder what is most common a loopback on ip# 127.0.0.1 or - * a loopback with the name "localhost"? - * Let's hope those few people who don't have socketpair have - * a loopback on 127.0.0.1 - */ - my_addr.sin_addr.s_addr=htonl(INADDR_ANY); - my_addr.sin_port=htons(0); - - /* Bind our sockets on any port */ - if(bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) - { - close(fd); - fd=-1; - return -1; - } - - /* Check what ports we got.. */ - len=sizeof(my_addr); - if(getsockname(fd,(struct sockaddr *)&my_addr,&len) < 0) - { - close(fd); - fd=-1; - return -1; - } - - /* Listen to connections on our new socket */ - if(listen(fd, 5) < 0) - { - close(fd); - fd=-1; - return -1; - } - } - - if((sv[1]=socket(AF_INET, SOCK_STREAM, 0)) <0) return -1; - - addr.sin_addr.s_addr=inet_addr("127.0.0.1"); - -/* set_nonblocking(sv[1],1); */ - - if(connect(sv[1], (struct sockaddr *)&my_addr, sizeof(my_addr)) < 0) - { - int tmp2; - for(tmp2=0;tmp2<20;tmp2++) - { - int tmp; - len=sizeof(addr); - tmp=accept(fd,(struct sockaddr *)&addr,&len); - - if(tmp!=-1) close(tmp); - if(connect(sv[1], (struct sockaddr *)&my_addr, sizeof(my_addr))>=0) - break; - } - if(tmp2>=20) - return -1; - } - - len=sizeof(addr); - if(getsockname(sv[1],(struct sockaddr *)&addr2,&len) < 0) return -1; - - /* Accept connection - * Make sure this connection was our OWN connection, - * otherwise some wizeguy could interfere with our - * pipe by guessing our socket and connecting at - * just the right time... Pike is supposed to be - * pretty safe... - */ - do - { - len=sizeof(addr); - sv[0]=accept(fd,(struct sockaddr *)&addr,&len); - - if(sv[0] < 0) { - close(sv[1]); - return -1; - } - - /* We do not trust accept */ - len=sizeof(addr); - if(getpeername(sv[0], (struct sockaddr *)&addr,&len)) return -1; - }while(len < (int)sizeof(addr) || - addr2.sin_addr.s_addr != addr.sin_addr.s_addr || - addr2.sin_port != addr.sin_port); - -/* set_nonblocking(sv[1],0); */ - - return 0; -} - -int socketpair_ultra(int family, int type, int protocol, int sv[2]) -{ - int retries=0; - - while(1) - { - int ret=my_socketpair(family, type, protocol, sv); - if(ret>=0) return ret; - - switch(errno) - { - case EAGAIN: break; - -#ifdef EADDRINUSE - case EADDRINUSE: +#ifdef HAVE_WINSOCK_H +#include <winsock.h> #endif - -#ifdef WSAEADDRINUSE - if(retries++ > 10) return ret; - break; +#ifdef HAVE_ARPA_INET_H +#include <arpa/inet.h> #endif - - default: - return ret; - } - } -} +#ifdef HAVE_ARPA_INET_H +#include <arpa/inet.h> +#endif +#ifdef HAVE_SYS_SOCKET_H +#include <sys/socket.h> +#endif +#endif /* HAVE_SOCKETPAIR */ int main() { @@ -284,6 +158,10 @@ int main() tmp[0]=0; tmp[1]=0; +#ifdef HAVE_SOCKETPAIR + if(socketpair(AF_UNIX, SOCK_STREAM, 0, tmp) < 0) + tmp[0]=tmp[1]=0; +#endif set_nonblocking(tmp[0],1); signal(SIGALRM, sigalrm_handler1); @@ -293,6 +171,7 @@ int main() signal(SIGALRM, sigalrm_handler0); alarm(1); read(tmp[0],foo,999); + fprintf(stderr,"Failed at end of main.\n"); exit(1); } #endif -- GitLab