diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2015-10-23 10:27:31 +0200 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2015-10-23 10:31:25 +0200 |
commit | 436a1d4012553a2f33d0e3a5180b3b5ae0378bdd (patch) | |
tree | 984f5007600dcf9029eaf8750740e10226196af1 /src/main.c | |
parent | af0f9d4bbff4f7a166c15df8c60ad61791740207 (diff) | |
download | pianobar-436a1d4012553a2f33d0e3a5180b3b5ae0378bdd.tar.gz pianobar-436a1d4012553a2f33d0e3a5180b3b5ae0378bdd.tar.bz2 pianobar-436a1d4012553a2f33d0e3a5180b3b5ae0378bdd.zip |
Interruptible requests
^C now works as expected: It interrupts API requests, input prompts and
audio streaming. Timeouts have been removed.
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 26 |
1 files changed, 25 insertions, 1 deletions
@@ -199,7 +199,7 @@ static void BarMainGetInitialStation (BarApp_t *app) { static void BarMainHandleUserInput (BarApp_t *app) { char buf[2]; if (BarReadline (buf, sizeof (buf), NULL, &app->input, - BAR_RL_FULLRETURN | BAR_RL_NOECHO, 1) > 0) { + BAR_RL_FULLRETURN | BAR_RL_NOECHO | BAR_RL_NOINT, 1) > 0) { BarUiDispatch (app, buf[0], app->curStation, app->playlist, true, BAR_DC_GLOBAL); } @@ -259,6 +259,9 @@ static void BarMainStartPlayback (BarApp_t *app, pthread_t *playerThread) { pthread_mutex_init (&app->player.pauseMutex, NULL); pthread_cond_init (&app->player.pauseCond, NULL); + assert (interrupted == NULL); + interrupted = &app->player.interrupted; + /* throw event */ BarUiStartEventCmd (&app->settings, "songstart", app->curStation, curSong, &app->player, app->ph.stations, @@ -301,6 +304,9 @@ static void BarMainPlayerCleanup (BarApp_t *app, pthread_t *playerThread) { } memset (&app->player, 0, sizeof (app->player)); + + assert (interrupted == &app->player.interrupted); + interrupted = NULL; } /* print song duration @@ -384,6 +390,23 @@ static void BarMainLoop (BarApp_t *app) { } } +sig_atomic_t *interrupted = NULL; + +static void intHandler (int signal) { + if (interrupted != NULL) { + *interrupted = 1; + } +} + +static void BarMainSetupSigaction () { + struct sigaction act = { + .sa_handler = intHandler, + .sa_flags = 0, + }; + sigemptyset (&act.sa_mask); + sigaction (SIGINT, &act, NULL); +} + int main (int argc, char **argv) { static BarApp_t app; @@ -391,6 +414,7 @@ int main (int argc, char **argv) { /* save terminal attributes, before disabling echoing */ BarTermInit (); + BarMainSetupSigaction (); /* signals */ signal (SIGPIPE, SIG_IGN); |