From patchwork Fri Sep 7 18:19:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain via GitGitGadget X-Patchwork-Id: 10592471 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4BDFF14E0 for ; Fri, 7 Sep 2018 18:19:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 412582B3C3 for ; Fri, 7 Sep 2018 18:19:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 34FA42B3EF; Fri, 7 Sep 2018 18:19:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 927D12B3C3 for ; Fri, 7 Sep 2018 18:19:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727606AbeIGXCB (ORCPT ); Fri, 7 Sep 2018 19:02:01 -0400 Received: from mail-pf1-f169.google.com ([209.85.210.169]:42038 "EHLO mail-pf1-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726695AbeIGXCA (ORCPT ); Fri, 7 Sep 2018 19:02:00 -0400 Received: by mail-pf1-f169.google.com with SMTP id l9-v6so7392364pff.9 for ; Fri, 07 Sep 2018 11:19:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:in-reply-to:references:from:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=pnwk0EoNTP+LwkEUQKM8wXdk0g0wfrt/l8GjPW1SAfw=; b=SKNhZO3TrE76v5b+RhkTujuXcfq/KjiFzOGO3gHtqrf8kCapbo3VL90pld2FrSqFLL HAgN/bGPKy3g4MqS0/GFFB7Vptca+sW6inPBFhTBwpGVA4PWKCrD+hgzyNJYLzMyzY4c VGBZNrwLNfr+93JjW9acTlhmwnzxnNejZyUcGrzGp1ht5/W8kdwsHf7LzNUi7mW8k5d+ XA0ail3taJauYqucVntkTvVUIIEftWMBJt4Z18g8Wg5DCa9QGnVZtXk3qr9q2g5RjJkO vQ5CYr9Els1ERCszNglGNYO6zzO7MIGC8zSS+MJNkVATiw4W2QHWikMOQIQjZdwkzV9O x/iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:in-reply-to:references:from :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=pnwk0EoNTP+LwkEUQKM8wXdk0g0wfrt/l8GjPW1SAfw=; b=tLgnhLLWUFeV+5U398gtSjApCVW6UqTw3nx0mWwPPkHU2rZSCnErkssJsOKMdmxtKd c9JTXER2/jE7appWtDhvYJkbqBNRGGuOCQh8NfMeg1lECzaYHF++t5ieI9Avw1XNiRqV BLqWiLr2Pm+qle5Y6gVm1hYYA3JYWJi37g62hivpVcwVjxLCiM4l0OYFhABKdUU9V/u2 ncZc/hkJQ0xfjGzZnvujRwyu9VAi47I0PioWnkHj18+VNOqs+Dh603sYov5MGBxg/PAs PyJeaNTJ2N0R+3ugQdLC9cheFNlbjHKEPJG2wj3ts9abm7tqrfmWfcss3jBCBg+4V6cd TLjw== X-Gm-Message-State: APzg51D+G3Padc7zHwxhSeQBWRuz2TcbRmeL9eUUOjllZ3WqwjlNT7hO DqIatM4EFCwxCnwXR82k2Ps5jvwZ X-Google-Smtp-Source: ANB0VdZUyAeUEjBUeShdlqefpRPYiStvPcrEiaHXSTQO6eLZbYRNetnIzrAfJb3aft7lok93Vb19Eg== X-Received: by 2002:a62:6eca:: with SMTP id j193-v6mr10000984pfc.256.1536344391771; Fri, 07 Sep 2018 11:19:51 -0700 (PDT) Received: from [127.0.0.1] ([40.112.142.204]) by smtp.gmail.com with ESMTPSA id f87-v6sm24734666pfh.168.2018.09.07.11.19.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 11:19:51 -0700 (PDT) Date: Fri, 07 Sep 2018 11:19:51 -0700 (PDT) X-Google-Original-Date: Fri, 07 Sep 2018 18:19:45 GMT Message-Id: <03453cb521ae57475d046024f5840991553410d6.1536344387.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Jeff Hostetler via GitGitGadget" Subject: [PATCH 1/2] t0051: test GIT_TRACE to a windows named pipe Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: jeffhost@microsoft.com, Junio C Hamano , Jeff Hostetler Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jeff Hostetler Create a test-tool helper to create the server side of a windows named pipe, wait for a client connection, and copy data written to the pipe to stdout. Create t0051 test to route GIT_TRACE output of a command to a named pipe using the above test-tool helper. Signed-off-by: Jeff Hostetler --- Makefile | 1 + t/helper/test-tool.c | 3 ++ t/helper/test-tool.h | 3 ++ t/helper/test-windows-named-pipe.c | 72 ++++++++++++++++++++++++++++++ t/t0051-windows-named-pipe.sh | 17 +++++++ 5 files changed, 96 insertions(+) create mode 100644 t/helper/test-windows-named-pipe.c create mode 100755 t/t0051-windows-named-pipe.sh diff --git a/Makefile b/Makefile index e4b503d259..b1b934d295 100644 --- a/Makefile +++ b/Makefile @@ -731,6 +731,7 @@ TEST_BUILTINS_OBJS += test-submodule-config.o TEST_BUILTINS_OBJS += test-subprocess.o TEST_BUILTINS_OBJS += test-urlmatch-normalization.o TEST_BUILTINS_OBJS += test-wildmatch.o +TEST_BUILTINS_OBJS += test-windows-named-pipe.o TEST_BUILTINS_OBJS += test-write-cache.o TEST_PROGRAMS_NEED_X += test-dump-fsmonitor diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c index 805a45de9c..7a9764cd5c 100644 --- a/t/helper/test-tool.c +++ b/t/helper/test-tool.c @@ -41,6 +41,9 @@ static struct test_cmd cmds[] = { { "subprocess", cmd__subprocess }, { "urlmatch-normalization", cmd__urlmatch_normalization }, { "wildmatch", cmd__wildmatch }, +#ifdef GIT_WINDOWS_NATIVE + { "windows-named-pipe", cmd__windows_named_pipe }, +#endif { "write-cache", cmd__write_cache }, }; diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h index 7116ddfb94..01c34fe5e7 100644 --- a/t/helper/test-tool.h +++ b/t/helper/test-tool.h @@ -35,6 +35,9 @@ int cmd__submodule_config(int argc, const char **argv); int cmd__subprocess(int argc, const char **argv); int cmd__urlmatch_normalization(int argc, const char **argv); int cmd__wildmatch(int argc, const char **argv); +#ifdef GIT_WINDOWS_NATIVE +int cmd__windows_named_pipe(int argc, const char **argv); +#endif int cmd__write_cache(int argc, const char **argv); #endif diff --git a/t/helper/test-windows-named-pipe.c b/t/helper/test-windows-named-pipe.c new file mode 100644 index 0000000000..b4b752b01a --- /dev/null +++ b/t/helper/test-windows-named-pipe.c @@ -0,0 +1,72 @@ +#include "test-tool.h" +#include "git-compat-util.h" +#include "strbuf.h" + +#ifdef GIT_WINDOWS_NATIVE +static const char *usage_string = ""; + +#define TEST_BUFSIZE (4096) + +int cmd__windows_named_pipe(int argc, const char **argv) +{ + const char *filename; + struct strbuf pathname = STRBUF_INIT; + int err; + HANDLE h; + BOOL connected; + char buf[TEST_BUFSIZE + 1]; + + if (argc < 2) + goto print_usage; + filename = argv[1]; + if (strchr(filename, '/') || strchr(filename, '\\')) + goto print_usage; + strbuf_addf(&pathname, "//./pipe/%s", filename); + + /* + * Create a single instance of the server side of the named pipe. + * This will allow exactly one client instance to connect to it. + */ + h = CreateNamedPipeA( + pathname.buf, + PIPE_ACCESS_INBOUND | FILE_FLAG_FIRST_PIPE_INSTANCE, + PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, + PIPE_UNLIMITED_INSTANCES, + TEST_BUFSIZE, TEST_BUFSIZE, 0, NULL); + if (h == INVALID_HANDLE_VALUE) { + err = err_win_to_posix(GetLastError()); + fprintf(stderr, "CreateNamedPipe failed: %s\n", + strerror(err)); + return err; + } + + connected = ConnectNamedPipe(h, NULL) + ? TRUE + : (GetLastError() == ERROR_PIPE_CONNECTED); + if (!connected) { + err = err_win_to_posix(GetLastError()); + fprintf(stderr, "ConnectNamedPipe failed: %s\n", + strerror(err)); + CloseHandle(h); + return err; + } + + while (1) { + DWORD nbr; + BOOL success = ReadFile(h, buf, TEST_BUFSIZE, &nbr, NULL); + if (!success || nbr == 0) + break; + buf[nbr] = 0; + + write(1, buf, nbr); + } + + DisconnectNamedPipe(h); + CloseHandle(h); + return 0; + +print_usage: + fprintf(stderr, "usage: %s %s\n", argv[0], usage_string); + return 1; +} +#endif diff --git a/t/t0051-windows-named-pipe.sh b/t/t0051-windows-named-pipe.sh new file mode 100755 index 0000000000..10ac92d225 --- /dev/null +++ b/t/t0051-windows-named-pipe.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +test_description='Windows named pipes' + +. ./test-lib.sh + +test_expect_success MINGW 'o_append write to named pipe' ' + GIT_TRACE="$(pwd)/expect" git status >/dev/null 2>&1 && + { test-tool windows-named-pipe t0051 >actual 2>&1 & } && + pid=$! && + sleep 1 && + GIT_TRACE=//./pipe/t0051 git status >/dev/null 2>warning && + wait $pid && + test_cmp expect actual +' + +test_done From patchwork Fri Sep 7 18:19:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain via GitGitGadget X-Patchwork-Id: 10592473 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3A89C14E0 for ; Fri, 7 Sep 2018 18:19:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 311A42B3C3 for ; Fri, 7 Sep 2018 18:19:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 25B2F2B3CD; Fri, 7 Sep 2018 18:19:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1A9552B3C7 for ; Fri, 7 Sep 2018 18:19:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727618AbeIGXCC (ORCPT ); Fri, 7 Sep 2018 19:02:02 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:40455 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726695AbeIGXCB (ORCPT ); Fri, 7 Sep 2018 19:02:01 -0400 Received: by mail-pg1-f196.google.com with SMTP id l63-v6so7372476pga.7 for ; Fri, 07 Sep 2018 11:19:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:in-reply-to:references:from:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=B49F1kB6gosK0V9gAMjrhZj8eNL+L4idpNHd4+AVFDM=; b=cJDa/lhlPlAlP7VDR/WAxuQhwOgB/FCyJ8OhhcwFqEBTQyIgGbERzY/H2mdDBL2Jsf X42+FZ/ulJNCao0NuyR8GeOPseOCpZCzCy+baQajeKuc3jLpUhDjkYqmhos9ns9Clwm5 RMICDrTJiE4r9+EBIC1VEiQ129S2gwCCQadlBudTmfelqiS8pFUQ/klZyWOX1vyGKdFA dko05/MNXwhYlbUt1mLdwkwV6QcsvnRXAomY9HlKn9OF/2X6yziydPVfPb5MmHjbkKLp yYQO8uhO6Rd7bvwYi5vyN5QXBfF8qUucrUAFhdxsFBcLCExFWQeKe60uu9g77nfOU/iN BWeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:in-reply-to:references:from :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=B49F1kB6gosK0V9gAMjrhZj8eNL+L4idpNHd4+AVFDM=; b=egCtTItIYq9FQrhCLkIrhViiOP8VsZ0rjXZeiFYgEGADzzB/OOsTr3cqhLnOEUy0B6 ESmnpOu2If4kAcZo0PaZPtXUeVxMPbD9oQjVeoKyc+ccFAapdZgl1s9w9s8hL5sxAmuf yldt/4yjTfjehAvihS8ADB/TKncRsxqMLnngQo+Z0xurVch9G7MmIdpsaUQb5VIrlVi1 evqu1OnnmLaCyCrkN2g/so7C10KzabvvNt2mIMeGy+uOIClYeQV9h1fHRZmAqvDzgGVQ ifAcX0Z0OK4YQHZcX4A22o1Ad1LTW1zy4V6KBeiOov3HIfFYsTlujAVqOqwrTZNqq0YN K9Vw== X-Gm-Message-State: APzg51DTRCT9kqmn8bsT6OPNS0MB0Q8NIfTqhfWjgCOsyGAaxmdvn2Or 11B8nKZq3G1SVVI685JlCzn06MtD X-Google-Smtp-Source: ANB0VdaOShYW7wbFNrEDfUXrdNnRLPDZ1nuMQ3AyfNovfhXLEH/sS2sGrtntKMvhfOZYOspCp3qWRA== X-Received: by 2002:a63:cd4c:: with SMTP id a12-v6mr9617589pgj.15.1536344393146; Fri, 07 Sep 2018 11:19:53 -0700 (PDT) Received: from [127.0.0.1] ([40.112.142.204]) by smtp.gmail.com with ESMTPSA id u25-v6sm11950342pfk.177.2018.09.07.11.19.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 11:19:52 -0700 (PDT) Date: Fri, 07 Sep 2018 11:19:52 -0700 (PDT) X-Google-Original-Date: Fri, 07 Sep 2018 18:19:46 GMT Message-Id: In-Reply-To: References: From: "Jeff Hostetler via GitGitGadget" Subject: [PATCH 2/2] mingw: fix mingw_open_append to work with named pipes Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: jeffhost@microsoft.com, Junio C Hamano , Jeff Hostetler Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jeff Hostetler Signed-off-by: Jeff Hostetler --- compat/mingw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compat/mingw.c b/compat/mingw.c index 858ca14a57..ef03bbe5d2 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -355,7 +355,7 @@ static int mingw_open_append(wchar_t const *wfilename, int oflags, ...) * FILE_SHARE_WRITE is required to permit child processes * to append to the file. */ - handle = CreateFileW(wfilename, FILE_APPEND_DATA, + handle = CreateFileW(wfilename, FILE_WRITE_DATA | FILE_APPEND_DATA, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, create, FILE_ATTRIBUTE_NORMAL, NULL); if (handle == INVALID_HANDLE_VALUE)