Re: sqlexit funny behavior
Posted in 1997
andy lennard wrote: > > We had a similar problem, which was caused by opening a pipe after having > attached to a database. > > Normally sqlturbo is blocked on a read from the pipe it has > established with the client app. sqlexit closes this pipe at the > client end, sqlturbo gets an error and closes down. > > However, after our popen the fds have been duplicated in the forked > process (including the database connection) and the sqlturbo sits > waiting on this instead. No error is generated and so sqlexit hangs. ----------------------------------------------------------------------- int pid_i; int fd_vi[4]; pipe( fd_vi ); // do your error handling pipe( fd_vi + 2 ); close(fd_vi[ 0 ]); // The following is defined for UNIX close(fd_vi[ 1 ]); // An open() will always return the close(fd_vi[ 2 ]); // first unused channel. Now we now close(fd_vi[ 3 ]); // the channels. Informix will open // two pipes, one for reading, another // one for writing. EXEC SQL DATABASE ... ; if ( ( pid_i = fork() ) == 0 ) { // that's just another way to close the connection // to your sqlturbo process. I'm not sure, but I // think it will work; close( fd_vi[3] ); close( fd_vi[2] ); close( fd_vi[1] ); close( fd_vi[0] ); // The sqlturbo will never get an EOF, unless all // open writing file descriptors are closed. // That's what we did above. There were two reading // file descriptors, but I don't want to look, how // Informix is using it's pipes. ... do whatever you want. // There are special functions in ESQL/C like // sqlquit(), which do exactly the same. But if // you don't trust in this functions, use the code // above. } else if ( pid _i > 0 ) { // The parent process will still have it's open // connection to the sqlturbo. } > The fix was to either to pclose before sqlexit, or re-do popen to close > unnecessary fds. > > Hope that helps. > > Andy. > > > > > We have several server-type applications when started, open a database, > > read tables for initialization, close the database via E/SQL and then > > remain idle for hours or days until called upon. This situation seemed > > perfect for sqlexit to free the database resources used during > > initialization. When the servers' initialization are finished, sqlexit is > > called after the CLOSE DATABASE statement. > > > > The problem appears when the server wakes up, does its work, closes > > the database and then calls sqlexit for the second time. From the > > debugger, the server goes into an infinite loop inside sqlexit. The > > stack track shows an infinite loop in the following routines: > > > > sqlexit > > killbackend > > wait > > _wait_sys > > $cerror > > > > The ESQL product is INFORMIX-ESQL Version 5.03.UC1 > > The On-Line server is RSAM Version 5.03.UC1 > > The hardware and OS are HP-UX 09.01 A 9000/755 and > > HP-UX 10.20 A 9000/755. > > > > The sqlexit routine would be a very nice thing to have working > > properly in these server applications. What I am doing wrong? > > > > Any help and/or advice would be appreciated on this. > > > > Thanks! > > > > mgo > > > > -------------------==== Posted via Deja News ====----------------------- > > http://www.dejanews.com/ Search, Read, Post to Usenet > > > > -- > =-~-=-~-=-~-=-~-=-~-=-~-=-~-=-~-=-~-=-~-=-~-=-~-=-~-=-~-=-~-=-~-= > Andy Lennard andy@kontron.demon.co.uk > =-~-=-~-=-~-=-~-=-~-=-~-=-~-=-~-=-~-=-~-=-~-=-~-=-~-=-~-=-~-=-~-=