[Xapian-tickets] [Xapian] #337: Extend test of behaviour of databases after close

Xapian nobody at xapian.org
Mon Apr 30 05:58:57 BST 2018


#337: Extend test of behaviour of databases after close
------------------------+------------------------------
 Reporter:  richard     |             Owner:  gp1308
     Type:  defect      |            Status:  closed
 Priority:  low         |         Milestone:  1.4.6
Component:  Test Suite  |           Version:  SVN trunk
 Severity:  normal      |        Resolution:  fixed
 Keywords:              |        Blocked By:
 Blocking:              |  Operating System:  All
------------------------+------------------------------

Comment (by olly):

 Replying to [comment:24 gp1308]:
 > DIR is directory handler for `/proc/self/fd`, so fd returned by
 `dirfd()` will be corresponding to the opened directory. How is that
 useful? Would you elaborate a bit?

 The fdtracker gets run before and after each test and needs to record what
 fds are open, but in order to find out what fds are open it has to call
 `opendir()`, and doing that opens another fd.  So without extra care we'd
 note that fd as being open too, when it's really just an artefact of how
 we determine which fds are open.

 So what I was saying is we ought to call `dirfd()` on the `DIR*` we get
 from `opendir()` and then exclude that from the list of fds we get by
 calling `readdir()`.

 However, I missed that the fdtracker code actually keeps the `DIR*` open
 while the testcase runs, and uses the same `DIR*` for the pre- and post-
 testcase fd enumeration.  It still gets an extra fd in its list, but
 that's harmless because it's there and the same fd both before and after,
 so it will be quietly ignored like any already open fd (e.g. 0, 1, 2 will
 be open for stdin, stdout, stderr).  We are only interested in finding
 leaked fds - i.e. those which a testcase opens but fails to close.

 > You may be talking in the context of getting fds to close db files? In
 that case `close(dirfd(DIR)` closes all files right?

 In the context of closing fds for a database we definitely '''SHOULD
 NOT''' close `dirfd(DIR)` - that would be undefined behaviour, see
 http://pubs.opengroup.org/onlinepubs/9699919799/functions/dirfd.html :

   The dirfd() function shall return a file descriptor referring to the
 same directory as the dirp argument. This file descriptor shall be closed
 by a call to closedir(). If any attempt is made to close the file
 descriptor, or to modify the state of the associated description, other
 than by means of closedir(), readdir(), readdir_r(), rewinddir(), or
 seekdir(), the behavior is undefined.

--
Ticket URL: <https://trac.xapian.org/ticket/337#comment:26>
Xapian <https://xapian.org/>
Xapian



More information about the Xapian-tickets mailing list