diff options
author | FreeArtMan <dos21h@gmail.com> | 2017-05-08 13:23:20 +0100 |
---|---|---|
committer | FreeArtMan <dos21h@gmail.com> | 2017-05-08 13:23:20 +0100 |
commit | 5025c0c8288a336f7986153574bce73df4bb3147 (patch) | |
tree | 9822b26811fbbd004c006651bdafb0cbabd25081 | |
parent | 0041b69fc5778d6be88d70e440cd8785b83d44dc (diff) | |
download | agni-5025c0c8288a336f7986153574bce73df4bb3147.tar.gz agni-5025c0c8288a336f7986153574bce73df4bb3147.zip |
Added new command that shows bots uptime
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | cmd_botu.c | 42 | ||||
-rw-r--r-- | cmd_botu.h | 17 | ||||
-rw-r--r-- | config_cmds.h | 3 |
4 files changed, 63 insertions, 2 deletions
@@ -23,9 +23,10 @@ make: version $(CC) $(CFLAGS) sha1.c -c $(CC) $(CFLAGS) cmd_sha1.c -c $(CC) $(CFLAGS) cmd_cookie.c -c + $(CC) $(CFLAGS) cmd_botu.c -c $(CC) $(CFLAGS) tbl_qcmd.o mq_cmd.o mq_ntf.o buf.o mmm.o darray.o util.o sock_conn.o \ irc_parse.o mmm.c cmd_date.o cmd_uptime.o cmd_version.o cmd_ping.o cmd_loadavg.o \ - cmd_rusage.c cmd_cmd.o sha1.o cmd_sha1.o cmd_cookie.o agni.c \ + cmd_rusage.c cmd_cmd.o sha1.o cmd_sha1.o cmd_cookie.o cmd_botu.o agni.c \ -o $(PROJECT) -std=c11 -lrt version: diff --git a/cmd_botu.c b/cmd_botu.c new file mode 100644 index 0000000..312509d --- /dev/null +++ b/cmd_botu.c @@ -0,0 +1,42 @@ +#include "cmd_botu.h" + +#define BILLION 1000000000L + +void *cmd_botu(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, "%llusec\n", proc_sec); + ret = alloc_new_str(buf); + + return ret; +} diff --git a/cmd_botu.h b/cmd_botu.h new file mode 100644 index 0000000..2c06230 --- /dev/null +++ b/cmd_botu.h @@ -0,0 +1,17 @@ +#ifndef __CMD_BOTU_H +#define __CMD_BOTU_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_botu(void *data); + +#endif
\ No newline at end of file diff --git a/config_cmds.h b/config_cmds.h index 1eea56a..a3e503e 100644 --- a/config_cmds.h +++ b/config_cmds.h @@ -18,7 +18,7 @@ typedef struct single_cmd_def #include "cmd_cmd.h" #include "cmd_sha1.h" #include "cmd_cookie.h" - +#include "cmd_botu.h" //some commands have aliases for compat with some developerslv bots //nothing else comaptible will be added, as its not about "standarts" @@ -33,6 +33,7 @@ single_cmd_def confgi_cmd_list[] = {"CMD",cmd_cmd}, {"!echo",cmd_cmd}, {"SHA1",cmd_sha1}, {"COOKIE",cmd_cookie}, + {"BOTU",cmd_botu}, {NULL,NULL} }; |