diff options
Diffstat (limited to 'libcrystfel/src/xds.c')
-rw-r--r-- | libcrystfel/src/xds.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/libcrystfel/src/xds.c b/libcrystfel/src/xds.c index ba053d2f..bfb977ea 100644 --- a/libcrystfel/src/xds.c +++ b/libcrystfel/src/xds.c @@ -45,6 +45,7 @@ #include <sys/ioctl.h> #include <errno.h> +#include "xds.h" #include "cell.h" #include "image.h" #include "utils.h" @@ -596,6 +597,12 @@ void *xds_prepare(IndexingMethod *indm, UnitCell *cell) { struct xds_private *xp; + if ( xds_probe(cell) == NULL ) { + ERROR("XDS does not appear to run properly.\n"); + ERROR("Please check your XDS installation.\n"); + return NULL; + } + /* Either cell,latt and cell provided, or nocell-nolatt and no cell * - complain about anything else. Could figure this out automatically, * but we'd have to decide whether the user just forgot the cell, or @@ -637,3 +644,57 @@ void xds_cleanup(void *pp) xp = (struct xds_private *)pp; free(xp); } + + +const char *xds_probe(UnitCell *cell) +{ + pid_t pid; + int pty; + int status; + FILE *fh; + char line[1024]; + int ok = 0; + int l; + + pid = forkpty(&pty, NULL, NULL, NULL); + if ( pid == -1 ) { + return NULL; + } + if ( pid == 0 ) { + + /* Child process */ + struct termios t; + + /* Turn echo off */ + tcgetattr(STDIN_FILENO, &t); + t.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL); + tcsetattr(STDIN_FILENO, TCSANOW, &t); + + execlp("xds", "xds", (char *)NULL); + _exit(1); + + } + + fh = fdopen(pty, "r"); + + for ( l=0; l<10; l++ ) { + char *pos; + if ( fgets(line, 1024, fh) == NULL ) { + ERROR("Failed to probe for XDS\n"); + } else { + pos = strstr(line, "** XDS **"); + if ( pos != NULL ) { + ok = 1; + } + } + } + + fclose(fh); + close(pty); + waitpid(pid, &status, 0); + + if ( !ok ) return NULL; + + if ( cell_has_parameters(cell) ) return "xds-cell-latt"; + return "xds-nocell-nolatt"; +} |