From: Andre Noll <maan@tuebingen.mpg.de>
Date: Mon, 19 Jan 2015 20:17:20 +0000 (+0100)
Subject: gui.c Fix error handling of for_each_stat_item().
X-Git-Tag: v0.5.4~6
X-Git-Url: https://git.tue.mpg.de/?a=commitdiff_plain;h=1aef9e5556484d0a2d44370b88121310a8081725;p=paraslash.git

gui.c Fix error handling of for_each_stat_item().

In status_post_select(), if read_nonblock() succeeds (ret >= 0)
but for_each_stat_item() fails (ret2 < 0), para_gui aborts with

	para_gui: error.h:639: para_strerror: Assertion `num > 0' failed.

This happens for example if the user is not allowed to connect to
para_audiod.

The problem is that the (non-positive) value -ret is passed to
para_strerror() as the error code rather than -ret2. This commit
fixes the bug. It was introduced one year ago in commit f840be8d
(gui: Introduce status_post_select()).
---

diff --git a/gui.c b/gui.c
index 552b625b..370c731c 100644
--- a/gui.c
+++ b/gui.c
@@ -659,7 +659,8 @@ static int status_post_select(struct sched *s, void *context)
 	ret2 = for_each_stat_item(st->buf, st->loaded, update_item);
 	if (ret < 0 || ret2 < 0) {
 		st->loaded = 0;
-		PARA_NOTICE_LOG("closing stat pipe: %s\n", para_strerror(-ret));
+		PARA_NOTICE_LOG("closing stat pipe: %s\n",
+			para_strerror(ret < 0? -ret : -ret2));
 		close(st->fd);
 		st->fd = -1;
 		clear_all_items();