all repos — slstatus @ b51721c65a8ec2067c599c076d2db6b4a29f567a

my build of slstatus (tools.suckless.org/slstatus/)

add config checks on startup for better error handling
Daniel Walter d.walter@0x90.at
Thu, 10 Mar 2016 12:11:46 +0100
commit

b51721c65a8ec2067c599c076d2db6b4a29f567a

parent

5295629c4fe987ee51fcfdd380c86e3e0d5de5b5

1 files changed, 25 insertions(+), 0 deletions(-)

jump to
M slstatus.cslstatus.c

@@ -2,10 +2,13 @@ /* See LICENSE file for copyright and license details. */

/* global libraries */ #include <alsa/asoundlib.h> +#include <fcntl.h> #include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <sys/types.h> +#include <sys/stat.h> #include <time.h> #include <unistd.h> #include <X11/Xlib.h>

@@ -15,6 +18,7 @@ #include "config.h"

/* functions */ void setstatus(char *str); +int config_check(); char *smprintf(char *fmt, ...); char *get_battery(); char *get_cpu_temperature();

@@ -47,6 +51,22 @@ return NULL;

va_end(fmtargs); return ret; +} + +#define CHECK_FILE(X,Y) do { \ + if (stat(X,&Y) < 0) return -1; \ + if (!S_ISREG(Y.st_mode)) return -1; \ +} while (0); + +/* check configured paths */ +int +config_check() +{ + struct stat fs; + CHECK_FILE(batterynowfile, fs); + CHECK_FILE(batteryfullfile, fs); + CHECK_FILE(tempfile, fs); + return 0; } /* battery percentage */

@@ -314,6 +334,11 @@ char *ram_usage = NULL;

char *volume = NULL; char *wifi_signal = NULL; + /* check config for sanity */ + if (config_check() < 0) { + fprintf(stderr, "Config error, please check paths and recompile\n"); + exit(1); + } /* open display */ if (!(dpy = XOpenDisplay(0x0))) { fprintf(stderr, "Cannot open display!\n");