diff options
author | Jon Lund Steffensen <jonlst@gmail.com> | 2014-11-03 20:57:15 -0500 |
---|---|---|
committer | Jon Lund Steffensen <jonlst@gmail.com> | 2014-11-04 00:36:19 -0500 |
commit | c0940492ed90d71097107a66cf2b184ceaec0da6 (patch) | |
tree | 45eed64979915538f36898e11e9a1167cd383f6c /src/redshift-gtk/statusicon.py | |
parent | Fix #112: Do not buffer lines from child indefinitely (diff) | |
download | redshift-ng-c0940492ed90d71097107a66cf2b184ceaec0da6.tar.gz redshift-ng-c0940492ed90d71097107a66cf2b184ceaec0da6.tar.bz2 redshift-ng-c0940492ed90d71097107a66cf2b184ceaec0da6.tar.xz |
redshift-gtk: Forward errors from child to stderr
This requires that the stderr (and stdout) are emptied when the
child process exits, otherwise redshift-gtk will exit before the
error output is forwarded. Also, the '-v' parameter is moved to
the beginning of the command line to avoid error output including
this (e.g. `redshift-gtk -l` would complain about the missing
location provided `-v`).
Diffstat (limited to 'src/redshift-gtk/statusicon.py')
-rw-r--r-- | src/redshift-gtk/statusicon.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/redshift-gtk/statusicon.py b/src/redshift-gtk/statusicon.py index 04a944f..8bcc572 100644 --- a/src/redshift-gtk/statusicon.py +++ b/src/redshift-gtk/statusicon.py @@ -14,7 +14,7 @@ # You should have received a copy of the GNU General Public License # along with Redshift. If not, see <http://www.gnu.org/licenses/>. -# Copyright (c) 2013 Jon Lund Steffensen <jonlst@gmail.com> +# Copyright (c) 2013-2014 Jon Lund Steffensen <jonlst@gmail.com> '''GUI status icon for Redshift. @@ -58,7 +58,7 @@ class RedshiftStatusIcon(object): # Start redshift with arguments args.insert(0, os.path.join(defs.BINDIR, 'redshift')) if '-v' not in args: - args.append('-v') + args.insert(1, '-v') self.start_child_process(args) @@ -288,6 +288,15 @@ class RedshiftStatusIcon(object): os.kill(self.process[0], signal.SIGUSR1) def child_cb(self, pid, cond, data=None): + # Empty stdout and stderr + for f, dest in ((self.process[2], sys.stdout), + (self.process[3], sys.stderr)): + while True: + buf = os.read(f, 256).decode('utf-8') + if buf == '': + break + print(buf, end='', file=dest) + sys.exit(-1) def child_key_change_cb(self, key, value): @@ -320,6 +329,8 @@ class RedshiftStatusIcon(object): ib.buf = last if stdout: self.child_stdout_line_cb(first) + else: + print(first, file=sys.stderr) return True |