diff options
author | Thomas White <taw@physics.org> | 2023-10-02 11:41:32 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2023-10-02 11:41:32 +0200 |
commit | ff20692598ffc5e34bd846ed7a68594c08d2c13f (patch) | |
tree | 332503c48e492e53017e423d8061d1ea24f3c821 | |
parent | 1a0580e817a0f60505e38c8dd29f9e4eeeae0558 (diff) |
align_detector: Try to find 'pede' next to align_detector binary
Lots of things can go wrong here, in which case it falls back to the
shell search path.
-rw-r--r-- | src/align_detector.c | 56 |
1 files changed, 42 insertions, 14 deletions
diff --git a/src/align_detector.c b/src/align_detector.c index c4059f2c..bdad7039 100644 --- a/src/align_detector.c +++ b/src/align_detector.c @@ -38,6 +38,7 @@ #include <stdio.h> #include <string.h> #include <getopt.h> +#include <libgen.h> #include <datatemplate.h> #include <utils.h> @@ -214,6 +215,46 @@ static int different(time_t a, time_t b) } +static int run_pede() +{ + char buf[1024]; + char cmdline[1280]; + int r; + + if ( readlink("/proc/self/exe", buf, 1024) != -1 ) { + char *dir = dirname(buf); + strcpy(cmdline, dir); + strcat(cmdline, "/pede"); + if ( !file_exists(cmdline) ) { + ERROR("Couldn't find %s - falling back on shell path\n"); + strcpy(cmdline, "pede millepede.txt"); + } else { + strcat(cmdline, " millepede.txt"); + } + } else { + ERROR("readlink() failed: %s\n", strerror(errno)); + strcpy(cmdline, "pede millepede.txt"); + } + + STATUS("Running '%s'\n", cmdline); + r = system(cmdline); + if ( r == -1 ) { + ERROR("Failed to run Millepde: %s\n", strerror(errno)); + return 1; + } + if ( !WIFEXITED(r) ) { + ERROR("Millepede exited abnormally.\n"); + return 1; + } + if ( WEXITSTATUS(r) != 0 ) { + ERROR("Millepede returned an error status (%i)\n", WEXITSTATUS(r)); + return 1; + } + + return 0; +} + + int main(int argc, char *argv[]) { int c; @@ -363,20 +404,7 @@ int main(int argc, char *argv[]) unlink("millepede.res"); - r = system("pede millepede.txt"); - if ( r == -1 ) { - ERROR("Failed to run Millepde: %s\n", strerror(errno)); - return 1; - } - if ( !WIFEXITED(r) ) { - ERROR("Millepede exited abnormally.\n"); - return 1; - } - if ( WEXITSTATUS(r) != 0 ) { - ERROR("Millepede returned an error status (%i)\n", WEXITSTATUS(r)); - return 1; - } - + if ( run_pede() ) return 1; STATUS("Millepede succeeded.\n\n"); fh = fopen("millepede.res", "r"); |