[comp.bugs.sys5] libPW.a

lml@cbnews.ATT.COM (L. Mark Larsen) (03/30/89)

With SVR3.0, libPW.a(curdir.o) uses a new algorithm that doesn't chdir().
Unfortunately, a small bug was introduced which causes each invocation
of curdir() to leave open an extra file descriptor.  If you use something
like build, which calls curdir() twice and usually is fork'd several
levels deep, you quickly run out of file descriptors for the real work.
For those with source, the solution is to add a call to closedir() just
before the return when identical() returns true:
	if( identical( &cdirectory, sbp ) ) {
 		closedir( cdp );	/* missing call in original source */
		stradd( str, "/" );
		return  str;
	}

For those without source, you could always use a pre-SVR3.0 version with
the old algorithm - it worked fine.

L. Mark Larsen
att!atlas!lml
lml@atlas.ATT.COM

dag@fciva.FRANKLIN.COM (Daniel A. Graifer) (03/31/89)

In article <5226@cbnews.ATT.COM> lml@cbnews.ATT.COM (L. Mark Larsen) writes:
>With SVR3.0, libPW.a(curdir.o) uses a new algorithm that doesn't chdir().
>Unfortunately, a small bug was introduced
>...[discussion of bug, and source patch to fix]
>L. Mark Larsen
>att!atlas!lml
>lml@atlas.ATT.COM

Has this been fixed in more recent releases?  I don't have source but we are
about to move from SVR3.0 to 3.1.  It would be nice if this were fixed.  I am
also about to buy a new 386 machine with 3.2.  What about that release?

Thanks in advance...
Dan

guy@auspex.UUCP (Guy Harris) (03/31/89)

>For those without source, you could always use a pre-SVR3.0 version with
>the old algorithm - it worked fine.

Or else:

	1) Use the implementation of "getcwd" that comes with S5R3 (or
	   R2, or...) if you're willing to put up with a "fork" and
	   "exec" of "/bin/pwd" per access

or

	2) grab the source to "getwd" from 4.3BSD and modify it slightly
	   to have the interface of "getcwd" (and not to use "lstat", if
	   you don't have it).

This:

	1) helps remove dependencies on the undocumented "-lPW" library,
	   and helps move that library towards the Elephant's Graveyard

and

	2) helps move your code towards being a SVID-compliant application.

"-lPW - just say no!"

lml@cbnews.ATT.COM (L. Mark Larsen) (04/02/89)

In article <461@fciva.FRANKLIN.COM> dag@fciva.UUCP (Daniel A. Graifer) writes:
#Has this been fixed in more recent releases?  I don't have source but we are
#about to move from SVR3.0 to 3.1.  It would be nice if this were fixed.  I am
#also about to buy a new 386 machine with 3.2.  What about that release?

(I tried mailing this but it bounced.)
As near as I can determine, SVR3.1 has the same bug.  I don't have the SVR3.2
source although I do have the source for the compiler (4.2) that comes with
3.2 and it has the bug too (sources for libraries are part of the compiler
package).  So, I wouldn't count on it being fixed anytime soon.  Of course,
as was pointed out, there are other alternatives.  If you are writing something
that would use this function, I suppose you could work around the bug by
explicitly closing the (n + 1)th file descriptor known to be in use, right
after the call to curdir().

cheers,
L. Mark Larsen
lml@atlas.ATT.COM
att!atlas!lml