]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Remove dependency on user32 1622/head
authorDustin Howett <duhowett@microsoft.com>
Wed, 13 Oct 2021 21:36:05 +0000 (14:36 -0700)
committerDustin L. Howett <dustin@howett.net>
Sat, 20 Nov 2021 21:01:06 +0000 (15:01 -0600)
libarchive/filter_fork_windows.c

index 8d11179f307ecc03f59dc7ac09d3247862cc028e..0b963975b90dff3838a9f3d1f39c27f0f6833365 100644 (file)
 
 #include "filter_fork.h"
 
+/* There are some editions of Windows ("nano server," for example) that
+ * do not host user32.dll. If we want to keep running on those editions,
+ * we need to delay-load WaitForInputIdle. */
+static void *
+la_GetFunctionUser32(const char *name)
+{
+       static HINSTANCE lib;
+       static int set;
+       if (!set) {
+               set = 1;
+               lib = LoadLibrary(TEXT("user32.dll"));
+       }
+       if (lib == NULL) {
+               return NULL;
+       }
+       return (void *)GetProcAddress(lib, name);
+}
+
+static int
+la_WaitForInputIdle(HANDLE hProcess, DWORD dwMilliseconds)
+{
+       static DWORD (WINAPI *f)(HANDLE, DWORD);
+       static int set;
+
+       if (!set) {
+               set = 1;
+               f = la_GetFunctionUser32("WaitForInputIdle");
+       }
+
+       if (!f) {
+               /* An inability to wait for input idle is
+                * not _good_, but it is not catastrophic. */
+               return WAIT_FAILED;
+       }
+       return (*f)(hProcess, dwMilliseconds);
+}
+
 int
 __archive_create_child(const char *cmd, int *child_stdin, int *child_stdout,
                HANDLE *out_child)
@@ -149,7 +186,7 @@ __archive_create_child(const char *cmd, int *child_stdin, int *child_stdout,
        if (CreateProcessA(fullpath.s, cmdline.s, NULL, NULL, TRUE, 0,
              NULL, NULL, &staInfo, &childInfo) == 0)
                goto fail;
-       WaitForInputIdle(childInfo.hProcess, INFINITE);
+       la_WaitForInputIdle(childInfo.hProcess, INFINITE);
        CloseHandle(childInfo.hProcess);
        CloseHandle(childInfo.hThread);