Replace numerous printf statements with LOG_* macros, introduce system_volume_following parameter, and improve error handling throughout the daemon. New Features - Introduce LOG_INFO, LOG_ERROR, LOG_WARN for unified diagnostics. - Add support for system_volume_following when spawning child processes. - Log detailed startup information instead of raw printf. Enhancements - Refactor start_children signature to accept the new parameter. - Use strerror(errno) in error logs for clearer messages. - Improve signal handling output and reload request logging. Bug Fixes - Correct error formatting for pipe, fork, chdir, and execl failures. - Ensure proper handling of system_volume_following_str initialization. - Replace daemon‑specific prints with appropriate log levels.
127 lines
5.8 KiB
C
127 lines
5.8 KiB
C
#include "app/reload.h"
|
|
#include "app/process.h"
|
|
#include "common/log.h"
|
|
#include "common/utils.h"
|
|
#include "soundpacks.h"
|
|
#include "user_config.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
int handle_reload(const char *user_cfg_path, char *current_sound_name,
|
|
char *current_mouse_sound_name, int *current_keyboard_volume,
|
|
int *current_mouse_volume, char *current_config_path,
|
|
char *current_sound_dir, char *current_mouse_config_path,
|
|
char *current_mouse_sound_dir, int current_mute,
|
|
int current_verbose, int current_keyboard_mute,
|
|
int current_mouse_mute, int *current_keyboard_enabled,
|
|
int *current_mouse_enabled, int *current_system_volume_following) {
|
|
int g_verbose = current_verbose;
|
|
char *cfg_keyboard_sound = NULL;
|
|
char *cfg_mouse_sound = NULL;
|
|
int cfg_keyboard_volume = *current_keyboard_volume;
|
|
int cfg_mouse_volume = *current_mouse_volume;
|
|
int cfg_keyboard_enabled = *current_keyboard_enabled;
|
|
int cfg_mouse_enabled = *current_mouse_enabled;
|
|
int cfg_system_volume_following = *current_system_volume_following;
|
|
if (read_user_config(user_cfg_path, &cfg_keyboard_sound, &cfg_mouse_sound,
|
|
&cfg_keyboard_volume, &cfg_mouse_volume,
|
|
&cfg_keyboard_enabled, &cfg_mouse_enabled, &cfg_system_volume_following)) {
|
|
LOG_DEBUG("Read config - keyboard:%s mouse:%s kvol:%d mvol:%d kenabled:%d "
|
|
"menabled:%d",
|
|
cfg_keyboard_sound ? cfg_keyboard_sound : "NULL",
|
|
cfg_mouse_sound ? cfg_mouse_sound : "NULL", cfg_keyboard_volume,
|
|
cfg_mouse_volume, cfg_keyboard_enabled, cfg_mouse_enabled);
|
|
int keyboard_changed = 0, mouse_changed = 0, keyboard_volume_changed = 0,
|
|
mouse_volume_changed = 0, keyboard_enabled_changed = 0,
|
|
mouse_enabled_changed = 0, sysvol_following_changed = 0;
|
|
if (cfg_keyboard_sound &&
|
|
strcmp(current_sound_name, cfg_keyboard_sound) != 0) {
|
|
keyboard_changed = 1;
|
|
strncpy(current_sound_name, cfg_keyboard_sound, 1023);
|
|
current_sound_name[1023] = '\0';
|
|
}
|
|
if (cfg_mouse_sound &&
|
|
strcmp(current_mouse_sound_name, cfg_mouse_sound) != 0) {
|
|
mouse_changed = 1;
|
|
strncpy(current_mouse_sound_name, cfg_mouse_sound, 1023);
|
|
current_mouse_sound_name[1023] = '\0';
|
|
}
|
|
free(cfg_keyboard_sound);
|
|
free(cfg_mouse_sound);
|
|
if (cfg_keyboard_volume != *current_keyboard_volume) {
|
|
keyboard_volume_changed = 1;
|
|
*current_keyboard_volume = cfg_keyboard_volume;
|
|
}
|
|
if (cfg_mouse_volume != *current_mouse_volume) {
|
|
mouse_volume_changed = 1;
|
|
*current_mouse_volume = cfg_mouse_volume;
|
|
}
|
|
if (cfg_keyboard_enabled != *current_keyboard_enabled) {
|
|
keyboard_enabled_changed = 1;
|
|
*current_keyboard_enabled = cfg_keyboard_enabled;
|
|
}
|
|
if (cfg_mouse_enabled != *current_mouse_enabled) {
|
|
mouse_enabled_changed = 1;
|
|
*current_mouse_enabled = cfg_mouse_enabled;
|
|
}
|
|
if (cfg_system_volume_following != *current_system_volume_following) {
|
|
sysvol_following_changed = 1;
|
|
*current_system_volume_following = cfg_system_volume_following;
|
|
}
|
|
LOG_DEBUG("Config changed - keyboard:%d mouse:%d kvol:%d mvol:%d kenabled:%d "
|
|
"menabled:%d",
|
|
keyboard_changed, mouse_changed, keyboard_volume_changed,
|
|
mouse_volume_changed, keyboard_enabled_changed,
|
|
mouse_enabled_changed);
|
|
if (keyboard_changed || mouse_changed || keyboard_volume_changed ||
|
|
mouse_volume_changed || keyboard_enabled_changed ||
|
|
mouse_enabled_changed || sysvol_following_changed) {
|
|
// Persist enabled state to runtime files so the audio process picks it up
|
|
// immediately
|
|
write_runtime_keyboard_enabled_file(*current_keyboard_enabled);
|
|
write_runtime_mouse_enabled_file(*current_mouse_enabled);
|
|
write_runtime_system_volume_following_file(*current_system_volume_following);
|
|
int keyboard_valid = validate_keyboard_sound_pack(current_sound_name);
|
|
int mouse_valid = validate_mouse_sound_pack(current_mouse_sound_name);
|
|
if (keyboard_valid && mouse_valid) {
|
|
if (build_paths_for_keyboard_sound(current_sound_name,
|
|
current_config_path, 1024,
|
|
current_sound_dir, 1024)) {
|
|
if (build_paths_for_mouse_sound(current_mouse_sound_name,
|
|
current_mouse_config_path, 1024,
|
|
current_mouse_sound_dir, 1024)) {
|
|
stop_children();
|
|
start_children(current_sound_dir, current_config_path,
|
|
*current_keyboard_volume, current_verbose,
|
|
current_mute, current_mouse_sound_dir,
|
|
current_mouse_config_path, *current_mouse_volume,
|
|
current_keyboard_mute, current_mouse_mute,
|
|
*current_keyboard_enabled, *current_mouse_enabled,
|
|
*current_system_volume_following);
|
|
LOG_INFO("Reloaded successfully: keyboard=%s, mouse=%s, kvol=%d, "
|
|
"mvol=%d",
|
|
current_sound_name, current_mouse_sound_name,
|
|
*current_keyboard_volume, *current_mouse_volume);
|
|
return 1;
|
|
} else {
|
|
LOG_ERROR("Failed to build mouse sound paths");
|
|
}
|
|
} else {
|
|
LOG_ERROR("Failed to build keyboard sound paths");
|
|
}
|
|
} else {
|
|
if (!keyboard_valid)
|
|
LOG_ERROR("Reload failed: invalid keyboard sound pack '%s'",
|
|
current_sound_name);
|
|
if (!mouse_valid)
|
|
LOG_ERROR("Reload failed: invalid mouse sound pack '%s'",
|
|
current_mouse_sound_name);
|
|
}
|
|
}
|
|
} else {
|
|
LOG_ERROR("Failed to read user config");
|
|
}
|
|
return 0;
|
|
}
|