]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Issue 208: test_write_compress_program hangs.
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Tue, 27 Dec 2011 17:10:55 +0000 (12:10 -0500)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Tue, 27 Dec 2011 17:10:55 +0000 (12:10 -0500)
Merge r4018 from trunk.

SVN-Revision: 4019

libarchive/archive_windows.c
libarchive/archive_windows.h
libarchive/filter_fork_windows.c

index f8e8e46667f972df0552ffb04f3db6927241a0c4..0bb2a80949074dd4abdd11ea8b1265a28c3c5db2 100644 (file)
@@ -234,27 +234,6 @@ la_CreateFile(const char *path, DWORD dwDesiredAccess, DWORD dwShareMode,
        return (handle);
 }
 
-/*
- * This fcntl is limited implementation.
- */
-int
-__la_fcntl(int fd, int cmd, int val)
-{
-       HANDLE handle;
-
-       handle = (HANDLE)_get_osfhandle(fd);
-       if (GetFileType(handle) == FILE_TYPE_PIPE) {
-               if (cmd == F_SETFL && val == 0) {
-                       DWORD mode = PIPE_WAIT;
-                       if (SetNamedPipeHandleState(
-                           handle, &mode, NULL, NULL) != 0)
-                               return (0);
-               }
-       }
-       errno = EINVAL;
-       return (-1);
-}
-
 /* This can exceed MAX_PATH limitation. */
 int
 __la_open(const char *path, int flags, ...)
index b26811e54fe7ffab8dd59114f942402dbefced2c..cfb3e97d2811983d6e5e00793b9baa3ab7b0f5fe 100644 (file)
@@ -90,7 +90,7 @@
 
 /* Alias the Windows _function to the POSIX equivalent. */
 #define        close           _close
-#define        fcntl           __la_fcntl
+#define        fcntl(fd, cmd, flg)     /* No operation. */             
 #ifndef fileno
 #define        fileno          _fileno
 #endif
 
 
 /* Replacement POSIX function */
-extern int      __la_fcntl(int fd, int cmd, int val);
 extern int      __la_fstat(int fd, struct stat *st);
 extern int      __la_lstat(const char *path, struct stat *st);
 extern int      __la_open(const char *path, int flags, ...);
index 38b7097ee996b1e5fa6675f17118f34a520e3dd6..272e56c6b4ba5bee3355776bc88386cd804e513f 100644 (file)
 pid_t
 __archive_create_child(const char *path, int *child_stdin, int *child_stdout)
 {
-       HANDLE childStdout[2], childStdin[2], childStdinWr, childStdoutRd;
+       HANDLE childStdout[2], childStdin[2],childStderr;
        SECURITY_ATTRIBUTES secAtts;
        STARTUPINFO staInfo;
        PROCESS_INFORMATION childInfo;
        char cmd[MAX_PATH];
-       DWORD mode;
 
        secAtts.nLength = sizeof(SECURITY_ATTRIBUTES);
        secAtts.bInheritHandle = TRUE;
        secAtts.lpSecurityDescriptor = NULL;
        if (CreatePipe(&childStdout[0], &childStdout[1], &secAtts, 0) == 0)
                goto fail;
-       if (DuplicateHandle(GetCurrentProcess(), childStdout[0],
-           GetCurrentProcess(), &childStdoutRd, 0, FALSE,
-           DUPLICATE_SAME_ACCESS) == 0) {
+       if (!SetHandleInformation(childStdout[0], HANDLE_FLAG_INHERIT, 0))
+       {
                CloseHandle(childStdout[0]);
                CloseHandle(childStdout[1]);
                goto fail;
        }
-       CloseHandle(childStdout[0]);
-
        if (CreatePipe(&childStdin[0], &childStdin[1], &secAtts, 0) == 0) {
-               CloseHandle(childStdoutRd);
+               CloseHandle(childStdout[0]);
                CloseHandle(childStdout[1]);
                goto fail;
        }
-
-       if (DuplicateHandle(GetCurrentProcess(), childStdin[1],
-           GetCurrentProcess(), &childStdinWr, 0, FALSE,
+       if (!SetHandleInformation(childStdin[1], HANDLE_FLAG_INHERIT, 0))
+       {
+               CloseHandle(childStdout[0]);
+               CloseHandle(childStdout[1]);
+               CloseHandle(childStdin[0]);
+               CloseHandle(childStdin[1]);
+               goto fail;
+       }
+       if (DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_ERROR_HANDLE),
+           GetCurrentProcess(), &childStderr, 0, TRUE,
            DUPLICATE_SAME_ACCESS) == 0) {
-               CloseHandle(childStdoutRd);
+               CloseHandle(childStdout[0]);
                CloseHandle(childStdout[1]);
                CloseHandle(childStdin[0]);
                CloseHandle(childStdin[1]);
                goto fail;
        }
-       CloseHandle(childStdin[1]);
 
        memset(&staInfo, 0, sizeof(staInfo));
        staInfo.cb = sizeof(staInfo);
+       staInfo.hStdError = childStderr;
        staInfo.hStdOutput = childStdout[1];
        staInfo.hStdInput = childStdin[0];
        staInfo.wShowWindow = SW_HIDE;
-       staInfo.dwFlags = STARTF_USEFILLATTRIBUTE | STARTF_USECOUNTCHARS |
-           STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
+       staInfo.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
        strncpy(cmd, path, sizeof(cmd)-1);
        cmd[sizeof(cmd)-1] = '\0';
        if (CreateProcessA(NULL, cmd, NULL, NULL, TRUE, 0, NULL, NULL,
            &staInfo, &childInfo) == 0) {
-               CloseHandle(childStdoutRd);
+               CloseHandle(childStdout[0]);
                CloseHandle(childStdout[1]);
                CloseHandle(childStdin[0]);
-               CloseHandle(childStdinWr);
+               CloseHandle(childStdin[1]);
+               CloseHandle(childStderr);
                goto fail;
        }
        WaitForInputIdle(childInfo.hProcess, INFINITE);
        CloseHandle(childInfo.hProcess);
        CloseHandle(childInfo.hThread);
 
-       mode = PIPE_NOWAIT;
-       SetNamedPipeHandleState(childStdoutRd, &mode, NULL, NULL);
-       *child_stdout = _open_osfhandle((intptr_t)childStdoutRd, _O_RDONLY);
-       *child_stdin = _open_osfhandle((intptr_t)childStdinWr, _O_WRONLY);
+       *child_stdout = _open_osfhandle((intptr_t)childStdout[0], _O_RDONLY);
+       *child_stdin = _open_osfhandle((intptr_t)childStdin[1], _O_WRONLY);
+       
+       CloseHandle(childStdout[1]);
+       CloseHandle(childStdin[0]);
 
        return (childInfo.dwProcessId);