grub/grub-core/osdep/linux
Michael Chang 42acdd3b40 hostdisk: Set linux file descriptor to O_CLOEXEC as default
We are often bothered by this sort of lvm warning while running grub-install
every now and then:

  File descriptor 4 (/dev/vda1) leaked on vgs invocation. Parent PID 1991: /usr/sbin/grub2-install

The requirement related to the warning is dictated in the lvm man page:

  "On invocation, lvm requires that only the standard file descriptors stdin,
  stdout and stderr are available.  If others are found, they get closed and
  messages are issued warning about the leak.  This warning can be suppressed by
  setting the environment variable LVM_SUPPRESS_FD_WARNINGS."

While it could be disabled through settings, most Linux distributions seem to
enable it by default and the justification provided by the developer looks to
be valid to me: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=466138#15

Rather than trying to close and reopen the file descriptor to the same file
multiple times, which is rather cumbersome, for the sake of no vgs invocation
could happen in between. This patch enables the close-on-exec flag (O_CLOEXEC)
for new file descriptor returned by the open() system call, making it closed
thus not inherited by the child process forked and executed by the exec()
family of functions.

Fixes Debian bug #466138.

Signed-off-by: Michael Chang <mchang@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2019-11-18 13:42:55 +01:00
..
blocklist.c linux/blocklist: Fix memory leak. 2015-01-26 09:50:58 +01:00
emunet.c Split emunet into platform-dependent and GRUB-binding parts. Keep 2013-10-15 11:55:20 +02:00
getroot.c osdep/linux: handle autofs entries in /proc/self/mountinfo 2017-01-24 20:05:19 +03:00
hostdisk.c hostdisk: Set linux file descriptor to O_CLOEXEC as default 2019-11-18 13:42:55 +01:00
ofpath.c sparc64: Limit nvme of_path_of_nvme to just SPARC 2018-03-05 14:38:07 +01:00
platform.c grub-install: Check for arm-efi as a default target 2019-02-26 15:25:13 +01:00