mirror of
https://github.com/psy0rz/zfs_autobackup.git
synced 2025-04-11 22:40:01 +03:00
correct brokenpipe handling
This commit is contained in:
parent
2fe008acf5
commit
bb9ce25a37
@ -1,4 +1,8 @@
|
||||
from __future__ import print_function
|
||||
import hashlib
|
||||
import sys
|
||||
from builtins import BrokenPipeError
|
||||
from signal import signal, SIGPIPE, SIG_DFL
|
||||
|
||||
from .ZfsNode import ZfsNode
|
||||
from .util import *
|
||||
@ -60,6 +64,10 @@ class ZfsCheck(CliBase):
|
||||
if not self.args.test:
|
||||
for (file, block, hash) in block_hash_tree(mnt, count, bs):
|
||||
print("{}\t{}\t{}".format(file, block, hash))
|
||||
sys.stdout.flush() #important, to generate SIGPIPES on ssh disconnect
|
||||
|
||||
except BrokenPipeError:
|
||||
output_redir()
|
||||
|
||||
finally:
|
||||
snapshot.unmount()
|
||||
@ -110,14 +118,17 @@ class ZfsCheck(CliBase):
|
||||
if not self.args.test:
|
||||
for (block, hash) in block_hash(dev, count, bs):
|
||||
print("{}\t{}".format(block, hash))
|
||||
sys.stdout.flush() #important, to generate SIGPIPES on ssh disconnect
|
||||
|
||||
except BrokenPipeError:
|
||||
output_redir()
|
||||
|
||||
finally:
|
||||
|
||||
self.deacitvate_volume_snapshot(snapshot)
|
||||
|
||||
def run(self):
|
||||
|
||||
|
||||
snapshot = self.node.get_dataset(self.args.snapshot)
|
||||
|
||||
if not snapshot.exists:
|
||||
@ -147,4 +158,25 @@ def cli():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# try:
|
||||
# while True:
|
||||
# # print("stderr", file=sys.stderr)
|
||||
# print("loop")
|
||||
# sys.stdout.flush()
|
||||
#
|
||||
# except BrokenPipeError:
|
||||
# output_redir()
|
||||
# print("pipe brookn", file=sys.stderr)
|
||||
# sys.stderr.flush()
|
||||
#
|
||||
# devnull = os.open(os.devnull, os.O_WRONLY)
|
||||
# os.dup2(devnull, sys.stdout.fileno())
|
||||
#
|
||||
# print("stout")
|
||||
# sys.stdout.flush()
|
||||
#
|
||||
#
|
||||
# print("hier kom ik nie", file=sys.stderr)
|
||||
# open("yo" ,"w")
|
||||
|
||||
cli()
|
||||
|
@ -78,3 +78,12 @@ def get_tmp_clone_name(snapshot):
|
||||
|
||||
|
||||
|
||||
def output_redir():
|
||||
"""use this after a BrokenPipeError to prevent further exceptions.
|
||||
Redirects stdout/err to /dev/null
|
||||
"""
|
||||
|
||||
devnull = os.open(os.devnull, os.O_WRONLY)
|
||||
os.dup2(devnull, sys.stdout.fileno())
|
||||
os.dup2(devnull, sys.stderr.fileno())
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user