|
From: Mukund S. <mu...@sh...> - 2004-01-08 06:16:58
|
Hi
I am trying to debug some large section of the code that
uses epoll. Unfortunately valgrind says epoll is an unimplemented system
call.=20
I have read the man page, tried to suppress the errors, but with no
success. Here is a sample code that causes the error.
=20
Error
=3D=3D23968=3D=3D Memcheck, a memory error detector for x86-linux.
=3D=3D23968=3D=3D Copyright (C) 2002-2003, and GNU GPL'd, by Julian =
Seward.
=3D=3D23968=3D=3D Using valgrind-2.1.0, a program supervision framework =
for
x86-linux.
=3D=3D23968=3D=3D Copyright (C) 2000-2003, and GNU GPL'd, by Julian =
Seward.
=3D=3D23968=3D=3D Estimated CPU clock rate is 2699 MHz
=3D=3D23968=3D=3D For more details, rerun with: -v
=3D=3D23968=3D=3D=20
--23968-- WARNING: unhandled syscall: 254
--23968-- Do not panic. You may be able to fix this easily.
--23968-- Read the file README_MISSING_SYSCALL_OR_IOCTL.
=3D=3D23968=3D=3D Invalid read of size 1
=3D=3D23968=3D=3D at 0x961D9A: strcmp (in /lib/ld-2.3.2.so)
=3D=3D23968=3D=3D by 0x40322499: dl_open_worker (in =
/lib/i686/libc-2.3.2.so)
=3D=3D23968=3D=3D by 0x95C735: _dl_catch_error_internal (in =
/lib/ld-2.3.2.so)
=3D=3D23968=3D=3D by 0x40322308: __GI__dl_open (in =
/lib/i686/libc-2.3.2.so)
=3D=3D23968=3D=3D Address 0xFFFFE210 is not stack'd, malloc'd or free'd
=3D=3D23968=3D=3D=20
=3D=3D23968=3D=3D Invalid read of size 1
=3D=3D23968=3D=3D at 0x961D9A: strcmp (in /lib/ld-2.3.2.so)
=3D=3D23968=3D=3D by 0x95C0FA: openaux (in /lib/ld-2.3.2.so)
=3D=3D23968=3D=3D by 0x95C735: _dl_catch_error_internal (in =
/lib/ld-2.3.2.so)
=3D=3D23968=3D=3D by 0x95BC80: _dl_map_object_deps_internal (in
/lib/ld-2.3.2.so)
=3D=3D23968=3D=3D Address 0xFFFFE210 is not stack'd, malloc'd or free'd
=3D=3D23968=3D=3D=20
=3D=3D23968=3D=3D Conditional jump or move depends on uninitialised =
value(s)
=3D=3D23968=3D=3D at 0x416C73FE: getanswer_r (in =
/lib/libnss_dns-2.3.2.so)
=3D=3D23968=3D=3D by 0x416C60B3: _nss_dns_gethostbyname2_r (in
/lib/libnss_dns-2.3.2.so)
=3D=3D23968=3D=3D by 0x416C62AB: _nss_dns_gethostbyname_r (in
/lib/libnss_dns-2.3.2.so)
=3D=3D23968=3D=3D by 0x40304CCA: gethostbyname_r@@GLIBC_2.1.2 (in
/lib/i686/libc-2.3.2.so)
=3D=3D23968=3D=3D=20
=3D=3D23968=3D=3D Conditional jump or move depends on uninitialised =
value(s)
=3D=3D23968=3D=3D at 0x416C7401: getanswer_r (in =
/lib/libnss_dns-2.3.2.so)
=3D=3D23968=3D=3D by 0x416C60B3: _nss_dns_gethostbyname2_r (in
/lib/libnss_dns-2.3.2.so)
=3D=3D23968=3D=3D by 0x416C62AB: _nss_dns_gethostbyname_r (in
/lib/libnss_dns-2.3.2.so)
=3D=3D23968=3D=3D by 0x40304CCA: gethostbyname_r@@GLIBC_2.1.2 (in
/lib/i686/libc-2.3.2.so)
--23968-- WARNING: unhandled syscall: 255
--23968-- Do not panic. You may be able to fix this easily.
--23968-- Read the file README_MISSING_SYSCALL_OR_IOCTL.
--23968-- WARNING: unhandled syscall: 256
--23968-- Do not panic. You may be able to fix this easily.
--23968-- Read the file README_MISSING_SYSCALL_OR_IOCTL.
=3D=3D23968=3D=3D Warning: invalid file descriptor -1 in syscall close()
=3D=3D23968=3D=3D=20
=3D=3D23968=3D=3D ERROR SUMMARY: 24 errors from 4 contexts (suppressed: =
5 from
1)
=3D=3D23968=3D=3D malloc/free: in use at exit: 0 bytes in 0 blocks.
=3D=3D23968=3D=3D malloc/free: 66 allocs, 66 frees, 5227 bytes =
allocated.
=3D=3D23968=3D=3D For a detailed leak analysis, rerun with: =
--leak-check=3Dyes
=3D=3D23968=3D=3D For counts of detected errors, rerun with: -v
=20
=20
Code
=3D=3D=3D=3D
=20
#include <sys/epoll.h>
#include <netdb.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
=20
#define MAX_BUFF_LEN 4096
#define MAX_EVENTS_SIZE 25
=20
int main() {
int ed =3D epoll_create(256);
char buf[MAX_BUFF_LEN];
char output_buff[MAX_BUFF_LEN];
struct epoll_event events[MAX_EVENTS_SIZE];
struct hostent hostEntity;
struct hostent *pResolvedHost;
struct sockaddr_in server;
int syserrno,i,numFds;
int sockfd;
struct epoll_event ev;
char data[] =3D"GET / HTTP/1.0\r\n\r\n";
int status =3D gethostbyname_r("www.yahoo.com",&hostEntity, buf,
MAX_BUFF_LEN,&pResolvedHost, &syserrno);
if (status !=3D 0) {
fprintf(stderr,"Cannot resolve the hostname. gethostbyname_r failed
");
exit(-1);
}
memset((char *) &server,0, sizeof(server));
memmove((char *) &server.sin_addr,
pResolvedHost->h_addr,pResolvedHost->h_length);
server.sin_family =3D pResolvedHost->h_addrtype;
server.sin_port =3D (unsigned short) htons( 80 );
=20
sockfd =3D socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
status =3D connect(sockfd,(struct sockaddr *)&server,sizeof(server));
if (status !=3D 0) {
fprintf(stderr,"Cannot connect to host \n");
}
write (sockfd,data,strlen(data));
=20
ev.events =3D EPOLLIN|EPOLLET;
ev.data.fd =3D sockfd;
status =3D epoll_ctl(ed,EPOLL_CTL_ADD,sockfd,&ev);
numFds =3D epoll_wait(ed, events,MAX_EVENTS_SIZE, -1);
for (i=3D0;i<numFds; i++) {
int len =3D0;
while ( (len =3Dread(events[i].data.fd,output_buff,MAX_BUFF_LEN)) >0 =
)
{
write(1,output_buff,len);
}
close(events[i].data.fd);
}
close(ed);
return 0;
}
=20
=20
=20
=20
=20
|