]> git.sur5r.net Git - i3/i3status/commitdiff
Merge pull request #13 from bapt/master
authorMichael Stapelberg <stapelberg@users.noreply.github.com>
Wed, 25 Mar 2015 07:56:00 +0000 (08:56 +0100)
committerMichael Stapelberg <stapelberg@users.noreply.github.com>
Wed, 25 Mar 2015 07:56:00 +0000 (08:56 +0100)
Fixes for FreeBSD

src/print_cpu_usage.c
src/print_disk_info.c
src/print_eth_info.c
src/print_volume.c

index 68437b3cc9e1836ef755c1e7b251a4c8734de43e..2c59f69277ffc0452f62f2498cda0c7c093efa22 100644 (file)
@@ -40,12 +40,12 @@ static int prev_idle = 0;
 void print_cpu_usage(yajl_gen json_gen, char *buffer, const char *format) {
     const char *walk;
     char *outwalk = buffer;
-    char buf[1024];
     int curr_user = 0, curr_nice = 0, curr_system = 0, curr_idle = 0, curr_total;
     int diff_idle, diff_total, diff_usage;
 
 #if defined(LINUX)
     static char statpath[512];
+    char buf[1024];
     strcpy(statpath, "/proc/stat");
     if (!slurp(statpath, buf, sizeof(buf)) ||
         sscanf(buf, "cpu %d %d %d %d", &curr_user, &curr_nice, &curr_system, &curr_idle) != 4)
index b9047e5388e9baa465cd23f334fbdf9755c7f9a9..69d7b8c6187445fe36047ce0c190355b3226c15c 100644 (file)
@@ -3,7 +3,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
-#include <mntent.h>
 #include <stdint.h>
 #include <sys/stat.h>
 #include <sys/statvfs.h>
@@ -11,6 +10,8 @@
 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || (__OpenBSD__) || defined(__DragonFly__)
 #include <sys/param.h>
 #include <sys/mount.h>
+#else
+#include <mntent.h>
 #endif
 #include <yajl/yajl_gen.h>
 #include <yajl/yajl_version.h>
index af5a75788f7cf17d4d0f3b9154781e83abc0e5d6..06a1613d62d418092b267786c687c127830c7762 100644 (file)
@@ -49,11 +49,13 @@ static int print_eth_speed(char *outwalk, const char *interface) {
     } else
         return sprintf(outwalk, "?");
 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
-    char *ethspeed;
+    const char *ethspeed;
     struct ifmediareq ifm;
     (void)memset(&ifm, 0, sizeof(ifm));
     (void)strncpy(ifm.ifm_name, interface, sizeof(ifm.ifm_name));
-    int ret = ioctl(general_socket, SIOCGIFMEDIA, (caddr_t)&ifm);
+    if (ioctl(general_socket, SIOCGIFMEDIA, (caddr_t)&ifm) < 0) {
+        return sprintf(outwalk, "?");
+    }
 
     /* Get the description of the media type, partially taken from
      * FreeBSD's ifconfig */
index ef1c913212b5eda50f96d33fb704649555996b0b..bc469f33e7dbdf06bb9c7fa7e71179b9e804b4b9 100644 (file)
@@ -3,6 +3,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <err.h>
 #include <yajl/yajl_gen.h>
 #include <yajl/yajl_version.h>
 
@@ -139,16 +140,22 @@ void print_volume(yajl_gen json_gen, char *buffer, const char *fmt, const char *
     else
         mixerpath = defaultmixer;
 
-    if ((mixfd = open(mixerpath, O_RDWR)) < 0)
-        return;
+    if ((mixfd = open(mixerpath, O_RDWR)) < 0) {
+        warn("OSS: Cannot open mixer");
+        goto out;
+    }
 
     if (mixer_idx > 0)
         free(mixerpath);
 
-    if (ioctl(mixfd, SOUND_MIXER_READ_DEVMASK, &devmask) == -1)
-        return;
-    if (ioctl(mixfd, MIXER_READ(0), &vol) == -1)
-        return;
+    if (ioctl(mixfd, SOUND_MIXER_READ_DEVMASK, &devmask) == -1) {
+        warn("OSS: Cannot read mixer information");
+        goto out;
+    }
+    if (ioctl(mixfd, MIXER_READ(0), &vol) == -1) {
+        warn("OSS: Cannot read mixer information");
+        goto out;
+    }
 
     if (((vol & 0x7f) == 0) && (((vol >> 8) & 0x7f) == 0)) {
         START_COLOR("color_degraded");