From ed6d013054f589f2999926b02f4ac6dc76c7fe91 Mon Sep 17 00:00:00 2001
From: Lars-Dominik Braun <lars@6xq.net>
Date: Sat, 31 Mar 2012 14:56:23 +0200
Subject: Warn if ctl is not a fifo

Ordinary files are not supported and cause problems, so close the fd and
print a warning instead. Thanks to Sergey Bronnikov for the initial
patch.
---
 src/main.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

(limited to 'src')

diff --git a/src/main.c b/src/main.c
index f431331..43f3ffc 100644
--- a/src/main.c
+++ b/src/main.c
@@ -369,9 +369,19 @@ int main (int argc, char **argv) {
 	assert (sizeof (app.input.fds) / sizeof (*app.input.fds) >= 2);
 	app.input.fds[1] = open (app.settings.fifo, O_RDWR);
 	if (app.input.fds[1] != -1) {
-		FD_SET(app.input.fds[1], &app.input.set);
-		BarUiMsg (&app.settings, MSG_INFO, "Control fifo at %s opened\n",
-				app.settings.fifo);
+		struct stat s;
+
+		/* check for file type, must be fifo */
+		fstat (app.input.fds[1], &s);
+		if (!S_ISFIFO (s.st_mode)) {
+			BarUiMsg (&app.settings, MSG_ERR, "File at %s is not a fifo\n", app.settings.fifo);
+			close (app.input.fds[1]);
+			app.input.fds[1] = -1;
+		} else {
+			FD_SET(app.input.fds[1], &app.input.set);
+			BarUiMsg (&app.settings, MSG_INFO, "Control fifo at %s opened\n",
+					app.settings.fifo);
+		}
 	}
 	app.input.maxfd = app.input.fds[0] > app.input.fds[1] ? app.input.fds[0] :
 			app.input.fds[1];
-- 
cgit v1.2.3