Skip to content

Commit

Permalink
Fix IPC config overriding previous values
Browse files Browse the repository at this point in the history
Before this patch whenever changing the IPC configuration, all previous
configuration options would be discarded. This was the case even when
the new option was invalid.

This patch ensures that the IPC config is only ever cleared when the
`--reset` flag is passed. Invalid IPC config options are logged and
discarded.

Additionally whenever a new IPC config message is sent, all previous IPC
error messages are cleared.

Closes #6330.
  • Loading branch information
chrisduerr committed Sep 17, 2022
1 parent fb82601 commit 0b03878
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
16 changes: 14 additions & 2 deletions alacritty/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,27 @@ use std::{env, process};
use glutin::event_loop::EventLoopProxy;
use log::{self, Level, LevelFilter};

use alacritty_terminal::config::LOG_TARGET_CONFIG;

use crate::cli::Options;
use crate::event::{Event, EventType};
use crate::message_bar::{Message, MessageType};

/// Logging target for IPC config error messages.
pub const LOG_TARGET_IPC_CONFIG: &str = "alacritty_log_ipc_config";

/// Name for the environment variable containing the log file's path.
const ALACRITTY_LOG_ENV: &str = "ALACRITTY_LOG";

/// List of targets which will be logged by Alacritty.
const ALLOWED_TARGETS: [&str; 4] =
["alacritty_terminal", "alacritty_config_derive", "alacritty", "crossfont"];
const ALLOWED_TARGETS: &[&str] = &[
LOG_TARGET_IPC_CONFIG,
LOG_TARGET_CONFIG,
"alacritty_config_derive",
"alacritty_terminal",
"alacritty",
"crossfont",
];

pub fn initialize(
options: &Options,
Expand Down
36 changes: 28 additions & 8 deletions alacritty/src/window_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use crate::config::UiConfig;
use crate::display::Display;
use crate::event::{ActionContext, Event, EventProxy, EventType, Mouse, SearchState};
use crate::input;
use crate::logging::LOG_TARGET_IPC_CONFIG;
use crate::message_bar::MessageBuffer;
use crate::scheduler::Scheduler;

Expand Down Expand Up @@ -184,10 +185,20 @@ impl WindowContext {
if !self.ipc_config.is_empty() {
let mut config = (*self.config).clone();

// Apply each option.
for (key, value) in &self.ipc_config {
if let Err(err) = config.replace(key, value.clone()) {
error!("Unable to override option '{}': {}", key, err);
// Apply each option, removing broken ones.
let mut i = 0;
while i < self.ipc_config.len() {
let (key, value) = &self.ipc_config[i];

match config.replace(key, value.clone()) {
Err(err) => {
error!(
target: LOG_TARGET_IPC_CONFIG,
"Unable to override option '{}': {}", key, err
);
self.ipc_config.swap_remove(i);
},
Ok(_) => i += 1,
}
}

Expand Down Expand Up @@ -255,23 +266,32 @@ impl WindowContext {
/// Update the IPC config overrides.
#[cfg(unix)]
pub fn update_ipc_config(&mut self, config: Rc<UiConfig>, ipc_config: IpcConfig) {
self.ipc_config.clear();
// Clear previous IPC errors.
self.message_buffer.remove_target(LOG_TARGET_IPC_CONFIG);

if !ipc_config.reset {
if ipc_config.reset {
self.ipc_config.clear();
} else {
for option in &ipc_config.options {
// Separate config key/value.
let (key, value) = match option.split_once('=') {
Some(split) => split,
None => {
error!("'{}': IPC config option missing value", option);
error!(
target: LOG_TARGET_IPC_CONFIG,
"'{}': IPC config option missing value", option
);
continue;
},
};

// Try and parse value as yaml.
match serde_yaml::from_str(value) {
Ok(value) => self.ipc_config.push((key.to_owned(), value)),
Err(err) => error!("'{}': Invalid IPC config value: {:?}", option, err),
Err(err) => error!(
target: LOG_TARGET_IPC_CONFIG,
"'{}': Invalid IPC config value: {:?}", option, err
),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions alacritty_terminal/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::ansi::{CursorShape, CursorStyle};

pub use crate::config::scrolling::{Scrolling, MAX_SCROLLBACK_LINES};

/// Logging target for config error messages.
pub const LOG_TARGET_CONFIG: &str = "alacritty_config_derive";

const MIN_BLINK_INTERVAL: u64 = 10;
Expand Down

0 comments on commit 0b03878

Please sign in to comment.