From: Kacper Michajłow Date: Tue, 3 Jan 2017 22:28:45 +0000 (+0100) Subject: Relax mtr-packet search rules. X-Git-Tag: v0.88~11^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F177%2Fhead;p=thirdparty%2Fmtr.git Relax mtr-packet search rules. First, mtr-packet or override path taken from MTR_PACKET env variable will be search in PATH if not found we falllback to current directory search. This way we can use mtr without installing or setting any additional env variables. Also fix batch file to support paths with spaces on Windows. --- diff --git a/build-aux/mtr.bat b/build-aux/mtr.bat index bda3fdd..044e4a7 100755 --- a/build-aux/mtr.bat +++ b/build-aux/mtr.bat @@ -18,15 +18,15 @@ rem Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. rem rem Assume the path of this batch file is the mtr installation location -set MTR_DIR=%~dp0 +set "MTR_DIR=%~dp0" -set MTR_BIN=%MTR_DIR%\bin +set "MTR_BIN=%MTR_DIR%\bin" rem ncurses needs to locate the cygwin terminfo file -set TERMINFO=%MTR_DIR%\terminfo +set "TERMINFO=%MTR_DIR%\terminfo" rem mtr needs to know the location to the packet generator -set MTR_PACKET=%MTR_BIN%\mtr-packet.exe +set "MTR_PACKET=%MTR_BIN%\mtr-packet.exe" rem Pass along commandline arguments -%MTR_BIN%\mtr %* +"%MTR_BIN%\mtr" %* diff --git a/ui/cmdpipe.c b/ui/cmdpipe.c index 81b1e7b..effabe2 100644 --- a/ui/cmdpipe.c +++ b/ui/cmdpipe.c @@ -210,34 +210,26 @@ int check_packet_features( static void execute_packet_child(void) { - char *mtr_packet_path; - /* - Allow the MTR_PACKET environment variable to overrride + Allow the MTR_PACKET environment variable to override the path to the mtr-packet executable. This is necessary for debugging changes for mtr-packet. */ - mtr_packet_path = getenv("MTR_PACKET"); + char *mtr_packet_path = getenv("MTR_PACKET"); if (mtr_packet_path == NULL) { mtr_packet_path = "mtr-packet"; } /* - First, try to execute using /usr/bin/env, because this - will search the PATH for mtr-packet + First, try to execute mtr-packet from PATH + or MTR_PACKET environment variable. */ - execl("/usr/bin/env", "mtr-packet", mtr_packet_path, (char *)NULL); + execlp(mtr_packet_path, "mtr-packet", (char *)NULL); /* - If env fails to execute, try to use the MTR_PACKET environment - as a full path to the executable. This is necessary because on - Windows, minimal mtr binary distributions will lack /usr/bin/env. - - Note: A side effect is that an mtr-packet in the current directory - could be executed. This will only be the case if /usr/bin/env - doesn't exist. + If mtr-packet is not found, try to use mtr-packet from current directory */ - execl(mtr_packet_path, "mtr-packet", (char *)NULL); + execl("./mtr-packet", "./mtr-packet", (char *)NULL); /* Both exec attempts failed, so nothing to do but exit */ exit(1);