@@ -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- static bool log_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+ static void log_path_init (void )
6461{
65- if (log_file_path [0 ]) {
66- return true;
67- }
6862size_t size = sizeof (log_file_path );
6963expand_env ((char_u * )"$" LOG_FILE_ENV , (char_u * )log_file_path ,
7064 (int )size - 1 );
7165if (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.
7670char * loghome = get_xdg_home (kXDGStateHome );
7771char * failed_dir = NULL ;
7872bool log_dir_failure = false;
@@ -91,7 +85,6 @@ static bool log_path_init(void)
9185// Fall back to stderr
9286if (len >=size || !log_try_create (log_file_path )) {
9387log_file_path [0 ]= '\0' ;
94- return false;
9588 }
9689os_setenv (LOG_FILE_ENV ,log_file_path , true);
9790if (log_dir_failure ) {
@@ -100,7 +93,6 @@ static bool log_path_init(void)
10093 }
10194XFREE_CLEAR (failed_dir );
10295 }
103- return true;
10496}
10597
10698void log_init (void )
@@ -166,21 +158,17 @@ bool logmsg(int log_level, const char *context, const char *func_name, int line_
166158if (!did_msg ) {
167159did_msg = true;
168160char * arg1 = func_name ?xstrdup (func_name ) : (context ?xstrdup (context ) :NULL );
161+ // coverity[leaked_storage]
169162loop_schedule_deferred (& main_loop ,event_create (on_log_recursive_event ,2 ,arg1 ,line_num ));
170163 }
171164g_stats .log_skip ++ ;
172165log_unlock ();
173166return false;
174167 }
175-
176168recursive = true;
177169bool ret = false;
178170FILE * log_file = open_log_file ();
179171
180- if (log_file == NULL ) {
181- gotoend ;
182- }
183-
184172va_list args ;
185173va_start (args ,fmt );
186174ret = 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_
190178if (log_file != stderr && log_file != stdout ) {
191179fclose (log_file );
192180 }
193- end :
181+
194182recursive = false;
195183log_unlock ();
196184return ret ;
@@ -202,42 +190,26 @@ void log_uv_handles(void *loop)
202190log_lock ();
203191FILE * log_file = open_log_file ();
204192
205- if (log_file == NULL ) {
206- gotoend ;
207- }
208-
209193uv_print_all_handles (l ,log_file );
210194
211195if (log_file != stderr && log_file != stdout ) {
212196fclose (log_file );
213197 }
214- end :
198+
215199log_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
221205FILE * open_log_file (void )
222206{
223- static bool recursive = 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- return log_file ;
207+ if (log_file_path [0 ]) {
208+ return fopen (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
243215do_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{
286258log_lock ();
287259FILE * log_file = open_log_file ();
288- if (log_file == NULL ) {
289- gotoend ;
290- }
291-
292260log_callstack_to_file (log_file ,func_name ,line_num );
293-
294- end :
295261log_unlock ();
296262}
297263#endif