[Wine-patches] [eter-1.0.12] Close file handle before running UNIX binary (eterbug #4125).

Alexander Morozov amorozov на etersoft.ru
Сб Июн 4 19:14:26 MSD 2011


----------- следующая часть -----------
From ae06b075769b4bbf206b1ab680174a4cfbe25b31 Mon Sep 17 00:00:00 2001
From: Alexander Morozov <amorozov на etersoft.ru>
Date: Sat, 4 Jun 2011 03:17:10 +0400
Subject: [eter-1.0.12] Close file handle before running UNIX binary (eterbug
 #4125).

---
 dlls/kernel32/process.c        |   18 +++-------------
 dlls/ntdll/loader.c            |    2 +-
 include/wine/server_protocol.h |   15 +++++++------
 server/fd.c                    |   43 +++++----------------------------------
 server/protocol.def            |    7 +++--
 server/request.h               |    8 +++---
 server/trace.c                 |   10 +++-----
 7 files changed, 31 insertions(+), 72 deletions(-)

diff --git a/dlls/kernel32/process.c b/dlls/kernel32/process.c
index 15bc054..cdb0695 100644
--- a/dlls/kernel32/process.c
+++ b/dlls/kernel32/process.c
@@ -1518,19 +1518,7 @@ static int fork_and_exec( const char *filename, const WCHAR *cmdline, const WCHA
 
         if (newdir) chdir(newdir);
 
-        if (argv && envp)
-        {
-            /* Close file descriptor for locks to prevent ETXTBSY error */
-            SERVER_START_REQ( close_lock_fd )
-            {
-                req->handle = 0;
-                wine_server_add_data( req, filename, strlen(filename) + 1 );
-                wine_server_call( req );
-            }
-            SERVER_END_REQ;
-
-            execve( filename, argv, envp );
-        }
+        if (argv && envp) execve( filename, argv, envp );
         err = errno;
         write( fd[1], &err, sizeof(err) );
         _exit(1);
@@ -2169,13 +2157,15 @@ BOOL WINAPI CreateProcessW( LPCWSTR app_name, LPWSTR cmd_line, LPSECURITY_ATTRIB
 
             if ((unix_name = wine_get_unix_file_name( name )))
             {
+                CloseHandle( hFile );
+                hFile = 0;
                 retv = (fork_and_exec( unix_name, tidy_cmdline, envW, unixdir, flags, startup_info ) != -1);
                 HeapFree( GetProcessHeap(), 0, unix_name );
             }
         }
         break;
     }
-    CloseHandle( hFile );
+    if (hFile) CloseHandle( hFile );
 
  done:
     if (tidy_cmdline != cmd_line) HeapFree( GetProcessHeap(), 0, tidy_cmdline );
diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c
index d8c3d10..e0551d6 100644
--- a/dlls/ntdll/loader.c
+++ b/dlls/ntdll/loader.c
@@ -1936,7 +1936,7 @@ static NTSTATUS load_dll( LPCWSTR load_path, LPCWSTR libname, DWORD flags, WINE_
 
     if (handle)
     {
-        SERVER_START_REQ( close_lock_fd )
+        SERVER_START_REQ( ignore_locks )
         {
             req->handle = wine_server_obj_handle( handle );
             wine_server_call( req );
diff --git a/include/wine/server_protocol.h b/include/wine/server_protocol.h
index b1a8c10..3f1eed2 100644
--- a/include/wine/server_protocol.h
+++ b/include/wine/server_protocol.h
@@ -4522,18 +4522,19 @@ struct get_device_reply
 };
 
 
-struct close_lock_fd_request
+
+struct ignore_locks_request
 {
     struct request_header __header;
     obj_handle_t handle;
-    /* VARARG(filename,string); */
 };
-struct close_lock_fd_reply
+struct ignore_locks_reply
 {
     struct reply_header __header;
 };
 
 
+
 struct kill_wineserver_request
 {
     struct request_header __header;
@@ -4785,7 +4786,7 @@ enum request
     REQ_set_window_layered_info,
     REQ_get_device_name,
     REQ_get_device,
-    REQ_close_lock_fd,
+    REQ_ignore_locks,
     REQ_kill_wineserver,
     REQ_NB_REQUESTS
 };
@@ -5032,7 +5033,7 @@ union generic_request
     struct set_window_layered_info_request set_window_layered_info_request;
     struct get_device_name_request get_device_name_request;
     struct get_device_request get_device_request;
-    struct close_lock_fd_request close_lock_fd_request;
+    struct ignore_locks_request ignore_locks_request;
     struct kill_wineserver_request kill_wineserver_request;
 };
 union generic_reply
@@ -5277,10 +5278,10 @@ union generic_reply
     struct set_window_layered_info_reply set_window_layered_info_reply;
     struct get_device_name_reply get_device_name_reply;
     struct get_device_reply get_device_reply;
-    struct close_lock_fd_reply close_lock_fd_reply;
+    struct ignore_locks_reply ignore_locks_reply;
     struct kill_wineserver_reply kill_wineserver_reply;
 };
 
-#define SERVER_PROTOCOL_VERSION 10387
+#define SERVER_PROTOCOL_VERSION 10388
 
 #endif /* __WINE_WINE_SERVER_PROTOCOL_H */
diff --git a/server/fd.c b/server/fd.c
index 12149e0..deb0b02 100644
--- a/server/fd.c
+++ b/server/fd.c
@@ -2321,45 +2321,14 @@ DECL_HANDLER(add_fd_completion)
     }
 }
 
-/* close file descriptor used for locks */
-DECL_HANDLER(close_lock_fd)
+/* ignore locks and share flags */
+DECL_HANDLER(ignore_locks)
 {
-    int unix_fd = -1;
-    struct stat st;
-    struct inode *inode;
-    struct fd *fd = NULL;
-    const char *name = get_req_data();
-
-    if (req->handle)
-    {
-        fd = get_handle_fd_obj( current->process, req->handle, 0 );
-        if (!fd) return;
-        inode = fd->inode;
-    }
-    else
-    {
-        if (name[get_req_data_size() - 1] != 0) return;
-        unix_fd = open( name, O_RDONLY );
-        if (unix_fd < 0) return;
-        fstat( unix_fd, &st );
-        inode = get_inode( st.st_dev, st.st_ino, unix_fd );
-    }
-
-    if (inode)
-    {
-        int lock_fd = inode_get_lock_fd( inode );
-        if (lock_fd != -1)
-        {
-            inode_set_lock_fd( inode, -1 );
-            close( lock_fd );
-        }
-        if (fd) fd->fs_locks = 0;
-    }
+    struct fd *fd = get_handle_fd_obj( current->process, req->handle, 0 );
 
-    if (fd) release_object( fd );
-    if (unix_fd != -1)
+    if (fd)
     {
-        close( unix_fd );
-        if (inode) release_object( inode );
+        fd->fs_locks = 0;
+        release_object( fd );
     }
 }
diff --git a/server/protocol.def b/server/protocol.def
index 08d1573..f353beb 100644
--- a/server/protocol.def
+++ b/server/protocol.def
@@ -3136,12 +3136,13 @@ enum message_type
     client_ptr_t user_ptr;        /* opaque ptr for client side */
 @END
 
-/* Close file descriptor used for locks */
- на REQ(close_lock_fd)
+
+/* Ignore locks and share flags */
+ на REQ(ignore_locks)
     obj_handle_t handle;          /* handle to the file */
-    VARARG(filename,string);      /* file name */
 @END
 
+
 /* Kill the wineserver process */
 @REQ(kill_wineserver)
     int signal;                   /* sending signal */
diff --git a/server/request.h b/server/request.h
index a6c8035..11994db 100644
--- a/server/request.h
+++ b/server/request.h
@@ -349,7 +349,7 @@ DECL_HANDLER(get_window_layered_info);
 DECL_HANDLER(set_window_layered_info);
 DECL_HANDLER(get_device_name);
 DECL_HANDLER(get_device);
-DECL_HANDLER(close_lock_fd);
+DECL_HANDLER(ignore_locks);
 DECL_HANDLER(kill_wineserver);
 
 #ifdef WANT_REQUEST_HANDLERS
@@ -595,7 +595,7 @@ static const req_handler req_handlers[REQ_NB_REQUESTS] =
     (req_handler)req_set_window_layered_info,
     (req_handler)req_get_device_name,
     (req_handler)req_get_device,
-    (req_handler)req_close_lock_fd,
+    (req_handler)req_ignore_locks,
     (req_handler)req_kill_wineserver,
 };
 
@@ -1900,8 +1900,8 @@ C_ASSERT( FIELD_OFFSET(struct get_device_request, rootdir) == 16 );
 C_ASSERT( FIELD_OFFSET(struct get_device_request, manager) == 20 );
 C_ASSERT( FIELD_OFFSET(struct get_device_reply, user_ptr) == 8 );
 C_ASSERT( sizeof(struct get_device_reply) == 16 );
-C_ASSERT( FIELD_OFFSET(struct close_lock_fd_request, handle) == 12 );
-C_ASSERT( sizeof(struct close_lock_fd_request) == 16 );
+C_ASSERT( FIELD_OFFSET(struct ignore_locks_request, handle) == 12 );
+C_ASSERT( sizeof(struct ignore_locks_request) == 16 );
 C_ASSERT( FIELD_OFFSET(struct kill_wineserver_request, signal) == 12 );
 C_ASSERT( sizeof(struct kill_wineserver_request) == 16 );
 
diff --git a/server/trace.c b/server/trace.c
index 1958cd0..f97f2e6 100644
--- a/server/trace.c
+++ b/server/trace.c
@@ -4040,11 +4040,9 @@ static void dump_get_device_reply( const struct get_device_reply *req )
     dump_uint64( &req->user_ptr );
 }
 
-static void dump_close_lock_fd_request( const struct close_lock_fd_request *req )
+static void dump_ignore_locks_request( const struct ignore_locks_request *req )
 {
-    fprintf( stderr, " handle=%04x,", req->handle );
-    fprintf( stderr, " filename=" );
-    dump_varargs_string( cur_size );
+    fprintf( stderr, " handle=%04x", req->handle );
 }
 
 static void dump_kill_wineserver_request( const struct kill_wineserver_request *req )
@@ -4291,7 +4289,7 @@ static const dump_func req_dumpers[REQ_NB_REQUESTS] = {
     (dump_func)dump_set_window_layered_info_request,
     (dump_func)dump_get_device_name_request,
     (dump_func)dump_get_device_request,
-    (dump_func)dump_close_lock_fd_request,
+    (dump_func)dump_ignore_locks_request,
     (dump_func)dump_kill_wineserver_request,
 };
 
@@ -4777,7 +4775,7 @@ static const char * const req_names[REQ_NB_REQUESTS] = {
     "set_window_layered_info",
     "get_device_name",
     "get_device",
-    "close_lock_fd",
+    "ignore_locks",
     "kill_wineserver",
 };
 
-- 
1.7.4.5



Подробная информация о списке рассылки Wine-patches