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)
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
-#include <mntent.h>
#include <stdint.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
#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>
} 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 */
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
+#include <err.h>
#include <yajl/yajl_gen.h>
#include <yajl/yajl_version.h>
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");