mirror of
https://github.com/neovim/neovim.git
synced 2026-04-23 07:45:32 +00:00
feat(startup): warn if NVIM_LOG_FILE is inaccessible #38070
Problem: If NVIM_LOG_FILE, or the default fallback, is inaccessible (e.g. directory is owned by root), users get confused. Solution: Show a warning when $NVIM_LOG_FILE or $XDG_STATE_HOME are inaccessible. Also fix a latent memory leak: `os_mkdir_recurse` returns a uv error code (int), but it was stored as `bool`, causing `os_strerror` to receive an invalid error code and leak memory. See: https://docs.libuv.org/en/v1.x/errors.html#c.uv_strerror Co-authored-by: Sean Dewar <6256228+seandewar@users.noreply.github.com> Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
This commit is contained in:
@@ -541,6 +541,18 @@ end
|
||||
|
||||
--- Default autocommands. See |default-autocmds|
|
||||
do
|
||||
-- Warn if $NVIM_LOG_FILE or $XDG_STATE_HOME are inaccessible. #38039
|
||||
if vim.v.vim_did_enter then
|
||||
require('vim._core.log').check_log_file()
|
||||
else
|
||||
vim.api.nvim_create_autocmd('VimEnter', {
|
||||
once = true,
|
||||
callback = function()
|
||||
require('vim._core.log').check_log_file()
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
local nvim_terminal_augroup = vim.api.nvim_create_augroup('nvim.terminal', {})
|
||||
vim.api.nvim_create_autocmd('BufReadCmd', {
|
||||
pattern = 'term://*',
|
||||
|
||||
30
runtime/lua/vim/_core/log.lua
Normal file
30
runtime/lua/vim/_core/log.lua
Normal file
@@ -0,0 +1,30 @@
|
||||
local M = {}
|
||||
|
||||
--- Checks that the logfile is accessible.
|
||||
function M.check_log_file()
|
||||
if vim.fn.mode() == 'c' then -- Ex mode
|
||||
return
|
||||
end
|
||||
|
||||
local wanted = vim.fn.getenv('__NVIM_LOG_FILE_WANT')
|
||||
if not wanted or wanted == vim.NIL then
|
||||
return
|
||||
end
|
||||
|
||||
local actual = vim.fn.getenv('NVIM_LOG_FILE')
|
||||
|
||||
local msg --[[@type string]]
|
||||
if not actual or actual == vim.NIL or actual == '' then
|
||||
msg = ('log: %q not accessible, logging disabled (stderr)'):format(wanted)
|
||||
elseif actual ~= wanted then
|
||||
msg = ('log: %q not accessible, logging to: %q'):format(wanted, actual)
|
||||
else
|
||||
return
|
||||
end
|
||||
|
||||
vim.defer_fn(function()
|
||||
vim.notify(msg, vim.log.levels.WARN)
|
||||
end, 100)
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user