From 3a40ae6b1e3cd67ea606a7af6938788fe470773e Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Fri, 16 Oct 2015 05:54:08 +0200
Subject: ntdll: Run directory initialization function early during the process
 startup.

---
 dlls/ntdll/directory.c  | 10 ++--------
 dlls/ntdll/loader.c     |  1 +
 dlls/ntdll/ntdll_misc.h |  1 +
 3 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/dlls/ntdll/directory.c b/dlls/ntdll/directory.c
index 770cd3f..94b6d77 100644
--- a/dlls/ntdll/directory.c
+++ b/dlls/ntdll/directory.c
@@ -176,7 +176,6 @@ union file_directory_info
 };
 
 static BOOL show_dot_files;
-static RTL_RUN_ONCE init_once = RTL_RUN_ONCE_INIT;
 
 /* at some point we may want to allow Winelib apps to set this */
 static const BOOL is_case_sensitive = FALSE;
@@ -1164,11 +1163,11 @@ static BOOLEAN get_dir_case_sensitivity( const char *dir )
 
 
 /***********************************************************************
- *           init_options
+ *           DIR_init_options
  *
  * Initialize the show_dot_files options.
  */
-static DWORD WINAPI init_options( RTL_RUN_ONCE *once, void *param, void **context )
+void DIR_init_options(void)
 {
     static const WCHAR WineW[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e',0};
     static const WCHAR ShowDotFilesW[] = {'S','h','o','w','D','o','t','F','i','l','e','s',0};
@@ -1207,7 +1206,6 @@ static DWORD WINAPI init_options( RTL_RUN_ONCE *once, void *param, void **contex
 #ifdef linux
     ignore_file( "/sys" );
 #endif
-    return TRUE;
 }
 
 
@@ -1220,8 +1218,6 @@ BOOL DIR_is_hidden_file( const UNICODE_STRING *name )
 {
     WCHAR *p, *end;
 
-    RtlRunOnceExecuteOnce( &init_once, init_options, NULL, NULL );
-
     if (show_dot_files) return FALSE;
 
     end = p = name->Buffer + name->Length/sizeof(WCHAR);
@@ -2278,8 +2274,6 @@ NTSTATUS WINAPI SYSCALL(NtQueryDirectoryFile)( HANDLE handle, HANDLE event,
 
     io->Information = 0;
 
-    RtlRunOnceExecuteOnce( &init_once, init_options, NULL, NULL );
-
     RtlEnterCriticalSection( &dir_section );
 
     cwd = open( ".", O_RDONLY );
diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c
index ecbc885..04cbb63 100644
--- a/dlls/ntdll/loader.c
+++ b/dlls/ntdll/loader.c
@@ -3283,6 +3283,7 @@ void __wine_process_init(void)
     umask( FILE_umask );
 
     load_global_options();
+    DIR_init_options();
 
     /* setup the load callback and create ntdll modref */
     wine_dll_set_callback( load_builtin_callback );
diff --git a/dlls/ntdll/ntdll_misc.h b/dlls/ntdll/ntdll_misc.h
index 11099c5..5ba1308 100644
--- a/dlls/ntdll/ntdll_misc.h
+++ b/dlls/ntdll/ntdll_misc.h
@@ -153,6 +153,7 @@ extern int get_file_info( const char *path, struct stat *st, ULONG *attr ) DECLS
 extern NTSTATUS fill_file_info( const struct stat *st, ULONG attr, void *ptr,
                                 FILE_INFORMATION_CLASS class ) DECLSPEC_HIDDEN;
 extern NTSTATUS server_get_unix_name( HANDLE handle, ANSI_STRING *unix_name ) DECLSPEC_HIDDEN;
+extern void DIR_init_options(void) DECLSPEC_HIDDEN;
 extern void DIR_init_windows_dir( const WCHAR *windir, const WCHAR *sysdir ) DECLSPEC_HIDDEN;
 extern BOOL DIR_is_hidden_file( const UNICODE_STRING *name ) DECLSPEC_HIDDEN;
 extern NTSTATUS DIR_unmount_device( HANDLE handle ) DECLSPEC_HIDDEN;
-- 
2.6.1

