summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Marcher <info@nulltime.net>2016-06-10 15:53:07 +0200
committerAaron Marcher (drkhsh) <info@nulltime.net>2016-06-10 15:53:07 +0200
commit2e72b212d3019a23accfd9d001bcec5d3ee5ab46 (patch)
tree2af43dcdc530b5e43c23520f8cf23283eeca0771
parent67203c66600113259f4f25b1021c6395f3a62dd6 (diff)
hostname function
-rw-r--r--config.def.h1
-rw-r--r--slstatus.c23
-rw-r--r--slstatus.h1
3 files changed, 25 insertions, 0 deletions
diff --git a/config.def.h b/config.def.h
index b4b65ac..351d7ed 100644
--- a/config.def.h
+++ b/config.def.h
@@ -17,6 +17,7 @@ static unsigned int update_interval = 1;
- datetime (date and time) [argument: format]
- disk_perc (disk usage in percent) [argument: mountpoint]
- entropy (available entropy) [argument: NULL]
+- hostname [argument: NULL]
- ip (ip address) [argument: interface]
- ram_perc (ram usage in percent) [argument: NULL]
- temp (temperature in degrees) [argument: temperature file]
diff --git a/slstatus.c b/slstatus.c
index 9cd5ae2..5bbf58a 100644
--- a/slstatus.c
+++ b/slstatus.c
@@ -208,6 +208,29 @@ entropy(const char *null)
return smprintf("%d", entropy);
}
+/* hostname */
+char *
+hostname(const char *null)
+{
+ char *hostname = "";
+ FILE *fp;
+
+ /* open hostname file */
+ if (!(fp = fopen("/proc/sys/kernel/hostname", "r"))) {
+ fprintf(stderr, "Could not open hostname file.\n");
+ return smprintf("n/a");
+ }
+
+ /* extract hostname */
+ fscanf(fp, "%s", hostname);
+
+ /* close hostname file */
+ fclose(fp);
+
+ /* return entropy */
+ return smprintf("%s", hostname);
+}
+
/* ip address */
char *
ip(const char *interface)
diff --git a/slstatus.h b/slstatus.h
index 0d86f33..64b8dfa 100644
--- a/slstatus.h
+++ b/slstatus.h
@@ -19,6 +19,7 @@ char *cpu_perc(const char *);
char *datetime(const char *);
char *disk_perc(const char *);
char *entropy(const char*);
+char *hostname(const char *);
char *ip(const char *);
char *ram_perc(const char *);
char *temp(const char *);