Fix bug with XSetRoot deadlock

This commit is contained in:
Alexander Rosenberg 2022-09-04 14:09:57 -07:00
parent b7ed7e230a
commit 85e710d3d5
Signed by: Zander671
GPG Key ID: 5FD0394ADBD72730

17
main.c
View File

@ -316,7 +316,8 @@ static arg_action interpret_flag_arg(const char *arg, const char *next) {
interpret_flag_character(*arg, next, return_action); interpret_flag_character(*arg, next, return_action);
if (current_action == ARG_ACTION_STOP) { if (current_action == ARG_ACTION_STOP) {
return ARG_ACTION_STOP; return ARG_ACTION_STOP;
} else if (current_action == ARG_ACTION_CONTINUE && return_action != ARG_ACTION_SKIP) { } else if (current_action == ARG_ACTION_CONTINUE &&
return_action != ARG_ACTION_SKIP) {
return_action = ARG_ACTION_CONTINUE; return_action = ARG_ACTION_CONTINUE;
} else if (current_action == ARG_ACTION_SKIP) { } else if (current_action == ARG_ACTION_SKIP) {
return_action = ARG_ACTION_SKIP; return_action = ARG_ACTION_SKIP;
@ -563,7 +564,6 @@ static void do_initial_refresh() {
} }
static void refresh_module(struct BarModule *module) { static void refresh_module(struct BarModule *module) {
sigprocmask(SIG_BLOCK, &global_real_time_mask, NULL);
if (module->last_text) { if (module->last_text) {
qtb_free(module->last_text); qtb_free(module->last_text);
module->last_text = NULL; module->last_text = NULL;
@ -574,7 +574,6 @@ static void refresh_module(struct BarModule *module) {
} else { } else {
module->last_text_length = 0; module->last_text_length = 0;
} }
sigprocmask(SIG_UNBLOCK, &global_real_time_mask, NULL);
} }
/* return TRUE if the module was refreshed, FALSE otherwise */ /* return TRUE if the module was refreshed, FALSE otherwise */
@ -595,6 +594,7 @@ static int check_and_refresh_module(struct BarModule *module,
static void module_poll_loop() { static void module_poll_loop() {
while (TRUE) { while (TRUE) {
sigprocmask(SIG_BLOCK, &global_real_time_mask, NULL);
struct timespec current_time; struct timespec current_time;
clock_gettime(global_cpu_clock_id, &current_time); clock_gettime(global_cpu_clock_id, &current_time);
unsigned long current_time_ms = timespec_to_miliseconds(&current_time); unsigned long current_time_ms = timespec_to_miliseconds(&current_time);
@ -616,6 +616,7 @@ static void module_poll_loop() {
timespec_diff(&current_time, &end_time, &span_time); timespec_diff(&current_time, &end_time, &span_time);
struct timespec final_sleep_time; struct timespec final_sleep_time;
timespec_diff(&span_time, &global_refresh_time, &final_sleep_time); timespec_diff(&span_time, &global_refresh_time, &final_sleep_time);
sigprocmask(SIG_UNBLOCK, &global_real_time_mask, NULL);
nanosleep(&final_sleep_time, NULL); nanosleep(&final_sleep_time, NULL);
} }
} }
@ -629,17 +630,17 @@ static void rewrite_bar() {
size_t i; size_t i;
for (i = 0; i < global_module_count - 1; ++i) { for (i = 0; i < global_module_count - 1; ++i) {
if (modules[i].last_text) { if (modules[i].last_text) {
bar_text = qtb_realloc( bar_text = qtb_realloc(bar_text,
bar_text, (bar_length += modules[i].last_text_length + (bar_length += modules[i].last_text_length +
global_seperator_length)); global_seperator_length));
strcat(bar_text, modules[i].last_text); strcat(bar_text, modules[i].last_text);
strcat(bar_text, SEPERATOR_TEXT); strcat(bar_text, SEPERATOR_TEXT);
} }
} }
struct BarModule *last_module = &modules[global_module_count - 1]; struct BarModule *last_module = &modules[global_module_count - 1];
if (last_module->last_text) { if (last_module->last_text) {
bar_text = qtb_realloc( bar_text = qtb_realloc(bar_text,
bar_text, (bar_length += last_module->last_text_length)); (bar_length += last_module->last_text_length));
strcat(bar_text, last_module->last_text); strcat(bar_text, last_module->last_text);
} }
strcat(bar_text, SUFFIX_TEXT); strcat(bar_text, SUFFIX_TEXT);