@@ -768,12 +768,12 @@ def _cleanup_rsyncd(proc, port: int) -> 'None':
768768
769769
770770def start_rsyncd (conf_path , port : int , rsync_cmd : str = None ,
771- stdin = subprocess .DEVNULL ) -> 'subprocess.Popen' :
772- """Spawn `rsync --daemon --no-detach --address=127.0.0.1 --port=N
771+ stdin = subprocess .DEVNULL , address : str = '127.0.0.1' ) -> 'subprocess.Popen' :
772+ """Spawn `rsync --daemon --no-detach --address=ADDRESS --port=N
773773 --config=conf` and return the Popen handle after the port is accepting
774774 connections.
775775
776- The daemon is bound to LOOPBACK ONLY (--address=127.0.0.1) : without it ,
776+ The daemon is bound to LOOPBACK ONLY: without an explicit address ,
777777 rsync --daemon binds 0.0.0.0 and the test modules would be reachable from
778778 the whole LAN. The daemon is killed automatically when this Python
779779 process exits (atexit). On Linux, the kernel also signals SIGTERM to the
@@ -791,9 +791,11 @@ def start_rsyncd(conf_path, port: int, rsync_cmd: str = None,
791791 This is only ever reached from start_test_daemon() in --use-tcp mode; the
792792 default (pipe) mode never starts a listening daemon.
793793 """
794+ if address not in ('127.0.0.1' , '::1' ):
795+ test_fail (f"test daemon address is not loopback: { address } " )
794796 argv = shlex .split (rsync_cmd or RSYNC_PEER ) + [
795797 '--daemon' , '--no-detach' ,
796- '--address=127.0.0.1 ' ,
798+ f '--address={ address } ' ,
797799 f'--port={ port } ' ,
798800 f'--config={ conf_path } ' ,
799801 ]
@@ -820,17 +822,18 @@ def start_rsyncd(conf_path, port: int, rsync_cmd: str = None,
820822 f"(status={ proc .returncode } )"
821823 )
822824 try :
823- with _socket .create_connection (('127.0.0.1' , port ), timeout = 0.5 ):
825+ with _socket .create_connection ((address , port ), timeout = 0.5 ):
824826 return proc
825827 except OSError as e :
826828 last_err = e
827829 time .sleep (0.05 )
828830
829831 _stop_rsyncd (proc )
830- test_fail (f"rsyncd never listened on 127.0.0.1 :{ port } : { last_err } " )
832+ test_fail (f"rsyncd never listened on { address } :{ port } : { last_err } " )
831833
832834
833- def start_test_daemon (conf_path , port : int , rsync_cmd : str = None ) -> str :
835+ def start_test_daemon (conf_path , port : int , rsync_cmd : str = None ,
836+ address : str = '127.0.0.1' ) -> str :
834837 """Bring up the test daemon and return a URL prefix for client commands.
835838
836839 rsync_cmd selects the daemon-side binary (default RSYNC_PEER); pass
@@ -844,20 +847,21 @@ def start_test_daemon(conf_path, port: int, rsync_cmd: str = None) -> str:
844847 'rsync://localhost/'. Another local user can't reach it; nothing is
845848 listening.
846849
847- * --use-tcp -- starts a real rsyncd bound to 127.0.0.1 on the given
848- claim_ports()-reserved port. Returns 'rsync://localhost:PORT/'. Bound
849- to loopback so off -host/LAN access is impossible; a same-host user
850- could still connect during the test window, which is the documented,
851- accepted cost of explicitly opting into TCP.
850+ * --use-tcp -- starts a real rsyncd bound to IPv4 loopback by default,
851+ or to the selected loopback address, on the claim_ports()-reserved
852+ port. Off -host/LAN access is impossible; a same-host user could still
853+ connect during the test window, which is the documented, accepted cost
854+ of explicitly opting into TCP.
852855
853856 Build URLs as f"{prefix}module/path". `port` is only used (and claimed)
854857 in --use-tcp mode.
855858 """
856859 daemon_cmd = rsync_cmd or RSYNC_PEER
857860 if USE_TCP :
858861 port = claim_free_port (port )
859- start_rsyncd (conf_path , port , daemon_cmd )
860- return f'rsync://localhost:{ port } /'
862+ start_rsyncd (conf_path , port , daemon_cmd , address = address )
863+ host = 'localhost' if address == '127.0.0.1' else f'[{ address } ]'
864+ return f'rsync://{ host } :{ port } /'
861865 # RSYNC_CONNECT_PROG is run by a shell, so every word has to survive
862866 # re-parsing: a build path with a space would otherwise exec its prefix.
863867 os .environ ['RSYNC_CONNECT_PROG' ] = (
0 commit comments