From f1ee022fd07e7ffebb29158c296b7e15f46e30d3 Mon Sep 17 00:00:00 2001 From: Paul Lietar Date: Wed, 19 Jun 2013 10:22:51 +0200 Subject: [PATCH] pulseaudio: fix option parsing --- audio_pulse.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/audio_pulse.c b/audio_pulse.c index bb90c727..e6e797fd 100644 --- a/audio_pulse.c +++ b/audio_pulse.c @@ -46,7 +46,10 @@ static void help(void) { static int init(int argc, char **argv) { - optind = 0; + optind = 1; // optind=0 is equivalent to optind=1 plus special behaviour + argv--; // so we shift the arguments to satisfy getopt() + argc++; + // some platforms apparently require optreset = 1; - which? int opt; char *mid; @@ -64,6 +67,9 @@ static int init(int argc, char **argv) { } } + if (optind < argc) + die("Invalid audio argument: %s", argv[optind]); + return 0; } @@ -77,7 +83,14 @@ static void start(int sample_rate) { .channels = 2 }; - pa_dev = pa_simple_new(pa_server, "shairport", PA_STREAM_PLAYBACK, pa_sink, "shairport", &ss, NULL, NULL, &pa_error); + pa_dev = pa_simple_new(pa_server, + "shairport", + PA_STREAM_PLAYBACK, + pa_sink, + "shairport", + &ss, NULL, NULL, + &pa_error); + if (!pa_dev) die("Could not connect to pulseaudio server: %s", pa_strerror(pa_error)); }