- /* generate the path name */
- strcat(path, path_start);
- strcat(path, wificard);
- strcat(path, path_end);
-
- /* open wifi file, extract status, close file */
- if(!(fp = fopen(path, "r"))) {
- fprintf(stderr, "Error opening wifi operstate file.");
- exit(1);
- }
- char status[5];
- fgets(status, 5, fp);
- 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 and close the file */
- 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);
+ fp= fopen("/proc/sys/kernel/random/entropy_avail", "r");
+ if (fp == NULL) {
+ warn("Failed to open file /proc/sys/kernel/random/entropy_avail");
+ return smprintf(UNKNOWN_STR);
+ }
+ fscanf(fp, "%d", &num);
+ fclose(fp);
+
+ return smprintf("%d", num);
+}
+
+static char *
+gid(void)
+{
+ return smprintf("%d", getgid());
+}
+
+static char *
+hostname(void)
+{
+ char buf[HOST_NAME_MAX];
+
+ if (gethostname(buf, sizeof(buf)) == -1) {
+ warn("hostname");
+ return smprintf(UNKNOWN_STR);
+ }
+
+ return smprintf("%s", buf);
+}
+
+static char *
+ip(const char *iface)
+{
+ struct ifaddrs *ifaddr, *ifa;
+ int s;
+ char host[NI_MAXHOST];
+
+ if (getifaddrs(&ifaddr) == -1) {
+ warn("Failed to get IP address for interface %s", iface);
+ return smprintf(UNKNOWN_STR);
+ }
+
+ for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
+ if (ifa->ifa_addr == NULL) {
+ continue;
+ }
+ s = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
+ if ((strcmp(ifa->ifa_name, iface) == 0) && (ifa->ifa_addr->sa_family == AF_INET)) {
+ if (s != 0) {
+ warnx("Failed to get IP address for interface %s", iface);
+ return smprintf(UNKNOWN_STR);
+ }
+ return smprintf("%s", host);
+ }
+ }
+
+ freeifaddrs(ifaddr);
+
+ return smprintf(UNKNOWN_STR);
+}
+
+static char *
+load_avg(void)
+{
+ double avgs[3];
+
+ if (getloadavg(avgs, 3) < 0) {
+ warnx("Failed to get the load avg");
+ return smprintf(UNKNOWN_STR);
+ }
+
+ return smprintf("%.2f %.2f %.2f", avgs[0], avgs[1], avgs[2]);
+}
+
+static char *
+ram_free(void)
+{
+ long free;
+ FILE *fp;
+
+ fp = fopen("/proc/meminfo", "r");
+ if (fp == NULL) {
+ warn("Failed to open file /proc/meminfo");
+ return smprintf(UNKNOWN_STR);
+ }
+ fscanf(fp, "MemFree: %ld kB\n", &free);
+ fclose(fp);
+
+ return smprintf("%f", (float)free / 1024 / 1024);
+}
+
+static char *
+ram_perc(void)
+{
+ long total, free, buffers, cached;
+ FILE *fp;
+
+ fp = fopen("/proc/meminfo", "r");
+ if (fp == NULL) {
+ warn("Failed to open file /proc/meminfo");
+ return smprintf(UNKNOWN_STR);