- /* generate the path name */
- strcat(path, path_start);
- strcat(path, wificard);
- strcat(path, path_end);
-
- /* open wifi file */
- if(!(fp = fopen(path, "r"))) {
- fprintf(stderr, "Error opening wifi operstate file.");
- exit(1);
- }
-
- /* read the status */
- fgets(status, 5, fp);
-
- /* close wifi file */
- fclose(fp);
-
- /* check if interface down */
- if(strcmp(status, "up\n") != 0){
- return "n/a";
- }
-
- /* open wifi file */
- if (!(fp = fopen("/proc/net/wireless", "r"))) {
- fprintf(stderr, "Error opening wireless file.");
- exit(1);
- }
-
- /* extract the signal strength */
- fgets(buf, bufsize, fp);
- fgets(buf, bufsize, fp);
- fgets(buf, bufsize, fp);
- if ((datastart = strstr(buf, "wlp3s0:")) != NULL) {
- datastart = strstr(buf, ":");
- sscanf(datastart + 1, " %*d %d %*d %*d %*d %*d %*d %*d %*d %*d",
- &strength);
+ t = time(NULL);
+ if (strftime(timestr, sizeof(timestr), timeformat, localtime(&t)) == 0)
+ return smprintf(UNKNOWN_STR);
+
+ return smprintf("%s", timestr);
+}
+
+static char *
+disk_free(const char *mountpoint)
+{
+ struct statvfs fs;
+
+ if (statvfs(mountpoint, &fs) < 0) {
+ warn("Could not get filesystem info");
+ return smprintf(UNKNOWN_STR);
+ }
+
+ return smprintf("%f", (float)fs.f_bsize * (float)fs.f_bfree / 1024 / 1024 / 1024);
+}
+
+static char *
+disk_perc(const char *mountpoint)
+{
+ int perc = 0;
+ struct statvfs fs;
+
+ if (statvfs(mountpoint, &fs) < 0) {
+ warn("Could not get filesystem info");
+ return smprintf(UNKNOWN_STR);
+ }
+
+ perc = 100 * (1.0f - ((float)fs.f_bfree / (float)fs.f_blocks));
+
+ return smprintf("%d%%", perc);
+}
+
+static char *
+disk_total(const char *mountpoint)
+{
+ struct statvfs fs;
+
+ if (statvfs(mountpoint, &fs) < 0) {
+ warn("Could not get filesystem info");
+ return smprintf(UNKNOWN_STR);
+ }
+
+ return smprintf("%f", (float)fs.f_bsize * (float)fs.f_blocks / 1024 / 1024 / 1024);
+}
+
+static char *
+disk_used(const char *mountpoint)
+{
+ struct statvfs fs;
+
+ if (statvfs(mountpoint, &fs) < 0) {
+ warn("Could not get filesystem info");
+ return smprintf(UNKNOWN_STR);
+ }
+
+ return smprintf("%f", (float)fs.f_bsize * ((float)fs.f_blocks - (float)fs.f_bfree) / 1024 / 1024 / 1024);
+}
+
+static char *
+entropy(void)
+{
+ int entropy = 0;
+ FILE *fp = fopen("/proc/sys/kernel/random/entropy_avail", "r");
+
+ if (fp == NULL) {
+ warn("Could not open entropy file");
+ return smprintf(UNKNOWN_STR);