From 1e2f1ace1441fa31de7bb70e2013c6eea4ac4163 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20H=C3=A4nseroth?= Date: Wed, 8 Jul 2026 16:04:01 +0200 Subject: [PATCH] Make UNIX socket prefix configurable via DRIVER%PREFIX Previously the "/tmp/qiskit_" prefix used for UNIX-domain sockets in i-PI driver mode was hardcoded in sockets.c, which breaks interoperability with i-PI (which expects "/tmp/ipi_") and any other driver using a different naming convention. Adds a PREFIX keyword to &MOTION/&DRIVER (default "ipi") and builds the full socket path in Fortran, aligning open_connect_socket with open_bind_socket, which already treats the host argument as a caller-supplied full path. Fixes #3884 --- src/ipi_driver.F | 12 ++++++++++-- src/sockets.c | 8 +++++--- src/start/input_cp2k_motion.F | 10 +++++++++- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/ipi_driver.F b/src/ipi_driver.F index ea8b57b9a3..3f557b59a3 100644 --- a/src/ipi_driver.F +++ b/src/ipi_driver.F @@ -87,7 +87,7 @@ CONTAINS #else INTEGER, PARAMETER :: MSGLEN = 12 - CHARACTER(len=default_path_length) :: c_hostname, drv_hostname + CHARACTER(len=default_path_length) :: c_hostname, drv_hostname, drv_prefix CHARACTER(LEN=default_string_length) :: header INTEGER :: drv_port, handle, i_drv_unix, & idir, ii, inet, ip, iwait, & @@ -132,6 +132,7 @@ CONTAINS CALL section_vals_val_get(drv_section, "HOST", c_val=drv_hostname) CALL section_vals_val_get(drv_section, "PORT", i_val=drv_port) CALL section_vals_val_get(drv_section, "UNIX", l_val=drv_unix) + CALL section_vals_val_get(drv_section, "PREFIX", c_val=drv_prefix) CALL section_vals_val_get(drv_section, "SLEEP_TIME", r_val=sleeptime) CPASSERT(sleeptime >= 0) @@ -145,7 +146,14 @@ CONTAINS WRITE (output_unit, *) "@ INPUT DATA: ", TRIM(drv_hostname), drv_port, drv_unix END IF - c_hostname = TRIM(drv_hostname)//C_NULL_CHAR + IF (drv_unix) THEN + ! for UNIX sockets, HOST names the socket file which lives at + ! /tmp/_ (PREFIX must match the peer's convention, + ! e.g. "ipi" for i-PI) + c_hostname = "/tmp/"//TRIM(drv_prefix)//"_"//TRIM(drv_hostname)//C_NULL_CHAR + ELSE + c_hostname = TRIM(drv_hostname)//C_NULL_CHAR + END IF IF (ionode) CALL open_connect_socket(socket, i_drv_unix, drv_port, c_hostname) NULLIFY (wait_msg) diff --git a/src/sockets.c b/src/sockets.c index dc2e00afe6..067635251f 100644 --- a/src/sockets.c +++ b/src/sockets.c @@ -61,7 +61,10 @@ * \param port The port number for the socket to be created. Low numbers are * often reserved for important channels, so use of numbers of 4 * or more digits is recommended. - * \param host The name of the host server. + * \param host The name of the host server (inet socket), or the full path + * of the UNIX socket file (unix socket). The caller is + * responsible for building this path, e.g. by prepending a + * prefix such as "/tmp/ipi_". * \note Fortran passes an extra argument for the string length, but this is * ignored here for C compatibility. ******************************************************************************/ @@ -105,8 +108,7 @@ void open_connect_socket(int *psockfd, int *inet, int *port, char *host) { // fills up details of the socket address memset(&serv_addr, 0, sizeof(serv_addr)); serv_addr.sun_family = AF_UNIX; - strcpy(serv_addr.sun_path, "/tmp/qiskit_"); - strcpy(serv_addr.sun_path + 12, host); + strcpy(serv_addr.sun_path, host); // creates the socket sockfd = socket(AF_UNIX, SOCK_STREAM, 0); diff --git a/src/start/input_cp2k_motion.F b/src/start/input_cp2k_motion.F index 550678a73f..cb9af737aa 100644 --- a/src/start/input_cp2k_motion.F +++ b/src/start/input_cp2k_motion.F @@ -1692,7 +1692,7 @@ CONTAINS CALL section_create(section, __LOCATION__, name="DRIVER", & description="This section defines the parameters needed to run in i-PI driver mode.", & citations=[Ceriotti2014, Kapil2016], & - n_keywords=3, n_subsections=0, repeats=.FALSE.) + n_keywords=4, n_subsections=0, repeats=.FALSE.) NULLIFY (keyword) CALL keyword_create(keyword, __LOCATION__, name="unix", & @@ -1716,6 +1716,14 @@ CONTAINS CALL section_add_keyword(section, keyword) CALL keyword_release(keyword) + CALL keyword_create(keyword, __LOCATION__, name="PREFIX", & + description="Prefix used to build the path of the UNIX socket file, "// & + "as /tmp/_. Only relevant if UNIX is set to true.", & + usage="PREFIX ipi", & + default_c_val="ipi") + CALL section_add_keyword(section, keyword) + CALL keyword_release(keyword) + CALL keyword_create(keyword, __LOCATION__, name="SLEEP_TIME", & description="Sleeping time while waiting for for driver commands [s].", & usage="SLEEP_TIME 0.1", &