mirror of
https://github.com/clearlinux/micro-config-drive.git
synced 2026-09-07 06:04:32 +00:00
use GString to run commands at runcmd ccmodule
Using GString is safer that use static char arrays
This commit is contained in:
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user