aboutsummaryrefslogtreecommitdiff
path: root/status.c
diff options
context:
space:
mode:
authortoni <matzeton@googlemail.com>2014-12-17 22:42:35 +0100
committertoni <matzeton@googlemail.com>2014-12-20 00:47:38 +0100
commit2011ed7c238a4d740f5ccd50fd084e0f07b03560 (patch)
tree88b2b9a0c9ea385cec03efdcdac98e35b950d760 /status.c
parent86f401fbd47e59aea421f7063a146b7c8ae95c03 (diff)
parentcb4ef70bef863b6f791755bacfc4f8f9339f3c2b (diff)
Merge branch 'master' of github.com:lnslbrty/naskpass
Conflicts: ui_statusbar.c
Diffstat (limited to 'status.c')
-rw-r--r--status.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/status.c b/status.c
new file mode 100644
index 0000000..5286ddf
--- /dev/null
+++ b/status.c
@@ -0,0 +1,29 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/sysinfo.h>
+
+#include "status.h"
+
+
+char *
+get_system_stat(void)
+{
+ char *retstr = NULL;
+ int ncpu;
+ struct sysinfo inf;
+
+ if (sysinfo(&inf) == EFAULT) {
+ return ("[SYSINFO ERROR]");
+ }
+ ncpu = get_nprocs();
+
+ if (asprintf(&retstr, "u:%04ld - l:%3.2f,%3.2f,%3.2f - %dcore%s - mem:%lu/%lumb - procs:%02d",
+ inf.uptime, ((float)inf.loads[0]/10000), ((float)inf.loads[1]/10000), ((float)inf.loads[2]/10000),
+ ncpu, (ncpu > 1 ? "s" : ""),
+ (unsigned long)((inf.freeram/1024)/1024), (unsigned long)((inf.totalram/1024)/1024), inf.procs) == -1) {
+ return ("[ASPRINTF ERROR]");
+ }
+ return (retstr);
+}