]> git.ipfire.org Git - thirdparty/mtr.git/commitdiff
Relax mtr-packet search rules. 177/head
authorKacper Michajłow <kasper93@gmail.com>
Tue, 3 Jan 2017 22:28:45 +0000 (23:28 +0100)
committerKacper Michajłow <kasper93@gmail.com>
Wed, 4 Jan 2017 16:35:19 +0000 (17:35 +0100)
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.

build-aux/mtr.bat
ui/cmdpipe.c

index bda3fdd477a5ebee2c5a2ede8cf87aee25a629b7..044e4a747e4a2cfdb676bb6fa3ad76d20fbf26ee 100755 (executable)
@@ -18,15 +18,15 @@ rem  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 rem\r
 \r
 rem Assume the path of this batch file is the mtr installation location\r
-set MTR_DIR=%~dp0\r
+set "MTR_DIR=%~dp0"\r
 \r
-set MTR_BIN=%MTR_DIR%\bin\r
+set "MTR_BIN=%MTR_DIR%\bin"\r
 \r
 rem ncurses needs to locate the cygwin terminfo file\r
-set TERMINFO=%MTR_DIR%\terminfo\r
+set "TERMINFO=%MTR_DIR%\terminfo"\r
 \r
 rem mtr needs to know the location to the packet generator\r
-set MTR_PACKET=%MTR_BIN%\mtr-packet.exe\r
+set "MTR_PACKET=%MTR_BIN%\mtr-packet.exe"\r
 \r
 rem Pass along commandline arguments\r
-%MTR_BIN%\mtr %*\r
+"%MTR_BIN%\mtr" %*\r
index 81b1e7bc98bbe61d81d5cfeaeb44b92d8191fc91..effabe293a6929347a4b6a02185d3a7299ee4058 100644 (file)
@@ -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);