summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2012-03-31 14:56:23 +0200
committerLars-Dominik Braun <lars@6xq.net>2012-03-31 14:56:23 +0200
commited6d013054f589f2999926b02f4ac6dc76c7fe91 (patch)
treef3b151f6dab423f74418d785654f2d0699e1ea28 /src
parent7d659d4bd624b3100b0c0852039648d7803cbaf9 (diff)
downloadpianobar-windows-ed6d013054f589f2999926b02f4ac6dc76c7fe91.tar.gz
pianobar-windows-ed6d013054f589f2999926b02f4ac6dc76c7fe91.tar.bz2
pianobar-windows-ed6d013054f589f2999926b02f4ac6dc76c7fe91.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/main.c16
1 files changed, 13 insertions, 3 deletions
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];