summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFreeArtMan <dos21h@gmail.com>2017-09-30 11:41:40 +0100
committerFreeArtMan <dos21h@gmail.com>2017-09-30 11:41:40 +0100
commit8c97104aa6fac4a7ed54d97bbcb1aed5e2398713 (patch)
tree3cdf868d8d7559efbf8185e7d4394291ed62b84d
parent5de1c5ba999dba7da45316d3c1f2592c0e0e4804 (diff)
downloadagni-8c97104aa6fac4a7ed54d97bbcb1aed5e2398713.tar.gz
agni-8c97104aa6fac4a7ed54d97bbcb1aed5e2398713.zip
Added command type detection
-rw-r--r--agni.c14
-rw-r--r--cmd/cmd_lua.c46
-rw-r--r--cmd/cmd_lua.h17
-rw-r--r--config_all_cmds.h13
-rw-r--r--config_cmds.h2
-rw-r--r--nbrpc_event.h18
-rw-r--r--tbl_qcmd.c13
7 files changed, 107 insertions, 16 deletions
diff --git a/agni.c b/agni.c
index b8fa534..e5ea822 100644
--- a/agni.c
+++ b/agni.c
@@ -710,6 +710,20 @@ int th_event_manager(void *data)
ecmd->id = uniq_id();
ecmd->name = alloc_new_str("local-executor");
ecmd->cmd = alloc_new_str(single_cmd->name);
+ switch(single_cmd->type)
+ {
+ case CMD_T_SIMPLE:
+ ecmd->type = TBL_T_SIMPLE;
+ break;
+ case CMD_T_RPC:
+ ecmd->type = TBL_T_RPC;
+ break;
+ case CMD_T_LUA:
+ ecmd->type = TBL_T_LUA;
+ break;
+ default:
+ ERROR("No such type, something wrong here\n");
+ }
ecmd->callback = single_cmd->callback;
if (-1 == tbl_exec_add(etbl, ecmd))
diff --git a/cmd/cmd_lua.c b/cmd/cmd_lua.c
new file mode 100644
index 0000000..a4d7573
--- /dev/null
+++ b/cmd/cmd_lua.c
@@ -0,0 +1,46 @@
+#include "cmd_lua.h"
+
+#define BILLION 1000000000L
+
+void *cmd_lua(void *data)
+{
+ char *ret = NULL;
+ int fret=-1;
+
+ const int buf_size = 128;
+ char buf[buf_size+1];
+
+ struct timespec start;
+ struct stat file_stat;
+ uint64_t proc_sec;
+
+ printf("BOTU\n");
+
+ stat("/proc/self",&file_stat);
+
+ /*
+ CHECK PREDIFINED MACROSES IF SUCH FUNCTIONALITY EXCISTS OR NOT
+ */
+ #if _POSIX_C_SOURCE < 199309L
+ ERROR("Dont have functionality\n");
+ #endif
+
+ fret = clock_gettime(CLOCK_REALTIME, &start);
+ if (fret<0)
+ {
+ perror("clock gettime");
+ ret = alloc_new_str("Can get clock thread uptime\n");
+ return ret;
+ }
+
+ proc_sec = start.tv_sec - file_stat.st_ctim.tv_sec;
+
+ snprintf(buf, buf_size, "%lud %luh %lum %lus",
+ (proc_sec/(3600*24)),
+ (proc_sec/(3600))%24,
+ (proc_sec/60)%60,
+ proc_sec%60);
+ ret = alloc_new_str(buf);
+
+ return ret;
+}
diff --git a/cmd/cmd_lua.h b/cmd/cmd_lua.h
new file mode 100644
index 0000000..e2a0c4d
--- /dev/null
+++ b/cmd/cmd_lua.h
@@ -0,0 +1,17 @@
+#ifndef __CMD_LUA_H
+#define __CMD_LUA_H
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <time.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "util.h"
+#include "debug.h"
+
+void *cmd_lua(void *data);
+
+#endif \ No newline at end of file
diff --git a/config_all_cmds.h b/config_all_cmds.h
index 435a24b..22abd4a 100644
--- a/config_all_cmds.h
+++ b/config_all_cmds.h
@@ -1,20 +1,23 @@
#ifndef __CONFIG_CMD_HEADERS_H
#define __CONFIG_CMD_HEADERS_H
+#include "cmd/cmd_todo.h"
#include "cmd/cmd_rand.h"
-#include "cmd/cmd_spi.h"
-#include "cmd/cmd_cmd.h"
#include "cmd/cmd_rusage.h"
#include "cmd/cmd_version.h"
+#include "cmd/cmd_stat.h"
#include "cmd/cmd_cookie.h"
+#include "cmd/cmd_date.h"
#include "cmd/cmd_sha1.h"
#include "cmd/cmd_fir1p.h"
-#include "cmd/cmd_loadavg.h"
#include "cmd/cmd_uptime.h"
#include "cmd/cmd_rand_libc.h"
-#include "cmd/cmd_ping.h"
#include "cmd/cmd_botu.h"
+#include "cmd/cmd_spi.h"
+#include "cmd/cmd_lua.h"
#include "cmd/cmd_fir.h"
+#include "cmd/cmd_loadavg.h"
+#include "cmd/cmd_ping.h"
#include "cmd/cmd_sum.h"
#include "cmd/cmd_help.h"
-#include "cmd/cmd_date.h"
+#include "cmd/cmd_cmd.h"
#endif
diff --git a/config_cmds.h b/config_cmds.h
index e532d64..8334d5b 100644
--- a/config_cmds.h
+++ b/config_cmds.h
@@ -42,6 +42,8 @@ single_cmd_def confgi_cmd_list[] =
//more complicated command
{CMD_T_RPC,"TODO",cmd_todo},
+ {CMD_T_LUA,"LUA",cmd_lua},
+
{0,NULL,NULL}
};
diff --git a/nbrpc_event.h b/nbrpc_event.h
index 5f3657a..020ecba 100644
--- a/nbrpc_event.h
+++ b/nbrpc_event.h
@@ -28,15 +28,6 @@ typedef struct rpc_response
rpc_request* rpc_req_new(char *method, char *params, int id);
rpc_response* rpc_resp_new(char *result, char *error, int id);
-int rpc_req_set_user(rpc_request *req);
-int rpc_resp_set_user(rpc_response *resp);
-
-int rpc_req_set_mask(rpc_request *req);
-int rpc_resp_set_mask(rpc_response *resp);
-
-int rpc_req_set_server(rpc_request *req);
-int rpc_resp_set_server(rpc_response *resp);
-
int rpc_req_free(rpc_request *req);
int rpc_resp_free(rpc_response *resp);
@@ -46,4 +37,13 @@ int rpc_resp_marsh( rpc_response *resp, netbyte_store **nb_resp);
int rpc_req_unmarsh( netbyte_store *nb_req, rpc_request **req);
int rpc_resp_unmarsh(netbyte_store *nb_resp, rpc_response **resp);
+int rpc_req_set_user(rpc_request *req);
+int rpc_resp_set_user(rpc_response *resp);
+
+int rpc_req_set_mask(rpc_request *req);
+int rpc_resp_set_mask(rpc_response *resp);
+
+int rpc_req_set_server(rpc_request *req);
+int rpc_resp_set_server(rpc_response *resp);
+
#endif \ No newline at end of file
diff --git a/tbl_qcmd.c b/tbl_qcmd.c
index d3e0d7f..adc3503 100644
--- a/tbl_qcmd.c
+++ b/tbl_qcmd.c
@@ -135,12 +135,21 @@ int tbl_exec_run(tbl_exec *tbl, char *cmd, void **resp)
//PRINT("CALLBACK PARAMS %s\n", clbk_data);
- ret_resp = el->callback(clbk_data); //no params for now
-
+ if (el->type == TBL_T_SIMPLE)
+ {
+ ret_resp = el->callback(clbk_data); //no params for now
+ } else if (el->type == TBL_T_RPC)
+ {
+ ERROR("Not implemented\n");
+ } else if (el->type == TBL_T_LUA)
+ {
+ ERROR("Not implemented\n");
+ }
//return
if (ret_resp != NULL)
{
*resp = ret_resp;
+ //return executed command id
ret = i;
}
}