From ff20692598ffc5e34bd846ed7a68594c08d2c13f Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 2 Oct 2023 11:41:32 +0200 Subject: 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. --- src/align_detector.c | 56 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 14 deletions(-) (limited to 'src/align_detector.c') 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 #include #include +#include #include #include @@ -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"); -- cgit v1.2.3