mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	fix(startup): report --startuptime error to stderr (#31131)
Problem:  Crash when initializing for --startuptime errors.
Solution: Report the error to stderr, as neither logging nor messages
          have been initialized yet.
(cherry picked from commit 17e00d0cc6)
			
			
This commit is contained in:
		 zeertzjq
					zeertzjq
				
			
				
					committed by
					
						![github-actions[bot]](/assets/img/avatar_default.png) github-actions[bot]
						github-actions[bot]
					
				
			
			
				
	
			
			
			![github-actions[bot]](/assets/img/avatar_default.png) github-actions[bot]
						github-actions[bot]
					
				
			
						parent
						
							f8ee92feec
						
					
				
				
					commit
					57b0fecd47
				
			| @@ -955,7 +955,7 @@ void time_init(const char *fname, const char *process_name) | |||||||
|   const size_t bufsize = 8192;  // Big enough for the entire --startuptime report. |   const size_t bufsize = 8192;  // Big enough for the entire --startuptime report. | ||||||
|   time_fd = fopen(fname, "a"); |   time_fd = fopen(fname, "a"); | ||||||
|   if (time_fd == NULL) { |   if (time_fd == NULL) { | ||||||
|     semsg(_(e_notopen), fname); |     fprintf(stderr, _(e_notopen), fname); | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   startuptime_buf = xmalloc(sizeof(char) * (bufsize + 1)); |   startuptime_buf = xmalloc(sizeof(char) * (bufsize + 1)); | ||||||
| @@ -967,8 +967,7 @@ void time_init(const char *fname, const char *process_name) | |||||||
|     XFREE_CLEAR(startuptime_buf); |     XFREE_CLEAR(startuptime_buf); | ||||||
|     fclose(time_fd); |     fclose(time_fd); | ||||||
|     time_fd = NULL; |     time_fd = NULL; | ||||||
|     ELOG("time_init: setvbuf failed: %d %s", r, uv_err_name(r)); |     fprintf(stderr, "time_init: setvbuf failed: %d %s", r, uv_err_name(r)); | ||||||
|     semsg("time_init: setvbuf failed: %d %s", r, uv_err_name(r)); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   fprintf(time_fd, "--- Startup times for process: %s ---\n", process_name); |   fprintf(time_fd, "--- Startup times for process: %s ---\n", process_name); | ||||||
|   | |||||||
| @@ -82,6 +82,25 @@ describe('startup', function() | |||||||
|     assert_log("require%('vim%._editor'%)", testfile, 100) |     assert_log("require%('vim%._editor'%)", testfile, 100) | ||||||
|   end) |   end) | ||||||
|  |  | ||||||
|  |   it('--startuptime does not crash on error #31125', function() | ||||||
|  |     eq( | ||||||
|  |       "E484: Can't open file .", | ||||||
|  |       fn.system({ | ||||||
|  |         nvim_prog, | ||||||
|  |         '-u', | ||||||
|  |         'NONE', | ||||||
|  |         '-i', | ||||||
|  |         'NONE', | ||||||
|  |         '--headless', | ||||||
|  |         '--startuptime', | ||||||
|  |         '.', | ||||||
|  |         '-c', | ||||||
|  |         '42cquit', | ||||||
|  |       }) | ||||||
|  |     ) | ||||||
|  |     eq(42, api.nvim_get_vvar('shell_error')) | ||||||
|  |   end) | ||||||
|  |  | ||||||
|   it('-D does not hang #12647', function() |   it('-D does not hang #12647', function() | ||||||
|     clear() |     clear() | ||||||
|     local screen |     local screen | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user