Path: blob/main/filesystems/amazon-efs-utils/files/patch-src_watchdog_____init____.py
46590 views
--- src/watchdog/__init__.py.orig 2026-04-17 08:53:05 UTC1+++ src/watchdog/__init__.py2@@ -60,7 +60,7 @@ FS_PREFIX = "fs-"3SERVICE = "elasticfilesystem"4FS_PREFIX = "fs-"56-CONFIG_FILE = "/etc/amazon/efs/efs-utils.conf"7+CONFIG_FILE = "/usr/local/etc/amazon/efs/efs-utils.conf"8CONFIG_SECTION = "mount-watchdog"9MOUNT_CONFIG_SECTION = "mount"10CLIENT_INFO_SECTION = "client-info"11@@ -79,7 +79,7 @@ EFS_SERVICE_NAME = "elasticfilesystem"1213DEFAULT_NFS_PORT = "2049"14EFS_SERVICE_NAME = "elasticfilesystem"15-PRIVATE_KEY_FILE = "/etc/amazon/efs/privateKey.pem"16+PRIVATE_KEY_FILE = "/usr/local/etc/amazon/efs/privateKey.pem"17DEFAULT_REFRESH_SELF_SIGNED_CERT_INTERVAL_MIN = 6018DEFAULT_STUNNEL_HEALTH_CHECK_INTERVAL_MIN = 519DEFAULT_STUNNEL_HEALTH_CHECK_TIMEOUT_SEC = 3020@@ -742,7 +742,64 @@ def get_current_local_nfs_mounts(mount_file="/proc/mou21"""22mounts = []2324- if not check_if_running_on_macos():25+ if sys.platform.startswith("freebsd"):26+ # FreeBSD: no /proc/mounts, and neither mount(8) nor nfsstat(8) exposes27+ # the NFS client's TCP port. Use the watchdog's own state files as the28+ # source of truth: each mount created by mount.efs has a state file29+ # fs-<id>.<mountpoint-with-slashes-as-dots>.<port>30+ # in STATE_FILE_DIR. Cross-check with `mount -t nfs` so we skip state31+ # files whose mountpoint has already been unmounted. Keying off the32+ # state file (not the live proxy) lets the watchdog notice a dead33+ # efs-proxy and restart it.34+ live_mps = set()35+ try:36+ process = subprocess.run(37+ ["mount", "-t", "nfs"],38+ check=True,39+ stdout=subprocess.PIPE,40+ universal_newlines=True,41+ )42+ for line in process.stdout.splitlines():43+ parts = line.split()44+ if len(parts) >= 3 and parts[1] == "on":45+ live_mps.add(parts[2])46+ except Exception as e:47+ logging.warning("Unable to list NFS mounts: %s", e)48+49+ if live_mps:50+ try:51+ state_files = os.listdir(STATE_FILE_DIR)52+ except OSError:53+ state_files = []54+ seen = set()55+ for sf in state_files:56+ if not sf.startswith("fs-"):57+ continue58+ if sf.endswith("+") or "stunnel-config" in sf:59+ continue60+ # fs-<id>.<mountpoint-with-slashes-as-dots>.<port>61+ stem_port = sf.rsplit(".", 1)62+ if len(stem_port) != 2:63+ continue64+ stem, port = stem_port65+ try:66+ int(port)67+ except ValueError:68+ continue69+ inner = stem[len("fs-"):]70+ if "." not in inner:71+ continue72+ _, _, mp_enc = inner.partition(".")73+ mp = "/" + mp_enc.replace(".", "/")74+ if mp not in live_mps or (mp, port) in seen:75+ continue76+ seen.add((mp, port))77+ mounts.append(78+ Mount._make(79+ ["127.0.0.1:/", mp, "nfs", "port=" + port, 0, 0]80+ )81+ )82+ elif not check_if_running_on_macos():83with open(mount_file) as f:84for mount in f:85try:868788