use GString to run commands at runcmd ccmodule

Using GString is safer that use static char arrays
This commit is contained in:
Julio Montes
2016-02-25 14:56:49 -06:00
parent 35c25ae9cd
commit d86fe138c7
+8 -9
View File
@@ -41,24 +41,23 @@
#define MOD "runcmd: "
#define COMMAND_SIZE 4096
static void runcmd_item(GNode* node, gpointer data) {
gchar command_line[COMMAND_SIZE] = { 0 };
static void runcmd_item(GNode* node, gpointer command_line) {
if (!node->data) {
g_node_children_foreach(node, G_TRAVERSE_ALL, runcmd_item, command_line);
if (!exec_task(command_line)) {
if (!exec_task(((GString*)command_line)->str)) {
LOG(MOD "Execute command failed\n");
}
g_string_set_size((GString*)command_line, 0);
} else {
g_strlcat(data, node->data,COMMAND_SIZE);
g_strlcat(data, " ", COMMAND_SIZE);
g_string_append_printf((GString*)command_line, "%s ", (char*)node->data);
}
}
void runcmd_handler(GNode *node) {
LOG(MOD "Runcmd Handler running...\n");
g_node_children_foreach(node, G_TRAVERSE_ALL, runcmd_item, NULL);
GString* command_line = g_string_new("");
LOG(MOD "runcmd handler running...\n");
g_node_children_foreach(node, G_TRAVERSE_ALL, runcmd_item, command_line);
g_string_free(command_line, true);
}
struct cc_module_handler_struct runcmd_cc_module = {