anarcat / bup

Very efficient backup system based on the git packfile format, providing fast incremental saves and global deduplication (among and within files, including virtual machine images). Current release is 0.25, and the development branch is master. Please post patches to the mailing list for discussion (see below).
Other
0 stars 0 forks source link

stdout/stderr handling is quirky #2

Open anarcat opened 10 years ago

anarcat commented 10 years ago

the way that bup handles stdout/stderr is a little exotic. it seems to reopen file descriptors under certain circumstances.

this makes it difficult to make subcommands that want to process logging or handle those file descriptors differently. for example, i worked on a wrapper for index/save that redirects stdout to /dev/null (if not verbose) and stderr to a file for logging.

this yields various errors in the logs:

close failed in file object destructor:
sys.excepthook is missing
lost sys.stderr

now this may be a bug in python itself: http://bugs.python.org/issue11380

but it's unclear to me while those file descriptors are being messed with.

anarcat commented 10 years ago

workaround:

diff --git a/main.py b/main.py
index 45a0e8a..e244da5 100755
--- a/main.py
+++ b/main.py
@@ -126,7 +126,7 @@ def subpath(s):
     usage('error: unknown command "%s"' % subcmd_name)

 already_fixed = atoi(os.environ.get('BUP_FORCE_TTY'))
-if subcmd_name in ['mux', 'ftp', 'help']:
+if subcmd_name in ['mux', 'ftp', 'help', 'cron']:
     already_fixed = True
 fix_stdout = not already_fixed and os.isatty(1)
 fix_stderr = not already_fixed and os.isatty(2)