brewery
notashelf /
987f4fcc99a0c380b487742577efa3882379d13f

chroma

public

Lightweight wallpaper daemon for Wayland

Star0tarball
clone
ssh://git@git.notashelf.dev:33/notashelf/chroma.git

Commit 987f4fcc99a0

tarball

NotAShelf <raf@notashelf.dev> · 2026-04-15 10:08 UTC

unverified4 files changed+13-102
treewide: unify signal handling, error reporting, and string utils

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I8351ecccb03281e438dba666390021306a6a6964
diff --git a/include/chroma.h b/include/chroma.hindex 7ff7ead..6d51f92 100644--- a/include/chroma.h+++ b/include/chroma.h@@ -282,9 +282,6 @@ bool chroma_is_regular_file(const char *path); bool chroma_is_directory(const char *path); long chroma_get_file_size(const char *path); const char *chroma_get_file_extension(const char *path);-int chroma_strcasecmp(const char *s1, const char *s2);-size_t chroma_strlcpy(char *dst, const char *src, size_t size);-size_t chroma_strlcat(char *dst, const char *src, size_t size); long long chroma_get_time_ms(void); void chroma_sleep_ms(long ms); void chroma_format_memory_size(size_t bytes, char *buffer, size_t buffer_size);diff --git a/src/image.c b/src/image.cindex caea5e2..5b66862 100644--- a/src/image.c+++ b/src/image.c@@ -239,6 +239,11 @@ void chroma_image_free(chroma_image_t *image) {   if (image->data) {     // Log memory deallocation before freeing     size_t image_size = (size_t)image->width * image->height * image->channels;++    if (strlen(image->path) > 0) {+      chroma_log("DEBUG", "Freed image: %s", image->path);+    }+     chroma_log_resource_deallocation("image_data", image_size, image->path);      // Always use stbi_image_free since we load directly with stbi_loaddiff --git a/src/main.c b/src/main.cindex 9cbd464..b0d72c2 100644--- a/src/main.c+++ b/src/main.c@@ -1,3 +1,4 @@+#include <errno.h> #include <getopt.h> #include <signal.h> #include <stdio.h>@@ -32,49 +33,11 @@ static void print_version(void) {   printf("Minimal Wayland Multi-Monitor Wallpaper Daemon\n"); } -static void signal_handler(int sig) {-  switch (sig) {-  case SIGTERM:-  case SIGINT:-    chroma_should_quit = 1;-    break;-  case SIGHUP:-    // TODO: Implement config reload-    break;-  }-}--static int setup_signals(void) {-  struct sigaction sa;--  memset(&sa, 0, sizeof(sa));-  sa.sa_handler = signal_handler;-  sigemptyset(&sa.sa_mask);-  sa.sa_flags = SA_RESTART;--  if (sigaction(SIGTERM, &sa, NULL) == -1) {-    perror("sigaction(SIGTERM)");-    return -1;-  }--  if (sigaction(SIGINT, &sa, NULL) == -1) {-    perror("sigaction(SIGINT)");-    return -1;-  }--  if (sigaction(SIGHUP, &sa, NULL) == -1) {-    perror("sigaction(SIGHUP)");-    return -1;-  }--  return 0;-}- static int daemonize(void) {   pid_t pid = fork();    if (pid < 0) {-    perror("fork");+    chroma_log("ERROR", "fork: %s", strerror(errno));     return -1;   } @@ -85,13 +48,13 @@ static int daemonize(void) {    // Child process continues   if (setsid() < 0) {-    perror("setsid");+    chroma_log("ERROR", "setsid: %s", strerror(errno));     return -1;   }    // Change working directory to root   if (chdir("/") < 0) {-    perror("chdir");+    chroma_log("ERROR", "chdir: %s", strerror(errno));     return -1;   } @@ -166,12 +129,6 @@ int main(int argc, char *argv[]) {   // 0: ERROR+WARN only, 1: +INFO, 2: +DEBUG, 3+: +TRACE   chroma_set_log_level(verbose_level); -  // Set up signal handlers-  if (setup_signals() != 0) {-    fprintf(stderr, "Failed to set up signal handlers\n");-    return 1;-  }-   // Load configuration   if (!config_file) {     config_file = get_default_config_path();@@ -200,11 +157,14 @@ int main(int argc, char *argv[]) {   }   chroma_log_memory_stats("post-init"); +  // Set up signal handlers after state is initialized+  chroma_set_signal_state(&state, config_file);+  chroma_handle_signals();+   // Load configuration   chroma_log("INFO", "Loading configuration from: %s", config_file);   if (chroma_config_load(&state.config, config_file) != CHROMA_OK) {     chroma_log("WARN", "Failed to load config file, using defaults");-    // Continue with default configuration   }   chroma_log_memory_stats("post-config-load"); diff --git a/src/utils.c b/src/utils.cindex 5341c5b..24b9241 100644--- a/src/utils.c+++ b/src/utils.c@@ -442,57 +442,6 @@ const char *chroma_get_file_extension(const char *path) {   return last_dot + 1; } -// Case-insensitive string comparison-int chroma_strcasecmp(const char *s1, const char *s2) {-  if (!s1 || !s2) {-    return (s1 == s2) ? 0 : (s1 ? 1 : -1);-  }--  while (*s1 && *s2) {-    int c1 = tolower((unsigned char)*s1);-    int c2 = tolower((unsigned char)*s2);--    if (c1 != c2) {-      return c1 - c2;-    }--    s1++;-    s2++;-  }--  return tolower((unsigned char)*s1) - tolower((unsigned char)*s2);-}--// Safe string copy-size_t chroma_strlcpy(char *dst, const char *src, size_t size) {-  size_t src_len = strlen(src);--  if (size > 0) {-    size_t copy_len = (src_len < size - 1) ? src_len : size - 1;-    memcpy(dst, src, copy_len);-    dst[copy_len] = '\0';-  }--  return src_len;-}--// Safe string concatenation-size_t chroma_strlcat(char *dst, const char *src, size_t size) {-  size_t dst_len = strnlen(dst, size);-  size_t src_len = strlen(src);--  if (dst_len < size) {-    size_t copy_len = size - dst_len - 1;-    if (src_len < copy_len) {-      copy_len = src_len;-    }-    memcpy(dst + dst_len, src, copy_len);-    dst[dst_len + copy_len] = '\0';-  }--  return dst_len + src_len;-}- // Get current time in milliseconds long long chroma_get_time_ms(void) {   struct timeval tv;