added uptime function
authorAaron Marcher <info@nulltime.net>
Thu, 18 Aug 2016 11:43:18 +0000 (13:43 +0200)
committerAaron Marcher (drkhsh) <info@nulltime.net>
Thu, 18 Aug 2016 11:43:18 +0000 (13:43 +0200)
README.md
config.def.h
slstatus.c
slstatus.h

index feb63f520bdf3e011f64bba5a6e27f3e9ec74556..dad5df786215f782b132eddfa924eaff24420c9b 100644 (file)
--- a/README.md
+++ b/README.md
@@ -20,6 +20,7 @@ The following information is included:
 - load avg
 - ram numbers (free ram, percentage, total ram and used ram)
 - temperature
+- uptime
 - volume percentage (alsa)
 - wifi percentage and essid
 
index 2dd05ded9230222174d4f8bcf8c47827eff903ca..5fb52b318db8ae93da5d584f7119995a2caf6be3 100644 (file)
@@ -34,6 +34,7 @@ static const char unknowntext[] = "n/a";
 - run_command (run custom shell command) [argument: command]
 - temp (temperature in degrees) [argument: temperature file]
 - uid (uid of current user) [argument: NULL]
+- uptime (uptime) [argument: NULL]
 - username (username of current user) [argument: NULL]
 - vol_perc (alsa volume and mute status in percent) [argument: soundcard]
 - wifi_perc (wifi signal in percent) [argument: wifi card interface name]
index 87e705d1758566d3d10f760d8dd12c0ee69a0b48..fee56fcb3d4a44030838a2c61bd1fc5d50d349d8 100644 (file)
@@ -18,6 +18,7 @@
 #include <sys/stat.h>
 #include <sys/statvfs.h>
 #include <sys/socket.h>
+#include <sys/sysinfo.h>
 #include <sys/types.h>
 #include <time.h>
 #include <unistd.h>
@@ -521,6 +522,23 @@ temp(const char *file)
        return smprintf("%d°C", temperature / 1000);
 }
 
+/* uptime */
+char *
+uptime(const char *null)
+{
+       struct sysinfo info;
+       int hours = 0;
+       int minutes = 0;
+
+       /* get info */
+       sysinfo(&info);
+       hours = info.uptime / 3600;
+       minutes = (info.uptime - hours * 3600 ) / 60;
+
+       /* return it */
+       return smprintf("%dh %dm", hours, minutes);
+}
+
 /* username */
 char *
 username(const char *null)
index 5efc5f2dfe1d03a93e417b576f04e042a019d24f..9d6de2e5a99712c548146f7def71fcea9b2789e6 100644 (file)
@@ -33,6 +33,7 @@ char *ram_total(const char *);
 char *run_command(const char *);
 char *temp(const char *);
 char *uid(const char*);
+char *uptime(const char*);
 char *username(const char*);
 char *vol_perc(const char *);
 char *wifi_perc(const char *);