X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fprint_cpu_temperature.c;h=569ea6064e4aa234a2e157f68037610ffd01517a;hb=fadd4d89b1e196e009d5cd5cc2f6c3bdda83b12e;hp=57cb1148fbc85fee35c65825a55911a154ede05d;hpb=9375959b68d7c80dbad53a6eb0df1035bb33c6ce;p=i3%2Fi3status diff --git a/src/print_cpu_temperature.c b/src/print_cpu_temperature.c index 57cb114..569ea60 100644 --- a/src/print_cpu_temperature.c +++ b/src/print_cpu_temperature.c @@ -13,7 +13,7 @@ #include #include #include -#define TZ_ZEROC 2732 +#define TZ_ZEROC 2731 #define TZ_KELVTOC(x) (((x)-TZ_ZEROC) / 10), abs(((x)-TZ_ZEROC) % 10) #define TZ_AVG(x) ((x)-TZ_ZEROC) / 10 #endif @@ -112,7 +112,7 @@ static int read_temperature(char *thermal_zone, temperature_t *temperature) { /* 'path' is the node within the full path (defaults to acpitz0). */ if (BEGINS_WITH(sensordev.xname, thermal_zone)) { mib[3] = SENSOR_TEMP; - /* Limit to temo0, but should retrieve from a full path... */ + /* Limit to temp0, but should retrieve from a full path... */ for (numt = 0; numt < 1 /*sensordev.maxnumt[SENSOR_TEMP]*/; numt++) { mib[4] = numt; if (sysctl(mib, 5, &sensor, &slen, NULL, 0) == -1) { @@ -205,7 +205,7 @@ error_netbsd1: /* * Reads the CPU temperature from /sys/class/thermal/thermal_zone%d/temp (or - * the user provided path) and returns the temperature in degree celcius. + * the user provided path) and returns the temperature in degree celsius. * */ void print_cpu_temperature_info(yajl_gen json_gen, char *buffer, int zone, const char *path, const char *format, const char *format_above_threshold, int max_threshold) { @@ -216,12 +216,14 @@ void print_cpu_temperature_info(yajl_gen json_gen, char *buffer, int zone, const bool colorful_output = false; char *thermal_zone; temperature_t temperature; + temperature.raw_value = 0; + sprintf(temperature.formatted_value, "%.2f", 0.0); if (path == NULL) asprintf(&thermal_zone, THERMAL_ZONE, zone); else { static glob_t globbuf; - if (glob(path, GLOB_NOCHECK | GLOB_TILDE, NULL, &globbuf) < 0) + if (glob(path, GLOB_NOCHECK | GLOB_TILDE, NULL, &globbuf) != 0) die("glob() failed\n"); if (globbuf.gl_pathc == 0) { /* No glob matches, the specified path does not contain a wildcard. */ @@ -248,11 +250,13 @@ void print_cpu_temperature_info(yajl_gen json_gen, char *buffer, int zone, const for (walk = selected_format; *walk != '\0'; walk++) { if (*walk != '%') { *(outwalk++) = *walk; - continue; - } - if (BEGINS_WITH(walk + 1, "degrees")) { + + } else if (BEGINS_WITH(walk + 1, "degrees")) { outwalk += sprintf(outwalk, "%s", temperature.formatted_value); walk += strlen("degrees"); + + } else { + *(outwalk++) = '%'; } }