[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 04/10] Cleanup execution of commands in dummy
From: |
Boris Dušek |
Subject: |
[PATCH 04/10] Cleanup execution of commands in dummy |
Date: |
Mon, 23 Jul 2012 15:22:29 +0200 |
From: Boris Dus?ek <address@hidden>
To: address@hidden
---
src/modules/dummy.c | 46 ++++++++++++++++------------------------------
1 files changed, 16 insertions(+), 30 deletions(-)
diff --git a/src/modules/dummy.c b/src/modules/dummy.c
index 28fd5e4..6784cb8 100644
--- a/src/modules/dummy.c
+++ b/src/modules/dummy.c
@@ -229,51 +229,37 @@ void _dummy_child()
sigset_t some_signals;
int ret;
- char *try1, *try2, *try3;
+#define PLAY_CMD(cmd) #cmd " " DATADIR "/dummy-message.wav > /dev/null 2>
/dev/null"
+ static const char *const play_cmds[] = {
+ PLAY_CMD(play),
+ PLAY_CMD(aplay),
+ PLAY_CMD(paplay),
+ NULL
+ };
+#undef PLAY_CMD
+ const char *const *play_cmd = NULL;
sigfillset(&some_signals);
module_sigunblockusr(&some_signals);
DBG("Entering child loop\n");
/* Read the waiting data */
- try1 =
- g_strdup("play " DATADIR
- "/dummy-message.wav > /dev/null 2> /dev/null");
- try2 =
- g_strdup("aplay " DATADIR
- "/dummy-message.wav > /dev/null 2> /dev/null");
- try3 =
- g_strdup("paplay " DATADIR
- "/dummy-message.wav > /dev/null 2> /dev/null");
-
- DBG("child: synth commands = |%s|%s|%s|", try1, try2, try3);
DBG("Speaking in child...");
module_sigblockusr(&some_signals);
- ret = system(try1);
- DBG("Executed shell command '%s' returned with %d", try1, ret);
- if ((ret != 0)) {
- DBG("Execution failed, trying seccond command");
- ret = system(try2);
- DBG("Executed shell command '%s' returned with %d", try1, ret);
- if ((ret != 0)) {
- DBG("Execution failed, trying third command");
- ret = system(try3);
- DBG("Executed shell command '%s' returned with %d",
- try1, ret);
- if ((ret != 0) && (ret != 256)) {
- DBG("Failed, giving up.");
- }
+ for (play_cmd = play_cmds; *play_cmd != NULL; ++play_cmd) {
+ DBG("Executing shell command '%s'", *play_cmd);
+ ret = system(*play_cmd);
+ if (ret != 0) {
+ DBG("Executing command failed with return code %d",
ret);
+ } else {
+ break;
}
}
module_sigunblockusr(&some_signals);
- g_free(try1);
- g_free(try2);
- g_free(try3);
-
DBG("Done, exiting from child.");
exit(0);
}
--
1.7.7.5 (Apple Git-26)
- [PATCH 01/10] Remove references to TEMP_FAILURE_RETRY, Boris Dušek, 2012/07/23
- [PATCH 02/10] Do not exit on localization init fail, Boris Dušek, 2012/07/23
- [PATCH 03/10] Fix termination of threads in spd_close, Boris Dušek, 2012/07/23
- [PATCH 04/10] Cleanup execution of commands in dummy,
Boris Dušek <=
- [PATCH 05/10] Fix audio module dynamic opening on OS X, Boris Dušek, 2012/07/23
- [PATCH 06/10] Use afplay and libao for playing sound on OS X in dummy, Boris Dušek, 2012/07/23
- [PATCH 07/10] Abstract unnamed semaphore interface and add OS X implementation, Boris Dušek, 2012/07/23
- [PATCH 08/10] Use launchd on OS X for launching the server, Boris Dušek, 2012/07/23
- [PATCH 09/10] Installation instructions for OS X, Boris Dušek, 2012/07/23
- [PATCH 10/10] Native SSM output module for OS X, Boris Dušek, 2012/07/23