[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#764204: apt-cache calls fcntl() on 65536 FDs



Hi,

just looked into this, apparently the calls originate in the ExecFork
function in apt-pkg/contrib/fileutl.cc, lines 760-792 (as of commit
15901516).

Michael Vogt seems to have increased the number of file descriptors
that are closed from 40 to sysconf(_SC_OPEN_MAX) in Git commit
61f954bf. (While the 65535 calls to getrlimit have been reduced to 1
in the latest Git version, the fcntl problem remains.)

The code fragment in question seems to have been introduced in the
early days of apt (April 1999) by Jason Gunthorpe:

commit 54676e1a82f400e37879bc931b6db0c13b8ebb3f
Author: Arch Librarian <arch@canonical.com>
Date:   Mon Sep 20 16:53:38 2004 +0000
    Working apt-get source build stuff
    Author: jgg
    Date: 1999-04-20 05:02:09 GMT
    Working apt-get source build stuff

// Close all of our FDs - just in case
for (int K = 3; K != 40; K++)
  fcntl(K,F_SETFD,FD_CLOEXEC);

I am not familiar enough with the apt codebase to understand the need
to close all file descriptors. Would it be ok to only close the fds
listed in /proc/self/fd/ as suggested by Julian Andres Klode?

Best,
Sebastian


Reply to: