From 0c1d42ad03f7e49b23755209f5b1f295cbe21f6b Mon Sep 17 00:00:00 2001 Message-Id: <0c1d42ad03f7e49b23755209f5b1f295cbe21f6b.1715154691.git.mdw@distorted.org.uk> From: Mark Wooding Date: Sun, 14 Aug 2011 18:22:49 +0100 Subject: [PATCH] server: don't report wstat for processes killed by the server Organization: Straylight/Edgeware From: Richard Kettlewell --- lib/queue.h | 6 ++++++ server/play.c | 35 ++++++++++++++++++++--------------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/lib/queue.h b/lib/queue.h index 2219763..9bad76e 100644 --- a/lib/queue.h +++ b/lib/queue.h @@ -220,6 +220,12 @@ struct queue_entry { /** @brief Decoder (or player) process ID */ pid_t pid; + + /** @brief Termination signal sent to subprocess + * + * Used to supress 'terminated' messages. + */ + int killed; }; void queue_insert_entry(struct queue_entry *b, struct queue_entry *n); diff --git a/server/play.c b/server/play.c index b6d3dcc..a1384f8 100644 --- a/server/play.c +++ b/server/play.c @@ -250,10 +250,12 @@ static int player_finished(ev_source *ev, q->state = playing_ok; break; } - /* Regardless we always report and record the status and do cleanup for - * prefork calls. */ - if(status) - disorder_error(0, "player for %s %s", q->track, wstat(status)); + /* Report the status unless we killed it */ + if(status) { + if(!(q->killed && WIFSIGNALED(status) && WTERMSIG(status) == q->killed)) + disorder_error(0, "player for %s %s", q->track, wstat(status)); + } + /* Clean up any prefork calls */ if(q->type & DISORDER_PLAYER_PREFORK) play_cleanup(q->pl, q->data); q->wstat = status; @@ -474,6 +476,15 @@ static int prepare_child(struct queue_entry *q, return 0; } +/** @brief Kill a player + * @param q Queue entry corresponding to player + */ +static void kill_player(struct queue_entry *q) { + if(q->pid >= 0) + kill(-q->pid, config->signal); + q->killed = config->signal; +} + /** @brief Abandon a queue entry * * Called from c_remove() (but NOT when scratching a track). Only does @@ -489,7 +500,7 @@ void abandon(ev_source attribute((unused)) *ev, if((q->type & DISORDER_PLAYER_TYPEMASK) != DISORDER_PLAYER_RAW) return; /* Not a raw player. */ /* Terminate the player. */ - kill(-q->pid, config->signal); + kill_player(q); /* Cancel the track. */ memset(&sm, 0, sizeof sm); sm.type = SM_CANCEL; @@ -693,10 +704,8 @@ void scratch(const char *who, const char *id) { playing->state = playing_scratched; playing->scratched = who ? xstrdup(who) : 0; /* Find the player and kill the whole process group */ - if(playing->pid >= 0) { - D(("kill -%d -%lu", config->signal, (unsigned long)playing->pid)); - kill(-playing->pid, config->signal); - } + if(playing->pid >= 0) + kill_player(playing); /* Tell the speaker, if we think it'll care */ if((playing->type & DISORDER_PLAYER_TYPEMASK) == DISORDER_PLAYER_RAW) { memset(&sm, 0, sizeof sm); @@ -735,17 +744,13 @@ void quitting(ev_source *ev) { shutting_down = 1; /* Shut down the current player */ if(playing) { - if(playing->pid >= 0) - kill(-playing->pid, config->signal); + kill_player(playing); playing->state = playing_quitting; finished(0); } /* Zap any background decoders that are going */ for(q = qhead.next; q != &qhead; q = q->next) - if(q->pid >= 0) { - D(("kill -%d %lu", config->signal, (unsigned long)q->pid)); - kill(-q->pid, config->signal); - } + kill_player(q); /* Don't need the speaker any more */ ev_fd_cancel(ev, ev_read, speaker_fd); xclose(speaker_fd); -- [mdw]