mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
fix(logging): try harder to resolve Nvim "name" #19016
Problem: If startup finishes (starting=false) before the logger ever happens to see a v:servername, we're stuck with the "?.<PID>" fallback name forever. Solution: Drop the `starting` condition. Discard the "?.<PID>" fallback after using it for the current log message. So logging will always check v:servername next time.
This commit is contained in:
parent
1ad6423f02
commit
9c0f2253a5
@ -8199,7 +8199,7 @@ varnumber_T get_vim_var_nr(int idx) FUNC_ATTR_PURE
|
|||||||
|
|
||||||
/// Get string v: variable value. Uses a static buffer, can only be used once.
|
/// Get string v: variable value. Uses a static buffer, can only be used once.
|
||||||
/// If the String variable has never been set, return an empty string.
|
/// If the String variable has never been set, return an empty string.
|
||||||
/// Never returns NULL;
|
/// Never returns NULL.
|
||||||
char *get_vim_var_str(int idx)
|
char *get_vim_var_str(int idx)
|
||||||
FUNC_ATTR_PURE FUNC_ATTR_NONNULL_RET
|
FUNC_ATTR_PURE FUNC_ATTR_NONNULL_RET
|
||||||
{
|
{
|
||||||
|
@ -305,15 +305,15 @@ static bool v_do_log_to_file(FILE *log_file, int log_level, const char *context,
|
|||||||
|
|
||||||
// Get a name for this Nvim instance.
|
// Get a name for this Nvim instance.
|
||||||
// TODO(justinmk): expose this as v:name ?
|
// TODO(justinmk): expose this as v:name ?
|
||||||
if (starting || name[0] == '\0') {
|
if (name[0] == '\0') {
|
||||||
// Parent servername.
|
// Parent servername.
|
||||||
const char *parent = path_tail(os_getenv(ENV_NVIM));
|
const char *parent = path_tail(os_getenv(ENV_NVIM));
|
||||||
// Servername. Empty until starting=false.
|
// Servername. Empty until starting=false.
|
||||||
const char *serv = path_tail(get_vim_var_str(VV_SEND_SERVER));
|
const char *serv = path_tail(get_vim_var_str(VV_SEND_SERVER));
|
||||||
if (parent && parent[0] != NUL) {
|
if (parent && parent[0] != NUL) {
|
||||||
snprintf(name, sizeof(name), "%s/c", parent); // "/c" indicates child.
|
snprintf(name, sizeof(name), "%s/c", parent); // "/c" indicates child.
|
||||||
} else if (serv && serv[0] != NUL) {
|
} else if (serv[0] != NUL) {
|
||||||
snprintf(name, sizeof(name), "%s", serv ? serv : "");
|
snprintf(name, sizeof(name), "%s", serv);
|
||||||
} else {
|
} else {
|
||||||
int64_t pid = os_get_pid();
|
int64_t pid = os_get_pid();
|
||||||
snprintf(name, sizeof(name), "?.%-5" PRId64, pid);
|
snprintf(name, sizeof(name), "?.%-5" PRId64, pid);
|
||||||
@ -329,6 +329,11 @@ static bool v_do_log_to_file(FILE *log_file, int log_level, const char *context,
|
|||||||
log_levels[log_level], date_time, millis, name,
|
log_levels[log_level], date_time, millis, name,
|
||||||
(context == NULL ? "" : context),
|
(context == NULL ? "" : context),
|
||||||
func_name, line_num);
|
func_name, line_num);
|
||||||
|
if (name[0] == '?') {
|
||||||
|
// No v:servername yet. Clear `name` so that the next log can try again.
|
||||||
|
name[0] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
if (rv < 0) {
|
if (rv < 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user