mirror of
https://github.com/cp2k/cp2k.git
synced 2026-07-28 14:15:19 -04:00
Make UNIX socket prefix configurable via DRIVER%PREFIX
Previously the "/tmp/qiskit_<host>" 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_<host>") 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
This commit is contained in:
parent
1b0cc9d292
commit
1e2f1ace14
3 changed files with 24 additions and 6 deletions
|
|
@ -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>_<HOST> (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)
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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/<PREFIX>_<HOST>. 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", &
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue