diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2012-03-31 14:56:23 +0200 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2012-03-31 14:56:23 +0200 |
commit | ed6d013054f589f2999926b02f4ac6dc76c7fe91 (patch) | |
tree | f3b151f6dab423f74418d785654f2d0699e1ea28 /src | |
parent | 7d659d4bd624b3100b0c0852039648d7803cbaf9 (diff) | |
download | pianobar-ed6d013054f589f2999926b02f4ac6dc76c7fe91.tar.gz pianobar-ed6d013054f589f2999926b02f4ac6dc76c7fe91.tar.bz2 pianobar-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.c | 16 |
1 files changed, 13 insertions, 3 deletions
@@ -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]; |