All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] set linux file descriptor to O_CLOEXEC as default
@ 2019-11-05  9:19 Michael Chang
  2019-11-05 12:07 ` Daniel Kiper
  0 siblings, 1 reply; 2+ messages in thread
From: Michael Chang @ 2019-11-05  9:19 UTC (permalink / raw)
  To: grub-devel

We are often bothered by this sort of lvm warning while running grub-install or
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 coulde 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.

Signed-off-by: Michael Chang <mchang@suse.com>
---
 grub-core/osdep/linux/hostdisk.c | 3 +++
 grub-core/osdep/unix/hostdisk.c  | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/grub-core/osdep/linux/hostdisk.c b/grub-core/osdep/linux/hostdisk.c
index 8b92f8528..da62f924e 100644
--- a/grub-core/osdep/linux/hostdisk.c
+++ b/grub-core/osdep/linux/hostdisk.c
@@ -366,6 +366,9 @@ grub_util_fd_open_device (const grub_disk_t disk, grub_disk_addr_t sector, int f
 #ifdef O_BINARY
   flags |= O_BINARY;
 #endif
+#ifdef O_CLOEXEC
+  flags |= O_CLOEXEC;
+#endif
 
   /* Linux has a bug that the disk cache for a whole disk is not consistent
      with the one for a partition of the disk.  */
diff --git a/grub-core/osdep/unix/hostdisk.c b/grub-core/osdep/unix/hostdisk.c
index 91150969b..3a00d7451 100644
--- a/grub-core/osdep/unix/hostdisk.c
+++ b/grub-core/osdep/unix/hostdisk.c
@@ -164,6 +164,9 @@ grub_util_fd_open (const char *os_dev, int flags)
 #ifdef O_BINARY
   flags |= O_BINARY;
 #endif
+#ifdef O_CLOEXEC
+  flags |= O_CLOEXEC;
+#endif
 
   return open (os_dev, flags, S_IROTH | S_IRGRP | S_IRUSR | S_IWUSR);
 }
-- 
2.16.4



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] set linux file descriptor to O_CLOEXEC as default
  2019-11-05  9:19 [PATCH] set linux file descriptor to O_CLOEXEC as default Michael Chang
@ 2019-11-05 12:07 ` Daniel Kiper
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Kiper @ 2019-11-05 12:07 UTC (permalink / raw)
  To: Michael Chang; +Cc: grub-devel

On Tue, Nov 05, 2019 at 09:19:26AM +0000, Michael Chang wrote:
> We are often bothered by this sort of lvm warning while running grub-install or
> 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 coulde 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.
>
> Signed-off-by: Michael Chang <mchang@suse.com>

Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>

Daniel


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-11-05 12:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-05  9:19 [PATCH] set linux file descriptor to O_CLOEXEC as default Michael Chang
2019-11-05 12:07 ` Daniel Kiper

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.