public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
* [PATCH] isar-events: close /proc/mounts after cleanup
@ 2026-11-11 14:40 'Clara Kowalsky' via isar-users
  2026-11-19 17:02 ` Zhihang Wei
  0 siblings, 1 reply; 2+ messages in thread
From: 'Clara Kowalsky' via isar-users @ 2026-11-11 14:40 UTC (permalink / raw)
  To: isar-users; +Cc: Clara Kowalsky

When running a Python unittest that exercises the BuildCompleted
handler, a warning is emitted:

/isar/meta/classes-global/isar-events.bbclass:65:
  ResourceWarning: unclosed file <_io.TextIOWrapper name='/proc/mounts'
  mode='r' encoding='UTF-8'>

The BuildCompleted handler reads /proc/mounts using open() without
closing the file. Fix this by reading the mount entries within a
context manager for deterministic file closure.

Fixes: e596cdf97198 ("isar-events: Unhide mounts left behind")
Signed-off-by: Clara Kowalsky <clara.kowalsky@siemens.com>
---
 meta/classes-global/isar-events.bbclass | 37 +++++++++++++------------
 1 file changed, 19 insertions(+), 18 deletions(-)

diff --git a/meta/classes-global/isar-events.bbclass b/meta/classes-global/isar-events.bbclass
index 15bfdb99..1427bf64 100644
--- a/meta/classes-global/isar-events.bbclass
+++ b/meta/classes-global/isar-events.bbclass
@@ -65,24 +65,25 @@ python build_completed() {
 
     basepath = tmpdir + '/work/'
 
-    for line in reversed(list(open('/proc/mounts'))):
-        if basepath not in line:
-            continue
-        msg_line = f"{line.split()[1]} left mounted"
-        # If bitbake is started manually, bb.warn and bb.error go to stdout;
-        # with bb.error, bitbake additionally fails the build. Under CI,
-        # bb.warn and bb.error currently go to a file.
-        if fail_on_cleanup:
-            bb.error(msg_line)
-        else:
-            msg_line += ', unmounting...'
-            bb.warn(msg_line)
-            try:
-                subprocess.run(
-                    f"sudo umount {line.split()[1]}", shell=True, check=True
-                )
-            except subprocess.CalledProcessError as e:
-                bb.error(str(e))
+    with open('/proc/mounts') as mounts:
+        for line in reversed(mounts.readlines()):
+            if basepath not in line:
+                continue
+            msg_line = f"{line.split()[1]} left mounted"
+            # If bitbake is started manually, bb.warn and bb.error go to stdout;
+            # with bb.error, bitbake additionally fails the build. Under CI,
+            # bb.warn and bb.error currently go to a file.
+            if fail_on_cleanup:
+                bb.error(msg_line)
+            else:
+                msg_line += ', unmounting...'
+                bb.warn(msg_line)
+                try:
+                    subprocess.run(
+                        f"sudo umount {line.split()[1]}", shell=True, check=True
+                    )
+                except subprocess.CalledProcessError as e:
+                    bb.error(str(e))
 
     # Cleanup build UUID, the next bitbake run will generate new one
     bb.persist_data.persist('BB_ISAR_UUID_DATA', d).clear()
-- 
2.56.0

-- 
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/isar-users/20261111144025.2516053-1-clara.kowalsky%40siemens.com.

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

* Re: [PATCH] isar-events: close /proc/mounts after cleanup
  2026-11-11 14:40 [PATCH] isar-events: close /proc/mounts after cleanup 'Clara Kowalsky' via isar-users
@ 2026-11-19 17:02 ` Zhihang Wei
  0 siblings, 0 replies; 2+ messages in thread
From: Zhihang Wei @ 2026-11-19 17:02 UTC (permalink / raw)
  To: Clara Kowalsky, isar-users

Applied to next, thanks.

Zhihang

On 11/11/26 15:40, 'Clara Kowalsky' via isar-users wrote:
> When running a Python unittest that exercises the BuildCompleted
> handler, a warning is emitted:
>
> /isar/meta/classes-global/isar-events.bbclass:65:
>    ResourceWarning: unclosed file <_io.TextIOWrapper name='/proc/mounts'
>    mode='r' encoding='UTF-8'>
>
> The BuildCompleted handler reads /proc/mounts using open() without
> closing the file. Fix this by reading the mount entries within a
> context manager for deterministic file closure.
>
> Fixes: e596cdf97198 ("isar-events: Unhide mounts left behind")
> Signed-off-by: Clara Kowalsky <clara.kowalsky@siemens.com>
> ---
>   meta/classes-global/isar-events.bbclass | 37 +++++++++++++------------
>   1 file changed, 19 insertions(+), 18 deletions(-)
>
> diff --git a/meta/classes-global/isar-events.bbclass b/meta/classes-global/isar-events.bbclass
> index 15bfdb99..1427bf64 100644
> --- a/meta/classes-global/isar-events.bbclass
> +++ b/meta/classes-global/isar-events.bbclass
> @@ -65,24 +65,25 @@ python build_completed() {
>   
>       basepath = tmpdir + '/work/'
>   
> -    for line in reversed(list(open('/proc/mounts'))):
> -        if basepath not in line:
> -            continue
> -        msg_line = f"{line.split()[1]} left mounted"
> -        # If bitbake is started manually, bb.warn and bb.error go to stdout;
> -        # with bb.error, bitbake additionally fails the build. Under CI,
> -        # bb.warn and bb.error currently go to a file.
> -        if fail_on_cleanup:
> -            bb.error(msg_line)
> -        else:
> -            msg_line += ', unmounting...'
> -            bb.warn(msg_line)
> -            try:
> -                subprocess.run(
> -                    f"sudo umount {line.split()[1]}", shell=True, check=True
> -                )
> -            except subprocess.CalledProcessError as e:
> -                bb.error(str(e))
> +    with open('/proc/mounts') as mounts:
> +        for line in reversed(mounts.readlines()):
> +            if basepath not in line:
> +                continue
> +            msg_line = f"{line.split()[1]} left mounted"
> +            # If bitbake is started manually, bb.warn and bb.error go to stdout;
> +            # with bb.error, bitbake additionally fails the build. Under CI,
> +            # bb.warn and bb.error currently go to a file.
> +            if fail_on_cleanup:
> +                bb.error(msg_line)
> +            else:
> +                msg_line += ', unmounting...'
> +                bb.warn(msg_line)
> +                try:
> +                    subprocess.run(
> +                        f"sudo umount {line.split()[1]}", shell=True, check=True
> +                    )
> +                except subprocess.CalledProcessError as e:
> +                    bb.error(str(e))
>   
>       # Cleanup build UUID, the next bitbake run will generate new one
>       bb.persist_data.persist('BB_ISAR_UUID_DATA', d).clear()

-- 
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/isar-users/65d3c5c0-2975-43a8-b145-dc16f6bcc12b%40ilbers.de.

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

end of thread, other threads:[~2026-11-19 17:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-11 14:40 [PATCH] isar-events: close /proc/mounts after cleanup 'Clara Kowalsky' via isar-users
2026-11-19 17:02 ` Zhihang Wei

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox