grub/grub-core/osdep/unix
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
..
compress.c Rewrite grub-install, grub-mkrescue, grub-mkstandalone and grub-mknetdir 2013-11-16 20:21:16 +01:00
config.c * grub-core/osdep/unix/config.c: Remove extraneous comma. 2014-09-21 17:49:13 +02:00
cputime.c unix/cputime.c: Cache sc_clk_tck and check it for sanity. 2015-01-21 17:42:15 +01:00
dl.c Move OS-dependent mprotect for module loading to grub-core/osdep/*/dl.c 2013-12-08 18:08:23 +01:00
emuconsole.c * grub-core/osdep/unix/emuconsole.c (put): Pacify the compiler on 2013-11-13 13:34:57 +00:00
exec.c unix exec: avoid atexit handlers when child exits 2017-08-30 15:20:13 +02:00
getroot.c getroot: Save/restore CWD more reliably on Unix 2019-03-19 11:23:22 +01:00
hostdisk.c hostdisk: Set linux file descriptor to O_CLOEXEC as default 2019-11-18 13:42:55 +01:00
password.c unix: do not close stdin in grub_passwd_get 2015-11-18 22:23:58 +03:00
platform.c unix/platform: Initialize variable to fix grub-install on UEFI system 2018-11-09 13:34:16 +01:00
random.c Add a wrapper for fopen. On unix-like systems just pass-through. On 2013-10-13 20:36:28 +02:00
relpath.c unix/relpath: memory leak 2015-06-19 18:38:25 +03:00
sleep.c Move sleep routines to grub-core/osdep. 2013-10-08 17:38:46 +02:00