From 5025c0c8288a336f7986153574bce73df4bb3147 Mon Sep 17 00:00:00 2001 From: FreeArtMan Date: Mon, 8 May 2017 13:23:20 +0100 Subject: Added new command that shows bots uptime --- Makefile | 3 ++- cmd_botu.c | 42 ++++++++++++++++++++++++++++++++++++++++++ cmd_botu.h | 17 +++++++++++++++++ config_cmds.h | 3 ++- 4 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 cmd_botu.c create mode 100644 cmd_botu.h diff --git a/Makefile b/Makefile index 62f2d11..226eef7 100644 --- a/Makefile +++ b/Makefile @@ -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 +#include +#include +#include +#include +#include +#include + +#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} }; -- cgit v1.2.3