summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Stapelberg <stapelberg@users.noreply.github.com>2015-03-25 08:56:00 +0100
committerMichael Stapelberg <stapelberg@users.noreply.github.com>2015-03-25 08:56:00 +0100
commitbe583ea739fd2412138c1d73a01ca4a5ca4e9252 (patch)
treece0a76d9f000ef1cd13eadb5ae2f126174846e6a /src
parentbf223d9b61498a6b1e723bacb007545a696141fe (diff)
parentc9dc67e0542a0f540b014e8b2607bfc269433951 (diff)
Merge pull request #13 from bapt/master
Fixes for FreeBSD
Diffstat (limited to 'src')
-rw-r--r--src/print_cpu_usage.c2
-rw-r--r--src/print_disk_info.c3
-rw-r--r--src/print_eth_info.c6
-rw-r--r--src/print_volume.c19
4 files changed, 20 insertions, 10 deletions
diff --git a/src/print_cpu_usage.c b/src/print_cpu_usage.c
index 68437b3..2c59f69 100644
--- a/src/print_cpu_usage.c
+++ b/src/print_cpu_usage.c
@@ -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)
diff --git a/src/print_disk_info.c b/src/print_disk_info.c
index b9047e5..69d7b8c 100644
--- a/src/print_disk_info.c
+++ b/src/print_disk_info.c
@@ -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>
diff --git a/src/print_eth_info.c b/src/print_eth_info.c
index af5a757..06a1613 100644
--- a/src/print_eth_info.c
+++ b/src/print_eth_info.c
@@ -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 */
diff --git a/src/print_volume.c b/src/print_volume.c
index ef1c913..bc469f3 100644
--- a/src/print_volume.c
+++ b/src/print_volume.c
@@ -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");