summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/main.c b/src/main.c
index b113f4e..5d0e91b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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);