speechd-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 2/3] Cleanup execution of commands in dummy


From: Trevor Saunders
Subject: [PATCH v2 2/3] Cleanup execution of commands in dummy
Date: Sat, 28 Jul 2012 21:20:08 -0400

> +             // no commands specified for whatever reason - resort to the 
> default ones
> +             for (i = 0; i < 
> sizeof(default_play_cmds)/sizeof(default_play_cmds[0]); ++i) {
> +                     play_cmd = g_strdup(default_play_cmds[i]);
> +                     g_array_append_val(PlayCommands, play_cmd);
> +             }
> +     }
>  
>       sigfillset(&some_signals);
>       module_sigunblockusr(&some_signals);
> @@ -237,43 +257,23 @@ void _dummy_child()
>       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 (i = 0; i < PlayCommands->len; ++i) {
> +             play_cmd = g_array_index(PlayCommands, const gchar *, i);
> +             const gchar *play_cmdline = g_strdup_printf("%s 
> %s/dummy-message.wav > /dev/null 2> /dev/null", play_cmd, DATADIR);

so, there's a bug here, if we're using the default you'll end up with
something like "play /path/to/dummy.wav > /dev/null 2>/dev/null
/dummy.way > /dev/null 2>/dev/null"

I'd probably fix this by just writing my own dotconf callback, that adds
the rest of the command to the binary to run before storing it.

> +#define MOD_OPTION_MORE(name) \
> +     GArray *name; \
> +     gchar *val;     \

couldn't you declare this one inside the loop?

> +     DOTCONF_CB(name ## _cb) \
> +     { \
> +             int i; \
> +             for (i = 0; i < cmd->arg_count; ++i) { \
> +                     val = g_strdup(cmd->data.list[i]); \
> +                     g_array_append_val(name, val); \
> +             } \

since you know the length of the array at the start cann't you allocate
it in one shot?

Trev



reply via email to

[Prev in Thread] Current Thread [Next in Thread]