implement runcmd ccmodule

this module is able to execute command lines
This commit is contained in:
Julio Montes
2015-11-27 12:46:42 -06:00
parent d4963adb31
commit 85dcda040f
3 changed files with 70 additions and 0 deletions
+1
View File
@@ -35,6 +35,7 @@ cloud_init_SOURCES = \
src/ccmodules/users.c \
src/ccmodules/write_files.c \
src/ccmodules/hostname.c \
src/ccmodules/runcmd.c \
src/curl.c \
src/curl.h \
src/datasources.h \
+2
View File
@@ -47,6 +47,7 @@ extern struct cc_module_handler_struct users_cc_module;
extern struct cc_module_handler_struct ssh_authorized_keys_cc_module;
extern struct cc_module_handler_struct service_cc_module;
extern struct cc_module_handler_struct hostname_cc_module;
extern struct cc_module_handler_struct runcmd_cc_module;
struct cc_module_handler_struct *cc_module_structs[] = {
&package_upgrade_cc_module,
@@ -57,6 +58,7 @@ struct cc_module_handler_struct *cc_module_structs[] = {
&ssh_authorized_keys_cc_module,
&service_cc_module,
&hostname_cc_module,
&runcmd_cc_module,
NULL
};
+67
View File
@@ -0,0 +1,67 @@
/***
Copyright (C) 2015 Intel Corporation
Author: Julio Montes <julio.montes@intel.com>
This file is part of clr-cloud-init.
clr-cloud-init is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
clr-cloud-init is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with clr-cloud-init. If not, see <http://www.gnu.org/licenses/>.
In addition, as a special exception, the copyright holders give
permission to link the code of portions of this program with the
OpenSSL library under certain conditions as described in each
individual source file, and distribute linked combinations
including the two.
You must obey the GNU General Public License in all respects
for all of the code used other than OpenSSL. If you modify
file(s) with this exception, you may extend this exception to your
version of the file(s), but you are not obligated to do so. If you
do not wish to do so, delete this exception statement from your
version. If you delete this exception statement from all source
files in the program, then also delete it here.
***/
#include <stdbool.h>
#include <glib.h>
#include "lib.h"
#include "handlers.h"
#define MOD "runcmd: "
#define COMMAND_SIZE 4096
static void runcmd_item(GNode* node, gpointer data) {
gchar command_line[COMMAND_SIZE] = { 0 };
if (!node->data) {
g_node_children_foreach(node, G_TRAVERSE_ALL, runcmd_item, command_line);
if (!exec_task(command_line)) {
LOG(MOD "Execute command failed\n");
}
} else {
g_strlcat(data, node->data,COMMAND_SIZE);
g_strlcat(data, " ", COMMAND_SIZE);
}
}
void runcmd_handler(GNode *node) {
LOG(MOD "Runcmd Handler running...\n");
g_node_children_foreach(node, G_TRAVERSE_ALL, runcmd_item, NULL);
}
struct cc_module_handler_struct runcmd_cc_module = {
.name = "runcmd",
.handler = &runcmd_handler
};