*
*
* Copyright © 2008-2009 Michael Stapelberg and contributors
+ * Copyright © 2009 Thorsten Toepper <atsutane at freethoughts dot de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
#include <glob.h>
#include <dirent.h>
#include <getopt.h>
+#include <signal.h>
#include "queue.h"
static const char *time_format;
static bool use_colors;
static bool get_ethspeed;
+static bool get_cpu_temperature;
+static char *thermal_zone;
static const char *wmii_normcolors = "#222222 #333333";
static char order[MAX_ORDER][2];
static const char **run_watches;
create_file(concat(order[ORDER_WLAN],"wlan"));
if (eth_interface)
create_file(concat(order[ORDER_ETH],"eth"));
+ if (get_cpu_temperature)
+ create_file(concat(order[ORDER_CPU_TEMPERATURE], "cpu_temperature"));
create_file(concat(order[ORDER_LOAD],"load"));
if (time_format)
create_file(concat(order[ORDER_TIME],"time"));
static void write_to_statusbar(const char *name, const char *message, bool final_entry) {
#ifdef DZEN
if (final_entry) {
- (void)printf("%s^p(6)\n", message);
+ if (printf("%s^p(6)\n", message) < 0) {
+ perror("printf");
+ exit(1);
+ }
+
fflush(stdout);
return;
}
- (void)printf("%s" BAR, message);
+ if (printf("%s" BAR, message) < 0) {
+ perror("printf");
+ exit(1);
+ }
return;
#endif
return part;
}
+/*
+ * Reads the CPU temperature from /sys/class/thermal/thermal_zone0/temp and
+ * returns the temperature in degree celcius.
+ *
+ */
+static char *get_cpu_temperature_info() {
+ static char part[16];
+ char buf[16];
+ int temp;
+ int fd;
+
+ memset(buf, 0, sizeof(buf));
+ memset(part, 0, sizeof(part));
+
+ if ((fd = open(thermal_zone, O_RDONLY)) == -1)
+ die("Could not open %s\n", thermal_zone);
+ (void)read(fd, buf, sizeof(buf));
+ (void)close(fd);
+
+ if (sscanf(buf, "%d", &temp) != 1)
+ (void)snprintf(part, sizeof(part), "T: ? C");
+ else
+ (void)snprintf(part, sizeof(part), "T: %d C", (temp/1000));
+
+ return part;
+}
+
/*
* Checks if the PID in path is still valid by checking:
* (Linux) if /proc/<pid> exists
use_colors = true;
OPT("get_ethspeed")
get_ethspeed = true;
- OPT("normcolors")
+ OPT("get_cpu_temperature") {
+ get_cpu_temperature = true;
+ if (strlen(dest_value) > 0) {
+ if (asprintf(&thermal_zone, "/sys/class/thermal/thermal_zone%d/temp", atoi(dest_value)) == -1)
+ die("Could not build thermal_zone path\n");
+ } else {
+ if (asprintf(&thermal_zone, "/sys/class/thermal/thermal_zone0/temp") == -1)
+ die("Could not build thermal_zone path\n");
+ }
+ } OPT("normcolors")
wmii_normcolors = strdup(dest_value);
OPT("interval")
interval = atoi(dest_value);
SET_ORDER("wlan", ORDER_WLAN);
SET_ORDER("eth", ORDER_ETH);
SET_ORDER("battery", ORDER_BATTERY);
+ SET_ORDER("cpu_temperature", ORDER_CPU_TEMPERATURE);
SET_ORDER("load", ORDER_LOAD);
SET_ORDER("time", ORDER_TIME);
token = walk;
return result;
}
+/*
+ * Exit upon SIGPIPE because when we have nowhere to write to, gathering
+ * system information is pointless.
+ *
+ */
+void sigpipe(int signum) {
+ fprintf(stderr, "Received SIGPIPE, exiting\n");
+ exit(1);
+}
+
int main(int argc, char *argv[]) {
char part[512],
pathbuf[512];
{0, 0, 0, 0}
};
+ struct sigaction action;
+ memset(&action, 0, sizeof(struct sigaction));
+ action.sa_handler = sigpipe;
+ sigaction(SIGPIPE, &action, NULL);
+
SIMPLEQ_INIT(&batteries);
while ((o = getopt_long(argc, argv, "c:h", long_options, &option_index)) != -1)
SIMPLEQ_FOREACH(current_battery, &batteries, batteries) {
write_to_statusbar(concat(order[ORDER_BATTERY], "battery"), get_battery_info(current_battery), false);
}
+ if (get_cpu_temperature)
+ write_to_statusbar(concat(order[ORDER_CPU_TEMPERATURE], "cpu_temperature"), get_cpu_temperature_info(), false);
/* Get load */
#ifdef LINUX