CyberPsychotic wrote:
> Here I was writing some code(just for testing purposes) which is supposed
> to sit and listen to some certain port on machine, and when gets
> connection, just pass some text file there. (in attached file, apache's
> access_log file). Originally I was writing this on BSD machine(FreeBSD
> 2.2.5) and things worked just fine. I brought it to some linux(redhat 4.1
> kernel 2.0.29,libc 5.3.*) and weird things happen:
libc 5.3.* is a development version. You should install one of the
recent 5.4.* versions to eliminate that as a possible source of error.
> When I either compile it with loggin' mode (so file with fd=0 is opened)
> or run the code with -d switch (so it doesn't close stdin/stdout/stderr at
> all) things work just fine. (as on BSD), but when I compile it with no
> LOGGING and DEBUG mode, and run with no -d switch (so all file descriptors
> are closed). The code hangs up somewhere.(but port isn't listened). I run
> gdb attach process, and gdb says that code sits in accept function. I
> wonder if that's just Linux implementation of accept which would want
> descriptor=0 being opened or something?.. I attached both pieces of code,
> if anyone would want to play with it.
> while(1)
> {
> close(sock_a);
The first time that you get here, sock_a will have a random value, so
you don't want to close it here. You should close it in the parent
process after the fork().
> while(waitpid(-1, NULL, (int) NULL) > 0);
You should pass WNOHANG as the third argument to waitpid(), otherwise
this loop won't terminate.
Neither of these seem likely to cause accept() to fail to accept a
connection.
If I fix the above problems, it runs fine for me.
--
Glynn Clements <[EMAIL PROTECTED]>