|
From: Roberto D. <rd...@ti...> - 2006-02-28 10:10:33
|
Hi.
I have the following code:
....... this is inside a loop .............>
FD_SET (_pipeDesbloqueo[0], &listeners);
int pid = ::getpid ();
LOG_INFORMA << pid << ":Esperando conexiones entrantes en
select(2)\n";
int maxFd = ::sysconf (_SC_OPEN_MAX);
LOG_INFORMA << "maxFd: " << maxFd << "\n";
/* My problem is here */
rst = select (maxFd, &listeners, 0, 0, 0);
/* ................... */
// podemos haber sido interrumpidos por un SIGCHLD
if (rst < 0)
{
ErrNo e;
/* I get this line in an infinite loop */
LOG_DEBUG << "hemos retornado mal de select con rst: "
<< rst
<< " error: "
<< e
<< "\n";
continue;
}
.......
if I run my program under valgrind I get:
BrokerProcesos:1173:BrokerProcesos.cpp::443::debug::hemos retornado mal
de select con rst: -1 error: Bad address
BrokerProcesos:1173:BrokerProcesos.cpp::434::informa::1173:Esperando
conexiones entrantes en select(2)
BrokerProcesos.cpp::436::informa::maxFd: 65525
BrokerProcesos:1173:BrokerProcesos.cpp::443::debug::hemos retornado mal
de select con rst: -1 error: Bad address
BrokerProcesos:1173:BrokerProcesos.cpp::434::informa::1173:Esperando
conexiones entrantes en select(2)
BrokerProcesos.cpp::436::informa::maxFd: 65525
BrokerProcesos:1173:BrokerProcesos.cpp::443::debug::hemos retornado mal
de select con rst: -1 error: Bad address
BrokerProcesos:1173:BrokerProcesos.cpp::434::informa::1173:Esperando
conexiones entrantes en select(2)
BrokerProcesos.cpp::436::informa::maxFd: 65525
BrokerProcesos:1173:BrokerProcesos.cpp::443::debug::hemos retornado mal
de select con rst: -1 error: Bad address
BrokerProcesos:1173:BrokerProcesos.cpp::434::informa::1173:Esperando
conexiones entrantes en select(2)
BrokerProcesos.cpp::436::informa::maxFd: 65525
BrokerProcesos:1173:BrokerProcesos.cpp::443::debug::hemos retornado mal
de select con rst: -1 error: Bad address
BrokerProcesos:1173:BrokerProcesos.cpp::434::informa::1173:Esperando
conexiones entrantes en select(2)
BrokerProcesos.cpp::436::informa::maxFd: 65525
select is returning always with errno set to Bad address..
The program outside valgrind runs ok..
any help will be quite appreciated
Thanks in advance.
Roberto.
|
|
From: Dirk M. <dm...@gm...> - 2006-02-28 11:21:52
|
On Tuesday, 28. February 2006 11:03, Roberto Diaz wrote: > I have the following code: can you please post a compileable example? > int maxFd = ::sysconf (_SC_OPEN_MAX); > rst = select (maxFd, &listeners, 0, 0, 0); > /* ................... */ I believe the problem is here. The first parameter should be the number of the most important set bit in the listeners bitfield, not some arbitrary large number you found somewhere else. Most likely maxFd for you is massively bigger than the sizeof(listeners) (multiplied by 8). Therefore, you cause the kernel to overrun a buffer, which it complains about. Dirk |
|
From: Roberto D. <rd...@ti...> - 2006-02-28 11:33:08
|
I can not try to fix this right now.. but I think I changed it some d= ays ago and the problem was not there... Anyway I will try out again.. I will tell you. El mar, 28-02-2006 a las 12:21, Dirk Mueller escribi=F3: > On Tuesday, 28. February 2006 11:03, Roberto Diaz wrote: >=20 > > I have the following code: >=20 > can you please post a compileable example? >=20 > > int maxFd =3D ::sysconf (_SC_OPEN_MAX); > > rst =3D select (maxFd, &listeners, 0, 0, 0); > > /* ................... */ >=20 > I believe the problem is here. The first parameter should be the nu= mber of the=20 > most important set bit in the listeners bitfield, not some arbitrar= y large=20 > number you found somewhere else. Most likely maxFd for you is massi= vely=20 > bigger than the sizeof(listeners) (multiplied by 8). Therefore, you= cause the=20 > kernel to overrun a buffer, which it complains about.=20 >=20 >=20 > Dirk |
|
From: Dirk M. <dm...@gm...> - 2006-02-28 12:16:11
|
On Tuesday, 28. February 2006 12:33, Roberto Diaz wrote: > I can not try to fix this right now.. but I think I changed it some days > ago and the problem was not there... I'm quite confident that this is (one of the) issues you're seeing. Just make maxFD reasonable. Dirk |
|
From: Olly B. <ol...@su...> - 2006-02-28 13:18:43
|
On 2006-02-28, Dirk Mueller <dm...@gm...> wrote:
>> int maxFd = ::sysconf (_SC_OPEN_MAX);
>> rst = select (maxFd, &listeners, 0, 0, 0);
>
> I believe the problem is here. The first parameter should be the
> number of the most important set bit in the listeners bitfield
More precisely, it should be the largest fd in any of the 3 sets
*plus 1*.
If you're too slack to calculate this, FD_SETSIZE is the appropriate
"very large" value to use for this parameter since fds in an fd_set
must be < FD_SETSIZE.
Cheers,
Olly
|
|
From: Roberto D. <rd...@ti...> - 2006-03-01 07:52:08
|
Yes.. The problem was there.. I have fixed it.. sorry for the absurd error..=20 Thank you very much=20 Roberto. El mar, 28-02-2006 a las 12:21, Dirk Mueller escribi=F3: > On Tuesday, 28. February 2006 11:03, Roberto Diaz wrote: >=20 > > I have the following code: >=20 > can you please post a compileable example? >=20 > > int maxFd =3D ::sysconf (_SC_OPEN_MAX); > > rst =3D select (maxFd, &listeners, 0, 0, 0); > > /* ................... */ >=20 > I believe the problem is here. The first parameter should be the nu= mber of the=20 > most important set bit in the listeners bitfield, not some arbitrar= y large=20 > number you found somewhere else. Most likely maxFd for you is massi= vely=20 > bigger than the sizeof(listeners) (multiplied by 8). Therefore, you= cause the=20 > kernel to overrun a buffer, which it complains about.=20 >=20 >=20 > Dirk >=20 >=20 > ------------------------------------------------------- > This SF.Net email is sponsored by xPML, a groundbreaking scripting = language > that extends applications into web and mobile media. Attend the liv= e webcast > and join the prime developer group breaking into this new coding te= rritory! > http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D110944&bid=3D241720= &dat=3D121642 > _______________________________________________ > Valgrind-users mailing list > Val...@li... > https://lists.sourceforge.net/lists/listinfo/valgrind-users |