mirror of
https://github.com/psy0rz/zfs_autobackup.git
synced 2025-04-13 22:47:12 +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 hashlib
|
||||||
|
import sys
|
||||||
|
from builtins import BrokenPipeError
|
||||||
|
from signal import signal, SIGPIPE, SIG_DFL
|
||||||
|
|
||||||
from .ZfsNode import ZfsNode
|
from .ZfsNode import ZfsNode
|
||||||
from .util import *
|
from .util import *
|
||||||
@ -60,6 +64,10 @@ class ZfsCheck(CliBase):
|
|||||||
if not self.args.test:
|
if not self.args.test:
|
||||||
for (file, block, hash) in block_hash_tree(mnt, count, bs):
|
for (file, block, hash) in block_hash_tree(mnt, count, bs):
|
||||||
print("{}\t{}\t{}".format(file, block, hash))
|
print("{}\t{}\t{}".format(file, block, hash))
|
||||||
|
sys.stdout.flush() #important, to generate SIGPIPES on ssh disconnect
|
||||||
|
|
||||||
|
except BrokenPipeError:
|
||||||
|
output_redir()
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
snapshot.unmount()
|
snapshot.unmount()
|
||||||
@ -110,14 +118,17 @@ class ZfsCheck(CliBase):
|
|||||||
if not self.args.test:
|
if not self.args.test:
|
||||||
for (block, hash) in block_hash(dev, count, bs):
|
for (block, hash) in block_hash(dev, count, bs):
|
||||||
print("{}\t{}".format(block, hash))
|
print("{}\t{}".format(block, hash))
|
||||||
|
sys.stdout.flush() #important, to generate SIGPIPES on ssh disconnect
|
||||||
|
|
||||||
|
except BrokenPipeError:
|
||||||
|
output_redir()
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
|
||||||
self.deacitvate_volume_snapshot(snapshot)
|
self.deacitvate_volume_snapshot(snapshot)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|
||||||
|
|
||||||
snapshot = self.node.get_dataset(self.args.snapshot)
|
snapshot = self.node.get_dataset(self.args.snapshot)
|
||||||
|
|
||||||
if not snapshot.exists:
|
if not snapshot.exists:
|
||||||
@ -147,4 +158,25 @@ def cli():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
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()
|
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