make is holding a directory open

Robert Mecklenburg mecklen@cimsoft.com
Wed Jun 25 21:42:00 GMT 2003


I seem to be having a subtle issue with make under cygwin.  The
problem appears to be that make is "improperly" holding an open file
handle on a directory.  This prevents rm from deleting the directory
as part of a makefile action.  The actual problem occurs in a 4,700
line makefile which I've pared down (after many hours) to these 19
lines:

----- cut here -----
# make; make clean; make clean
# mkdir -p /tmp/a/b
# rm -rf /tmp/a
# rm: cannot remove directory `/tmp/a': Permission denied
# make: *** [clean] Error 1
# rm -rf /tmp/a

compile:
	mkdir -p /tmp/a/b

clean:
	rm -rf /tmp/a

define rule
c:
	$(wildcard /tmp/a/b)
endef

$(rule)
----- cut here -----

As the comment says, see the problem by executing it like this:

$ make
mkdir -p /tmp/a/b

$ make clean
rm -rf /tmp/a
rm: cannot remove directory `/tmp/a': Permission denied
make: *** [clean] Error 1

$ make clean
rm -rf /tmp/a

The "compile" rule simulates the essence of a java compile, the
following clean action deletes /tmp/a/b then fails because make is
holding a lock on /tmp/a.  A subsequent make clean succeeds because
/tmp/a/b no longer exists.

My theory is that when /tmp/a/b exists the $(wildcard /tmp/a/b) opens
/tmp/a and fails to close it.  When /tmp/a/b doesnot exist the file
/tmp/a is not held open.  I've used a utility called handle.exe from
sysinternals.com to verify that make has the /tmp/a handle open.

If I simplify the example in any of these ways the problem disappears:

1) Move the target c out of define rule to before $(rule)

2) Run "make compile clean" as a single invocation

3) Avoid define/endef by expanding the rule by hand

I've run strace on the "make clean" that fails.  Here is the actual rm
failure:

   30   19982 [main] rm 3596 normalize_posix_path: /c/work/bug = normalize_posix_path (/c/work/bug)
   29   20011 [main] rm 3596 chdir: 0 = chdir() cygheap->cwd.posix '/c/work/bug' native 'c:\work\bug'
   53   20064 [main] rm 3596 normalize_posix_path: src /tmp/a
   26   20090 [main] rm 3596 normalize_posix_path: /tmp/a = normalize_posix_path (/tmp/a)
   28   20118 [main] rm 3596 mount_info::conv_to_win32_path: conv_to_win32_path (/tmp/a)
   29   20147 [main] rm 3596 mount_info::cygdrive_win32_path: src '/tmp/a', dst ''
   31   20178 [main] rm 3596 set_flags: flags: binary (0x2)
   27   20205 [main] rm 3596 mount_info::conv_to_win32_path: src_path /tmp/a, dst C:\usr\cygwin\tmp\a, flags 0xA, rc 0
  106   20311 [main] rm 3596 symlink_info::check: not a symlink
   32   20343 [main] rm 3596 symlink_info::check: 0 = symlink.check (C:\usr\cygwin\tmp\a, 0x241F538) (0xA)
   30   20373 [main] rm 3596 path_conv::check: root_dir(C:\), this->path(C:\usr\cygwin\tmp\a), set_has_acls(8)
  103   20476 [main] rm 3596 seterrno_from_win_error: /netrel/src/cygwin-1.3.22-1/winsup/cygwin/dir.cc:332 windows error 32
   33   20509 [main] rm 3596 geterrno_from_win_error: windows error 32 == errno 13
   27   20536 [main] rm 3596 rmdir: -1 = rmdir (/tmp/a)

But I believe the actual problem is much farther "upstream" in make
and I couldn't determine where.  I've included the cygcheck output as
an attachment along with.  (I tried including the earlier strace
output but exceeded the 100k character limit.)

It turns out the message 

http://mail.gnu.org/archive/html/make-w32/2001-12/msg00000.html

indicates the bug occurred in 3.78.1 and 3.79.1 in the windows version
of make.  But the message is actually vague about whether this is a
win32 make or a cygwin make.  I have not yet found any follow-ups or
patches.

Comments or suggestions welcome.  
-- 
Robert
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: cygcheck.out
URL: <http://cygwin.com/pipermail/cygwin/attachments/20030625/4078b8d5/attachment.ksh>
-------------- next part --------------
--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


More information about the Cygwin mailing list