]> git.sur5r.net Git - i3/i3status/commitdiff
Error handling: Never output null as full_text (JSON), prefix messages with i3status...
authorMichael Stapelberg <michael@stapelberg.de>
Wed, 9 May 2012 16:56:57 +0000 (18:56 +0200)
committerMichael Stapelberg <michael@stapelberg.de>
Wed, 9 May 2012 16:56:57 +0000 (18:56 +0200)
The former made i3bar crash, the latter is helpful for debugging.

src/print_cpu_temperature.c
src/print_cpu_usage.c
src/print_ip_addr.c
src/print_ipv6_addr.c
src/print_load.c
src/print_volume.c

index 7797f061dc9cacfa090784a0db592f896271876b..8e7d7f9c4c23e0392c0e1940ec249e9b6dd24cfe 100644 (file)
@@ -113,5 +113,6 @@ void print_cpu_temperature_info(yajl_gen json_gen, char *buffer, int zone, const
         return;
 error:
 #endif
+        OUTPUT_FULL_TEXT("cant read temp");
         (void)fputs("i3status: Cannot read temperature. Verify that you have a thermal zone in /sys/class/thermal or disable the cpu_temperature module in your i3status config.\n", stderr);
 }
index 7113eaebfe80fc9e1d1a4d815aa0d54497a7424a..782084014433e831ff6ff46984f7247012b67945 100644 (file)
@@ -92,5 +92,6 @@ void print_cpu_usage(yajl_gen json_gen, char *buffer, const char *format) {
         OUTPUT_FULL_TEXT(buffer);
         return;
 error:
-        (void)fputs("Cannot read usage\n", stderr);
+        OUTPUT_FULL_TEXT("cant read cpu usage");
+        (void)fputs("i3status: Cannot read CPU usage\n", stderr);
 }
index 778427c940669c1d09230e1b81395718e94a4761..909a8b261b697c4b1166dc937a2c0628963117d8 100644 (file)
@@ -56,7 +56,7 @@ const char *get_ip_addr(const char *interface) {
 
         int ret;
         if ((ret = getnameinfo(addrp->ifa_addr, len, part, sizeof(part), NULL, 0, NI_NUMERICHOST)) != 0) {
-                fprintf(stderr, "getnameinfo(): %s\n", gai_strerror(ret));
+                fprintf(stderr, "i3status: getnameinfo(): %s\n", gai_strerror(ret));
                 freeifaddrs(ifaddr);
                 return "no IP";
         }
index f987b596b1471dc2cbaea3de25707619582cfc19..b7f668a4a6ba8353405f4a3268b17472ddbbfb17 100644 (file)
@@ -51,7 +51,7 @@ static char *get_sockname(struct addrinfo *addr) {
         if ((ret = getnameinfo((struct sockaddr*)&local, local_len,
                                buf, sizeof(buf), NULL, 0,
                                NI_NUMERICHOST)) != 0) {
-                fprintf(stderr, "getnameinfo(): %s\n", gai_strerror(ret));
+                fprintf(stderr, "i3status: getnameinfo(): %s\n", gai_strerror(ret));
                 (void)close(fd);
                 return NULL;
         }
index d0d65f731f27d516248d89e58bf091f15a2d3b6f..7fd54ca6f1a6f6af7a24649d6f8f750fcf5d9e57 100644 (file)
@@ -45,5 +45,6 @@ void print_load(yajl_gen json_gen, char *buffer, const char *format) {
         return;
 error:
 #endif
-        (void)fputs("Cannot read load\n", stderr);
+        OUTPUT_FULL_TEXT("cant read load");
+        (void)fputs("i3status: Cannot read system load using getloadavg()\n", stderr);
 }
index 7b38e6343fdf35a0cbe741dfbee5b562955bda91..dbf5e1ff02022f521f05c3cc4dd428911593fb07 100644 (file)
@@ -97,14 +97,14 @@ void print_volume(yajl_gen json_gen, char *buffer, const char *fmt, const char *
                }
 
                if ((err = snd_mixer_open(&(hdl->m), 0)) < 0) {
-                       fprintf(stderr, "ALSA: Cannot open mixer: %s\n", snd_strerror(err));
+                       fprintf(stderr, "i3status: ALSA: Cannot open mixer: %s\n", snd_strerror(err));
                        free_hdl(hdl);
                        return;
                }
 
                /* Attach this mixer handle to the given device */
                if ((err = snd_mixer_attach(hdl->m, device)) < 0) {
-                       fprintf(stderr, "ALSA: Cannot attach mixer to device: %s\n", snd_strerror(err));
+                       fprintf(stderr, "i3status: ALSA: Cannot attach mixer to device: %s\n", snd_strerror(err));
                        snd_mixer_close(hdl->m);
                        free_hdl(hdl);
                        return;
@@ -112,14 +112,14 @@ void print_volume(yajl_gen json_gen, char *buffer, const char *fmt, const char *
 
                /* Register this mixer */
                if ((err = snd_mixer_selem_register(hdl->m, NULL, NULL)) < 0) {
-                       fprintf(stderr, "ALSA: snd_mixer_selem_register: %s\n", snd_strerror(err));
+                       fprintf(stderr, "i3status: ALSA: snd_mixer_selem_register: %s\n", snd_strerror(err));
                        snd_mixer_close(hdl->m);
                        free_hdl(hdl);
                        return;
                }
 
                if ((err = snd_mixer_load(hdl->m)) < 0) {
-                       fprintf(stderr, "ALSA: snd_mixer_load: %s\n", snd_strerror(err));
+                       fprintf(stderr, "i3status: ALSA: snd_mixer_load: %s\n", snd_strerror(err));
                        snd_mixer_close(hdl->m);
                        free_hdl(hdl);
                        return;
@@ -129,7 +129,7 @@ void print_volume(yajl_gen json_gen, char *buffer, const char *fmt, const char *
                snd_mixer_selem_id_set_index(hdl->sid, mixer_idx);
                snd_mixer_selem_id_set_name(hdl->sid, mixer);
                if (!(hdl->elem = snd_mixer_find_selem(hdl->m, hdl->sid))) {
-                       fprintf(stderr, "ALSA: Cannot find mixer %s (index %i)\n",
+                       fprintf(stderr, "i3status: ALSA: Cannot find mixer %s (index %i)\n",
                                snd_mixer_selem_id_get_name(hdl->sid), snd_mixer_selem_id_get_index(hdl->sid));
                        snd_mixer_close(hdl->m);
                        free_hdl(hdl);
@@ -155,7 +155,7 @@ void print_volume(yajl_gen json_gen, char *buffer, const char *fmt, const char *
        if (snd_mixer_selem_has_playback_switch(hdl->elem)) {
                int pbval;
                if ((err = snd_mixer_selem_get_playback_switch(hdl->elem, 0, &pbval)) < 0)
-                       fprintf (stderr, "ALSA: playback_switch: %s\n", snd_strerror(err));
+                       fprintf (stderr, "i3status: ALSA: playback_switch: %s\n", snd_strerror(err));
                if (!pbval)
                        avg = 0;
        }