Skip to contentSkip to conversation

oe-pkgdata-util: ignore SIGPIPE

PATCH Chen Qi 1 participant 1 message Apr 27, 2021 1 message not in the archive

lore
Share & tools
lore

Chen Qi

author
#1 lore raw
In reply to a message not in the archive

ping

Quoted 40 lines · Chen Qi

oe-pkgdata-util sometimes outputs a large amount of data. When used with pipe, it's likely to get the following error.

BrokenPipeError: [Errno 32] Broken pipe

The problem could be reproduced by running `oe-pkgdata-util list-pkg | less'. Type 'q' after running the above command, and we get the error.

---
  scripts/oe-pkgdata-util | 5 +++++
  1 file changed, 5 insertions(+)
scripts/oe-pkgdata-util +5 -0
index 75dd23efa3..4aeb28879d 100755
@@ -17,6 +17,7 @@ import re
  import argparse
  import logging
  from collections import defaultdict, OrderedDict
+from signal import signal, SIGPIPE, SIG_DFL
 
  scripts_path = os.path.dirname(os.path.realpath(__file__))
  lib_path = scripts_path + '/lib'
@@ -615,6 +616,10 @@ def main():
          logger.error('Unable to find pkgdata directory %s' % args.pkgdata_dir)
          sys.exit(1)
 
+    # It's possible that this program will output large contents, and when used with a pipe in command line,
+    # we will get a 'BrokenPipeError: [Errno 32] Broken pipe'. Ignore the SIGPIPE to avoid such error.
+    signal(SIGPIPE, SIG_DFL)
+
      ret = args.func(args)
 
      return ret