From patchwork Wed Aug 31 16:09:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric DeCosta X-Patchwork-Id: 12961022 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 20CC9ECAAD4 for ; Wed, 31 Aug 2022 16:09:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231450AbiHaQJP (ORCPT ); Wed, 31 Aug 2022 12:09:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231351AbiHaQJM (ORCPT ); Wed, 31 Aug 2022 12:09:12 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 945DF43E6A for ; Wed, 31 Aug 2022 09:09:10 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id h204-20020a1c21d5000000b003a5b467c3abso11960286wmh.5 for ; Wed, 31 Aug 2022 09:09:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc; bh=UH6BST2xsgOSZkwrhMmvFJO7kolfu7XJE/lE1W/C990=; b=NkluoF2pA89kig8wZVm2Rv579t3ZE/7X8j2IC63XYZmqbTp2YVTOn5HJWMLCT2A2l8 /lh+CqIn0z8hEAHDg/AywwZDUXZZKZXyIeLJoQKo31x3kqJQ7NBO0RD9CSpAGiysIR/J NnJsVL0/kM/DzdIl9wpU72QxNDjin1VxOe0qPh0yR8ZKkQuHZPyrl85qen11HXPDrF36 5hGfEOkmnF7JZTSe+PfmY15gG2PXEvfBmgomZ37rfFaARn48EJZnu3/rYq5VBNrAoxDI rECUxDYjPy96XmDriNjuI8dj1A3hvi9vw7Oe/CikyaGADkcz9PDLXYtqCjXu5eYH6SU8 jhQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc; bh=UH6BST2xsgOSZkwrhMmvFJO7kolfu7XJE/lE1W/C990=; b=ZbnvgDbU/tuttvLCEFz7lCkdPjcNfM+SLYGHgy3VtwXj76vNxkM7GBEYGlpOJ2mq3L 0gO0SfV6ZTde92qi62R0EVNnZzqdAmiER6hSiRJSJm5RgYy5HCkvBkRmeuY+lgE1lK6E KP+PADewCh42FtMbmk5FgirXe/FBhRmwfQ3My+K4kLF/IaEUjwl0V7jzbl9cr6gfktbO UFiMHQBtLRZufneIRaUY+VTQ7eroypVvXeV3UOFy8DYvZdH6+19LL0iFZL+WYdViTQkU a/8l+3csRwTz+VIGBeV1/QJXxvHgrv4dE3dXMrTrtQOM0dTWhrcwYpHvICAgwEBTyv9Q GKBw== X-Gm-Message-State: ACgBeo36qNJUxCNlL2hqpT4YRJXbZ0xCIsIz5ttWBnFtNsAkh4bcvcYg 5XMfi715uOLidVdmiyJtXKxiCLHhOZk= X-Google-Smtp-Source: AA6agR6X3XwNuo44x441CkWFOXxcZ0rzmJMOgPCW5xAnt9pY7olB5xa9twUlVqnVlfcNIJ2HFKnJsQ== X-Received: by 2002:a05:600c:1ca0:b0:3a8:41cf:a31f with SMTP id k32-20020a05600c1ca000b003a841cfa31fmr2527898wms.161.1661962148879; Wed, 31 Aug 2022 09:09:08 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id i6-20020a1c3b06000000b003a4efb794d7sm2827667wma.36.2022.08.31.09.09.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 09:09:07 -0700 (PDT) Message-Id: <836a791e6b7fd4490674254ce03105a8ca2175cb.1661962145.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 31 Aug 2022 16:09:01 +0000 Subject: [PATCH v4 1/4] fsmonitor: add two new config options, allowRemote and socketDir Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Eric DeCosta , Eric DeCosta Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Eric DeCosta From: Eric DeCosta Introduce two new configuration options fsmonitor.allowRemote - setting this to true overrides fsmonitor's default behavior of erroring out when enountering network file systems. Additionly, when true, the Unix domain socket (UDS) file used for IPC is located in $HOME rather than in the .git directory. fsmonitor.socketDir - allows for the UDS file to be located anywhere the user chooses rather $HOME. Signed-off-by: Eric DeCosta --- fsmonitor-settings.c | 67 ++++++++++++++++++++++++++++++++++++++++++-- fsmonitor-settings.h | 4 +++ 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/fsmonitor-settings.c b/fsmonitor-settings.c index 464424a1e92..a15eeecebf4 100644 --- a/fsmonitor-settings.c +++ b/fsmonitor-settings.c @@ -10,7 +10,9 @@ struct fsmonitor_settings { enum fsmonitor_mode mode; enum fsmonitor_reason reason; + int allow_remote; char *hook_path; + char *sock_dir; }; static enum fsmonitor_reason check_for_incompatible(struct repository *r) @@ -43,6 +45,7 @@ static struct fsmonitor_settings *alloc_settings(void) CALLOC_ARRAY(s, 1); s->mode = FSMONITOR_MODE_DISABLED; s->reason = FSMONITOR_REASON_UNTESTED; + s->allow_remote = -1; return s; } @@ -90,6 +93,26 @@ static void lookup_fsmonitor_settings(struct repository *r) fsm_settings__set_disabled(r); } +int fsm_settings__get_allow_remote(struct repository *r) +{ + if (!r) + r = the_repository; + if (!r->settings.fsmonitor) + lookup_fsmonitor_settings(r); + + return r->settings.fsmonitor->allow_remote; +} + +const char *fsm_settings__get_socket_dir(struct repository *r) +{ + if (!r) + r = the_repository; + if (!r->settings.fsmonitor) + lookup_fsmonitor_settings(r); + + return r->settings.fsmonitor->sock_dir; +} + enum fsmonitor_mode fsm_settings__get_mode(struct repository *r) { if (!r) @@ -100,6 +123,7 @@ enum fsmonitor_mode fsm_settings__get_mode(struct repository *r) return r->settings.fsmonitor->mode; } + const char *fsm_settings__get_hook_path(struct repository *r) { if (!r) @@ -110,9 +134,44 @@ const char *fsm_settings__get_hook_path(struct repository *r) return r->settings.fsmonitor->hook_path; } +void fsm_settings__set_allow_remote(struct repository *r) +{ + int allow; + + if (!r) + r = the_repository; + if (!r->settings.fsmonitor) + r->settings.fsmonitor = alloc_settings(); + if (!repo_config_get_bool(r, "fsmonitor.allowremote", &allow)) + r->settings.fsmonitor->allow_remote = allow; + + return; +} + +void fsm_settings__set_socket_dir(struct repository *r) +{ + const char *path; + + if (!r) + r = the_repository; + if (!r->settings.fsmonitor) + r->settings.fsmonitor = alloc_settings(); + + if (!repo_config_get_pathname(r, "fsmonitor.socketdir", &path)) { + FREE_AND_NULL(r->settings.fsmonitor->sock_dir); + r->settings.fsmonitor->sock_dir = strdup(path); + } + + return; +} + void fsm_settings__set_ipc(struct repository *r) { - enum fsmonitor_reason reason = check_for_incompatible(r); + enum fsmonitor_reason reason; + + fsm_settings__set_allow_remote(r); + fsm_settings__set_socket_dir(r); + reason = check_for_incompatible(r); if (reason != FSMONITOR_REASON_OK) { fsm_settings__set_incompatible(r, reason); @@ -135,7 +194,11 @@ void fsm_settings__set_ipc(struct repository *r) void fsm_settings__set_hook(struct repository *r, const char *path) { - enum fsmonitor_reason reason = check_for_incompatible(r); + enum fsmonitor_reason reason; + + fsm_settings__set_allow_remote(r); + fsm_settings__set_socket_dir(r); + reason = check_for_incompatible(r); if (reason != FSMONITOR_REASON_OK) { fsm_settings__set_incompatible(r, reason); diff --git a/fsmonitor-settings.h b/fsmonitor-settings.h index d9c2605197f..2de54c85e94 100644 --- a/fsmonitor-settings.h +++ b/fsmonitor-settings.h @@ -23,12 +23,16 @@ enum fsmonitor_reason { FSMONITOR_REASON_NOSOCKETS, /* NTFS,FAT32 do not support Unix sockets */ }; +void fsm_settings__set_allow_remote(struct repository *r); +void fsm_settings__set_socket_dir(struct repository *r); void fsm_settings__set_ipc(struct repository *r); void fsm_settings__set_hook(struct repository *r, const char *path); void fsm_settings__set_disabled(struct repository *r); void fsm_settings__set_incompatible(struct repository *r, enum fsmonitor_reason reason); +int fsm_settings__get_allow_remote(struct repository *r); +const char *fsm_settings__get_socket_dir(struct repository *r); enum fsmonitor_mode fsm_settings__get_mode(struct repository *r); const char *fsm_settings__get_hook_path(struct repository *r); From patchwork Wed Aug 31 16:09:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric DeCosta X-Patchwork-Id: 12961023 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1CD21ECAAD3 for ; Wed, 31 Aug 2022 16:09:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231663AbiHaQJ1 (ORCPT ); Wed, 31 Aug 2022 12:09:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231403AbiHaQJO (ORCPT ); Wed, 31 Aug 2022 12:09:14 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6ED14AFAC7 for ; Wed, 31 Aug 2022 09:09:12 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id m16so18883022wru.9 for ; Wed, 31 Aug 2022 09:09:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc; bh=LpOHQYd/OqaxsJSFz0fEed2hnZFuxw4EuQJ1lFaj3ag=; b=d8lgbWuBA8M2AbIGhPaKbDhij4VyDk6xsDL7N72m/37Fl2R4tps7J/k1ztWcQyrR3V 8mCTVBplyYOP4w4ghsBKm1hBm+gD71fo81dzZij867iAfrOwMTBjV1UbCgxAiOO1e3Oz NLGjUAXNwRoXhrZoFpix5YSjF7UkH4PTVWp+1Vd9Z5blZ6zEPRRuZsrsxBcT/VKM4V+0 i8SAEuhvvBAjD4/bIC6iH1qNBgjUuJpp38oM+gK/hd+9Zw7iPqrk4OmkO6SIfHxxc/tS LTBSIKwpe07Pek+vzP+IV40DWNnmFy4AAPcpH+Ac7uLDMQYGMBvlMLQu5NkOtFWq3MJ+ dmHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc; bh=LpOHQYd/OqaxsJSFz0fEed2hnZFuxw4EuQJ1lFaj3ag=; b=CMQaZ2OBisE58DychwCbKcd6UBn+FoTRrybZGZtpl76zV2SYBXvDzNunkKeKEIJ+0w f9HRFPUA9K2mv5j4WcmubzMW4ZbRXuzJ1HUzWKoNnRbGxMalrebojGn/RI0pUIJc9kIo KV36tRetsHvPffWtghwDpMiq5Xppq5cFKUfnUXtch3T9mYW9ec3KYZ0iXYOrkBbsmbYD DD9aUppKhpqSkxykhhy6Rjblo0aa7EFmC23bjSohXCiBS3rrP0gpS6aMtkuurZFBqgwC NFzQuc0OafafzYku3vq53/XSMPA7XmcrY1lrziCJRqS5xh3W+07oco8fbqotXjPHZQPz nypA== X-Gm-Message-State: ACgBeo3QAT332ObNeLgtKnboo376gYuHphBV79/doXnDNJ/1g3s721Wi 3awq9NBE23y49Ut31EsPjXeSCbWBjic= X-Google-Smtp-Source: AA6agR7fofupf6IWxYiKBBgjo0ngxX74BunpDqp87CuY6H6Dad3xGia/uBFFqJEE2RhpdS80X9TcAg== X-Received: by 2002:a5d:46d0:0:b0:226:d133:3a4a with SMTP id g16-20020a5d46d0000000b00226d1333a4amr11714330wrs.400.1661962150758; Wed, 31 Aug 2022 09:09:10 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id w5-20020a5d6805000000b0021e8d205705sm12077965wru.51.2022.08.31.09.09.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 09:09:09 -0700 (PDT) Message-Id: <2cb026a631704b004b06e4a944c79a434df08440.1661962145.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 31 Aug 2022 16:09:02 +0000 Subject: [PATCH v4 2/4] fsmonitor: generate unique Unix socket file name in the desired location Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Eric DeCosta , Eric DeCosta Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Eric DeCosta From: Eric DeCosta Based on the values of fsmonitor.allowRemote and fsmonitor.socketDir locate the Unix domain socket file in the desired location (either the .git directory, $HOME, or fsmonitor.socketDir). If the location is other than the .git directory, generate a unique file name based on the SHA1 has of the path to the .git directory. Signed-off-by: Eric DeCosta --- fsmonitor-ipc.c | 40 +++++++++++++++++++++++++++++++++++++--- fsmonitor-ipc.h | 6 ++++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/fsmonitor-ipc.c b/fsmonitor-ipc.c index 789e7397baa..1e3f0a6cf48 100644 --- a/fsmonitor-ipc.c +++ b/fsmonitor-ipc.c @@ -1,7 +1,6 @@ #include "cache.h" -#include "fsmonitor.h" -#include "simple-ipc.h" #include "fsmonitor-ipc.h" +#include "fsmonitor-settings.h" #include "run-command.h" #include "strbuf.h" #include "trace2.h" @@ -47,7 +46,42 @@ int fsmonitor_ipc__is_supported(void) return 1; } -GIT_PATH_FUNC(fsmonitor_ipc__get_path, "fsmonitor--daemon.ipc") +GIT_PATH_FUNC(fsmonitor_ipc__get_default_path, "fsmonitor--daemon.ipc") + +const char *fsmonitor_ipc__get_path(void) +{ +#ifdef WIN32 + return fsmonitor_ipc__get_default_path(); +#else + char *retval; + SHA_CTX sha1ctx; + const char *git_dir; + const char *sock_dir; + struct strbuf ipc_file = STRBUF_INIT; + unsigned char hash[SHA_DIGEST_LENGTH]; + + if (fsm_settings__get_allow_remote(the_repository) < 1) + return fsmonitor_ipc__get_default_path(); + + git_dir = get_git_dir(); + sock_dir = fsm_settings__get_socket_dir(the_repository); + + SHA1_Init(&sha1ctx); + SHA1_Update(&sha1ctx, git_dir, strlen(git_dir)); + SHA1_Final(hash, &sha1ctx); + + if (sock_dir && *sock_dir) + strbuf_addf(&ipc_file, "%s/.git-fsmonitor-%s", + sock_dir, hash_to_hex(hash)); + else + strbuf_addf(&ipc_file, "~/.git-fsmonitor-%s", hash_to_hex(hash)); + retval = interpolate_path(ipc_file.buf, 1); + if (!retval) + die(_("Invalid path: %s"), ipc_file.buf); + strbuf_release(&ipc_file); + return retval; +#endif +} enum ipc_active_state fsmonitor_ipc__get_state(void) { diff --git a/fsmonitor-ipc.h b/fsmonitor-ipc.h index b6a7067c3af..4d27223c2a6 100644 --- a/fsmonitor-ipc.h +++ b/fsmonitor-ipc.h @@ -18,6 +18,12 @@ int fsmonitor_ipc__is_supported(void); */ const char *fsmonitor_ipc__get_path(void); +/* + * Returns the pathname to the default IPC named pipe or Unix domain + * socket. + */ +const char *fsmonitor_ipc__get_default_path(void); + /* * Try to determine whether there is a `git-fsmonitor--daemon` process * listening on the IPC pipe/socket. From patchwork Wed Aug 31 16:09:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric DeCosta X-Patchwork-Id: 12961024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92752ECAAD1 for ; Wed, 31 Aug 2022 16:09:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231724AbiHaQJa (ORCPT ); Wed, 31 Aug 2022 12:09:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231438AbiHaQJO (ORCPT ); Wed, 31 Aug 2022 12:09:14 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9F7DB0880 for ; Wed, 31 Aug 2022 09:09:13 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id e20so18880231wri.13 for ; Wed, 31 Aug 2022 09:09:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc; bh=3xkCrUGmHxE0Vlh7KaT9kiu2RtYJf6DDPSmtM4ZuucI=; b=c59XG0/H/r60WoWBvmnTwse3yFrJAgZGHVWv2JLMME2hzFlw03aSRuxrEL4J8Nkw9B sHPVgDp+v1mDDwmsAmziH6snt/LthXfc8L9ozNtJKqZCgZsXfgxIp8wToUhz7ESrWHga uFXZLQNhvNttU4mLlDvBwzSzW2i/2JkYXf7pAc5O3FEjMwLp3rKm+OirbeodUX545f04 tBsmoH5MVJTgxtgxrKTmcBlwVIVVGrcvXvvACvjTyviRvG84LRGvHG8HTrlef/4jl8dD 1pNZLubwVt60/5/t/AnAJ7BT0dBYTxShSPChxFgYTmwJryfEUN/+SVR0g9JBHeVvhdW2 NUXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc; bh=3xkCrUGmHxE0Vlh7KaT9kiu2RtYJf6DDPSmtM4ZuucI=; b=zt8O3bL1iePWZJNs4M3zpr1OLPvQEyI7nw42tjsJ85vaLXX2ZXWPY/9CB0IfqlMUqs lRf8KEuMypltZ/zVFdFn3ENdXIgd1KcgadkZLsZjDpNSE583bUyjJZGoPvyTHxZkNngc 3eE+pTcQACMHUt6d2jRV+G8O1MFCZROs+NPevJuc89STtA2WsVjwbwkho9KH3PjiODuW PpFs9kGmOxPaGtkwm5uBPeXwOomP9ukrDHDUbj4vDrVGDcwdr9yrEhrIu2e/DY/F1I8h O/Vtxf4MWiqemrMXH2xlZFhsNonQ2ojQo6JUBozk1GQ2QaMYtRIq6EmTjM9mMzF9PuGt 48TQ== X-Gm-Message-State: ACgBeo0OReMR98RwfKFjc+Mphzlg1lzHQ/vAbUcpMTzN2cRNdMYVvQpN wtk7Pk5AefmWQGWdm8e22VlNY2I3qzI= X-Google-Smtp-Source: AA6agR45eGgAhlILdfrSEZ6Z6Szx3QmXEK6OnvyCr4a7sSfn+uTYg9wXXGvcZNirk4x84D2WigaRXQ== X-Received: by 2002:adf:f6cb:0:b0:220:7859:7bf with SMTP id y11-20020adff6cb000000b00220785907bfmr11693195wrp.683.1661962152263; Wed, 31 Aug 2022 09:09:12 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id q28-20020a056000137c00b002205cbc1c74sm12405331wrz.101.2022.08.31.09.09.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 09:09:11 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 31 Aug 2022 16:09:03 +0000 Subject: [PATCH v4 3/4] fsmonitor: ensure filesystem and unix socket filesystem are compatible Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Eric DeCosta , Eric DeCosta Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Eric DeCosta From: Eric DeCosta Perform separate checks for the working directory and Unix domain socket (UDS) file location. The working directory may be located on a network-mounted file system if 'fsmonitor.allowRemote' is true. The UDS file may never be located on a network-mounted file system; additionally it may not be located on FAT32 or NTFS file systems. Signed-off-by: Eric DeCosta --- compat/fsmonitor/fsm-settings-darwin.c | 72 +++++++++++++++++++------- 1 file changed, 52 insertions(+), 20 deletions(-) diff --git a/compat/fsmonitor/fsm-settings-darwin.c b/compat/fsmonitor/fsm-settings-darwin.c index efc732c0f31..dc79538607f 100644 --- a/compat/fsmonitor/fsm-settings-darwin.c +++ b/compat/fsmonitor/fsm-settings-darwin.c @@ -3,11 +3,12 @@ #include "repository.h" #include "fsmonitor-settings.h" #include "fsmonitor.h" +#include "fsmonitor-ipc.h" #include #include /* - * [1] Remote working directories are problematic for FSMonitor. + * Remote working directories are problematic for FSMonitor. * * The underlying file system on the server machine and/or the remote * mount type (NFS, SAMBA, etc.) dictates whether notification events @@ -27,26 +28,8 @@ * In theory, the above issues need to be addressed whether we are * using the Hook or IPC API. * - * For the builtin FSMonitor, we create the Unix domain socket for the - * IPC in the .git directory. If the working directory is remote, - * then the socket will be created on the remote file system. This - * can fail if the remote file system does not support UDS file types - * (e.g. smbfs to a Windows server) or if the remote kernel does not - * allow a non-local process to bind() the socket. (These problems - * could be fixed by moving the UDS out of the .git directory and to a - * well-known local directory on the client machine, but care should - * be taken to ensure that $HOME is actually local and not a managed - * file share.) - * * So (for now at least), mark remote working directories as - * incompatible. - * - * - * [2] FAT32 and NTFS working directories are problematic too. - * - * The builtin FSMonitor uses a Unix domain socket in the .git - * directory for IPC. These Windows drive formats do not support - * Unix domain sockets, so mark them as incompatible for the daemon. + * incompatible unless fsmonitor.allowRemote is true. * */ static enum fsmonitor_reason check_volume(struct repository *r) @@ -65,6 +48,51 @@ static enum fsmonitor_reason check_volume(struct repository *r) "statfs('%s') [type 0x%08x][flags 0x%08x] '%s'", r->worktree, fs.f_type, fs.f_flags, fs.f_fstypename); + if (!(fs.f_flags & MNT_LOCAL) + && (fsm_settings__get_allow_remote(r) < 1)) + return FSMONITOR_REASON_REMOTE; + + return FSMONITOR_REASON_OK; +} + +/* + * For the builtin FSMonitor, we create the Unix domain socket (UDS) + * for the IPC in the .git directory by default or $HOME if + * fsmonitor.allowRemote is true. If the directory is remote, + * then the socket will be created on the remote file system. This + * can fail if the remote file system does not support UDS file types + * (e.g. smbfs to a Windows server) or if the remote kernel does not + * allow a non-local process to bind() the socket. + * + * Therefore remote UDS locations are marked as incompatible. + * + * FAT32 and NTFS working directories are problematic too. + * + * These Windows drive formats do not support Unix domain sockets, so + * mark them as incompatible for the location of the UDS file. + * + */ +static enum fsmonitor_reason check_uds_volume(void) +{ + struct statfs fs; + struct strbuf path = STRBUF_INIT; + const char *ipc_path = fsmonitor_ipc__get_path(); + strbuf_add(&path, ipc_path, strlen(ipc_path)); + + if (statfs(dirname(path.buf), &fs) == -1) { + int saved_errno = errno; + trace_printf_key(&trace_fsmonitor, "statfs('%s') failed: %s", + path.buf, strerror(saved_errno)); + errno = saved_errno; + strbuf_release(&path); + return FSMONITOR_REASON_ERROR; + } + + trace_printf_key(&trace_fsmonitor, + "statfs('%s') [type 0x%08x][flags 0x%08x] '%s'", + path.buf, fs.f_type, fs.f_flags, fs.f_fstypename); + strbuf_release(&path); + if (!(fs.f_flags & MNT_LOCAL)) return FSMONITOR_REASON_REMOTE; @@ -85,5 +113,9 @@ enum fsmonitor_reason fsm_os__incompatible(struct repository *r) if (reason != FSMONITOR_REASON_OK) return reason; + reason = check_uds_volume(); + if (reason != FSMONITOR_REASON_OK) + return reason; + return FSMONITOR_REASON_OK; } From patchwork Wed Aug 31 16:09:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric DeCosta X-Patchwork-Id: 12961025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63913ECAAD3 for ; Wed, 31 Aug 2022 16:09:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231727AbiHaQJd (ORCPT ); Wed, 31 Aug 2022 12:09:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231454AbiHaQJW (ORCPT ); Wed, 31 Aug 2022 12:09:22 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD426C3F69 for ; Wed, 31 Aug 2022 09:09:15 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id k6-20020a05600c1c8600b003a54ecc62f6so8279881wms.5 for ; Wed, 31 Aug 2022 09:09:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc; bh=Zg7O1XjMqNJ0aoj0nTaeReoT+ibJ7sZub876zOA0gsY=; b=f75KbIW3tBpD4pLYwNbFjabreI1uUCGTN9jZzxHbxB7V9yj47I6pixqpVdibzdkpdZ 4ySKboIKJxP2Abk/LTe5qma5aERlVidnBQrAMEU7P+4ydfmCmURKmKRQ/T6B3mdU5Yom tnbV279zD/hvKeJ4pxGu68sVV7nhh9b/z3kuxBj8A/oxm0ZvgOStQnCEiqr+tPAGtvrH 8PwfOJueGiMh+UGv/Yz47OeHt+VrcsmSGYWMIRJsKch/uW9aRY3yUguZHwwPxsU00Rpn ZZxZU+4GGD/fH2JK8uewIjspZsB1MEA7A72j62bNQ13dXTZypbXTI6y1HHYIrT51lS08 VBjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc; bh=Zg7O1XjMqNJ0aoj0nTaeReoT+ibJ7sZub876zOA0gsY=; b=CoAg436aYseoHt+NBbwT3sWeQov7bwXplJTTfVd7bbn6Z993aGW8LuDYkn03Eu2lmI Wi0UCvo4OhShmK9LKxJREqNlTHUhB+eeK7xzWbkLLa6sH6tiIvpftK2vu5tqWKSDCuEo OBaSIoxAgstk6WOZz1R5jIuHl+itxlguEwVU6cFiK5+3sh7ZSBrMSdcDj2vOHsFATJSO jgzwbs3kQTr7+C1AQd1Jven9RvAk58QAMV1s/US0vjeuqSa5GpoTOuM8fPqO1Zjn8hDP VwhgHY4++rsyV7ZpEs8GDxr+VeL8GuxHEN6jb5Kmc3uMqZaB2it9a64OZjlEbrJi/Igv 0niQ== X-Gm-Message-State: ACgBeo24UfQ71pKLTfB3D0YyEUqqH975hHBUgEyj7iK3G1rVgP7bp6pJ FeGiwwak0XYoLx3sHKtUqTd9dqFmI9A= X-Google-Smtp-Source: AA6agR6o+aEycLIssOMvcFHUA083j7opI9lp7hVe+XP0NdL834yELwlxEq32vNbFek4fzjfc3osNTw== X-Received: by 2002:a05:600c:418a:b0:3a5:e724:21d4 with SMTP id p10-20020a05600c418a00b003a5e72421d4mr2547777wmh.168.1661962154175; Wed, 31 Aug 2022 09:09:14 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c16-20020adffb50000000b00226d473ebd6sm10952364wrs.86.2022.08.31.09.09.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 09:09:13 -0700 (PDT) Message-Id: <56cabf3be3b9e228bc948da372db4c9d11fd3926.1661962145.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 31 Aug 2022 16:09:04 +0000 Subject: [PATCH v4 4/4] fsmonitor: normalize FSEvents event paths to the real path Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Eric DeCosta , Eric DeCosta Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Eric DeCosta From: Eric DeCosta Consider the following network working directory that is mounted under /System/Volumes/Data: /network/working/directory The git working directory path is: /System/Volumes/Data/network/working/directory The paths reported by FSEvents always start with /network. fsmonitor expects paths to be under the working directory; therefore it fails to match /network/... and ignores the change. Change things such that if fsmonitor.allowRemote is true that the paths reported via FSEevents are normalized to the real path. Signed-off-by: Eric DeCosta --- compat/fsmonitor/fsm-listen-darwin.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/compat/fsmonitor/fsm-listen-darwin.c b/compat/fsmonitor/fsm-listen-darwin.c index 8e208e8289e..2ed828649ff 100644 --- a/compat/fsmonitor/fsm-listen-darwin.c +++ b/compat/fsmonitor/fsm-listen-darwin.c @@ -26,6 +26,7 @@ #include "fsmonitor.h" #include "fsm-listen.h" #include "fsmonitor--daemon.h" +#include "fsmonitor-settings.h" struct fsm_listen_data { @@ -183,7 +184,6 @@ static void my_add_path(struct fsmonitor_batch *batch, const char *path) free(composed); } - static void fsevent_callback(ConstFSEventStreamRef streamRef, void *ctx, size_t num_of_events, @@ -209,7 +209,12 @@ static void fsevent_callback(ConstFSEventStreamRef streamRef, /* * On Mac, we receive an array of absolute paths. */ - path_k = paths[k]; + if (fsm_settings__get_allow_remote(the_repository) > 0) { + strbuf_reset(&tmp); + strbuf_realpath_forgiving(&tmp, paths[k], 0); + path_k = tmp.buf; + } else + path_k = paths[k]; /* * If you want to debug FSEvents, log them to GIT_TRACE_FSMONITOR. @@ -237,6 +242,7 @@ static void fsevent_callback(ConstFSEventStreamRef streamRef, fsmonitor_force_resync(state); fsmonitor_batch__free_list(batch); + batch = NULL; string_list_clear(&cookie_list, 0); /* @@ -313,7 +319,6 @@ static void fsevent_callback(ConstFSEventStreamRef streamRef, case IS_WORKDIR_PATH: /* try to queue normal pathnames */ - if (trace_pass_fl(&trace_fsmonitor)) log_flags_set(path_k, event_flags[k]);