Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdf1b7c4

Browse files
committed
refactor(log): simplify log_path_init
Problem:Since22b52dd#11501, log_path_init is called in log_init, whichmeans it is now called at a deterministic time. So the "just in time"complexity of log_path_init is no longer needed.Solution:Remove logic intended to try to "heal" partial initialization.
1 parentf48aa68 commitdf1b7c4

File tree

1 file changed

+12
-46
lines changed

1 file changed

+12
-46
lines changed

‎src/nvim/log.c‎

Lines changed: 12 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,19 @@ static bool log_try_create(char *fname)
5454

5555
/// Initializes path to log file. Sets $NVIM_LOG_FILE if empty.
5656
///
57-
/// Tries $NVIM_LOG_FILE, or falls back to $XDG_STATE_HOME/nvim/log. Path to log
58-
/// file is cached, so only the first call has effect, unless first call was not
59-
/// successful. Failed initialization indicates either a bug in expand_env()
60-
/// or both $NVIM_LOG_FILE and $HOME environment variables are undefined.
61-
///
62-
/// @return true if path was initialized, false otherwise.
63-
staticboollog_path_init(void)
57+
/// Tries $NVIM_LOG_FILE, or falls back to $XDG_STATE_HOME/nvim/log. Failed
58+
/// initialization indicates either a bug in expand_env() or both $NVIM_LOG_FILE
59+
/// and $HOME environment variables are undefined.
60+
staticvoidlog_path_init(void)
6461
{
65-
if (log_file_path[0]) {
66-
return true;
67-
}
6862
size_tsize=sizeof(log_file_path);
6963
expand_env((char_u*)"$"LOG_FILE_ENV, (char_u*)log_file_path,
7064
(int)size-1);
7165
if (strequal("$"LOG_FILE_ENV,log_file_path)
7266
||log_file_path[0]=='\0'
7367
||os_isdir((char_u*)log_file_path)
7468
|| !log_try_create(log_file_path)) {
75-
// MakekXDGStateHome if it does not exist.
69+
// Make$XDG_STATE_HOME if it does not exist.
7670
char*loghome=get_xdg_home(kXDGStateHome);
7771
char*failed_dir=NULL;
7872
boollog_dir_failure= false;
@@ -91,7 +85,6 @@ static bool log_path_init(void)
9185
// Fall back to stderr
9286
if (len >=size|| !log_try_create(log_file_path)) {
9387
log_file_path[0]='\0';
94-
return false;
9588
}
9689
os_setenv(LOG_FILE_ENV,log_file_path, true);
9790
if (log_dir_failure) {
@@ -100,7 +93,6 @@ static bool log_path_init(void)
10093
}
10194
XFREE_CLEAR(failed_dir);
10295
}
103-
return true;
10496
}
10597

10698
voidlog_init(void)
@@ -166,21 +158,17 @@ bool logmsg(int log_level, const char *context, const char *func_name, int line_
166158
if (!did_msg) {
167159
did_msg= true;
168160
char*arg1=func_name ?xstrdup(func_name) : (context ?xstrdup(context) :NULL);
161+
// coverity[leaked_storage]
169162
loop_schedule_deferred(&main_loop,event_create(on_log_recursive_event,2,arg1,line_num));
170163
}
171164
g_stats.log_skip++;
172165
log_unlock();
173166
return false;
174167
}
175-
176168
recursive= true;
177169
boolret= false;
178170
FILE*log_file=open_log_file();
179171

180-
if (log_file==NULL) {
181-
gotoend;
182-
}
183-
184172
va_listargs;
185173
va_start(args,fmt);
186174
ret=v_do_log_to_file(log_file,log_level,context,func_name,line_num,
@@ -190,7 +178,7 @@ bool logmsg(int log_level, const char *context, const char *func_name, int line_
190178
if (log_file!=stderr&&log_file!=stdout) {
191179
fclose(log_file);
192180
}
193-
end:
181+
194182
recursive= false;
195183
log_unlock();
196184
returnret;
@@ -202,42 +190,26 @@ void log_uv_handles(void *loop)
202190
log_lock();
203191
FILE*log_file=open_log_file();
204192

205-
if (log_file==NULL) {
206-
gotoend;
207-
}
208-
209193
uv_print_all_handles(l,log_file);
210194

211195
if (log_file!=stderr&&log_file!=stdout) {
212196
fclose(log_file);
213197
}
214-
end:
198+
215199
log_unlock();
216200
}
217201

218202
/// Open the log file for appending.
219203
///
220-
/// @returnFILE* decided by log_path_init()or stderrin case of error
204+
/// @returnLog file,or stderron failure
221205
FILE*open_log_file(void)
222206
{
223-
staticboolrecursive= false;
224-
if (recursive) {
225-
abort();
226-
}
227-
228-
FILE*log_file=NULL;
229-
recursive= true;
230-
if (log_path_init()) {
231-
log_file=fopen(log_file_path,"a");
232-
}
233-
recursive= false;
234-
235-
if (log_file!=NULL) {
236-
returnlog_file;
207+
if (log_file_path[0]) {
208+
returnfopen(log_file_path,"a");
237209
}
238210

239211
// May happen if:
240-
// - LOG() is called beforeearly_init()
212+
// - LOG() is called beforelog_init()
241213
// - Directory does not exist
242214
// - File is not writable
243215
do_log_to_file(stderr,LOGLVL_ERR,NULL,__func__,__LINE__, true,
@@ -285,13 +257,7 @@ void log_callstack(const char *const func_name, const int line_num)
285257
{
286258
log_lock();
287259
FILE*log_file=open_log_file();
288-
if (log_file==NULL) {
289-
gotoend;
290-
}
291-
292260
log_callstack_to_file(log_file,func_name,line_num);
293-
294-
end:
295261
log_unlock();
296262
}
297263
#endif

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp