Compare commits

..

3 commits
v1.1 ... master

Author SHA1 Message Date
0a88ca1b8c
check that paths exist before using them 2026-01-08 14:50:28 -05:00
1456db633d
remove unused macro 2026-01-07 16:07:07 -05:00
d4c1c34016
a :retab a day keeps the doctor away 2026-01-07 16:06:42 -05:00
4 changed files with 127 additions and 100 deletions

View file

@ -1,7 +1,5 @@
#pragma once #pragma once
#define LED_BLINK_TRIGGER_DISABLED 101
/** /**
* @brief parse the config file * @brief parse the config file
* *
@ -14,6 +12,11 @@ void parse_config_file(char *path);
*/ */
void setup_led_formula(void); void setup_led_formula(void);
/**
* @brief ensure that the config paths are valid
*/
void check_config();
extern char *battery_status_path; extern char *battery_status_path;
extern char *battery_power_source; extern char *battery_power_source;

View file

@ -3,6 +3,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <log.h> #include <log.h>
#include <sys/stat.h>
#include <toml.h> #include <toml.h>
#include <tinyexpr.h> #include <tinyexpr.h>
@ -13,7 +14,7 @@
if (!v) { \ if (!v) { \
log_warn("missing [%s]", vn); \ log_warn("missing [%s]", vn); \
} \ } \
} while (0); } while (0)
#define set_str_conf(op, tt, v) do { \ #define set_str_conf(op, tt, v) do { \
toml_datum_t val; \ toml_datum_t val; \
@ -21,7 +22,7 @@
if (val.ok) { \ if (val.ok) { \
op = val.u.s; \ op = val.u.s; \
} \ } \
} while (0); } while (0)
#define set_int_conf(op, tt, v) do { \ #define set_int_conf(op, tt, v) do { \
toml_datum_t val; \ toml_datum_t val; \
@ -29,7 +30,15 @@
if (val.ok) { \ if (val.ok) { \
op = val.u.i; \ op = val.u.i; \
} \ } \
} while (0); } while (0)
#define check_path(path) do { \
struct stat sb; \
if (stat(path, &sb) == -1) { \
log_fatal("path does not exist: %s", path); \
exit(1); \
} \
} while (0)
static te_expr *expr; static te_expr *expr;
static double percentage; static double percentage;
@ -105,5 +114,16 @@ parse_config_file(char *path)
set_str_conf(led_blink_timing_formula, led_blink, "timing_formula"); set_str_conf(led_blink_timing_formula, led_blink, "timing_formula");
set_str_conf(acpi_daemon_socket_path, acpi_daemon, "socket_path"); set_str_conf(acpi_daemon_socket_path, acpi_daemon, "socket_path");
check_config();
toml_free(config); toml_free(config);
} }
void
check_config()
{
check_path(battery_status_path);
check_path(battery_power_source);
check_path(led_brightness_path);
check_path(acpi_daemon_socket_path);
}

View file

@ -86,7 +86,7 @@ int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
cag_option_context context; cag_option_context context;
bool plugged = plugged_in(battery_power_source); bool plugged;
char buffer[MAX_BUFLEN], *out[4], *config_path, *percent; char buffer[MAX_BUFLEN], *out[4], *config_path, *percent;
int sock_fd; int sock_fd;
bool debug = false; bool debug = false;
@ -113,6 +113,10 @@ main(int argc, char *argv[])
break; break;
} }
} }
check_config();
/* get current plugged in state */
plugged = plugged_in(battery_power_source);
/* configure the led blinking formula */ /* configure the led blinking formula */
setup_led_formula(); setup_led_formula();