From 85dd2c80325b2b3253df95fac47c2f792165df57 Mon Sep 17 00:00:00 2001 From: Darafei Praliaskouski Date: Fri, 8 May 2026 06:53:38 +0400 Subject: [PATCH] fix(install): honor transformed packet helper --- Makefile.am | 9 +++++++-- configure.ac | 16 ++++++++++++++++ ui/cmdpipe.c | 22 ++++++++++++++++------ 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/Makefile.am b/Makefile.am index a74cb20..6a6515f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -41,8 +41,13 @@ dist_man_MANS = mtr.8 mtr-packet.8 PATHFILES += man/mtr.8 man/mtr-packet.8 install-exec-hook: - `setcap cap_net_raw+ep $(DESTDIR)$(sbindir)/mtr-packet` \ - || chmod u+s $(DESTDIR)$(sbindir)/mtr-packet + mtr_packet_name=`echo mtr-packet | sed '$(transform)'`; \ + if command -v setcap >/dev/null 2>&1; then \ + setcap cap_net_raw+ep $(DESTDIR)$(sbindir)/$$mtr_packet_name \ + || chmod u+s $(DESTDIR)$(sbindir)/$$mtr_packet_name; \ + else \ + chmod u+s $(DESTDIR)$(sbindir)/$$mtr_packet_name; \ + fi mtr_SOURCES = ui/mtr.c ui/mtr.h \ ui/net.c ui/net.h \ diff --git a/configure.ac b/configure.ac index 444aad6..8b31a03 100644 --- a/configure.ac +++ b/configure.ac @@ -287,6 +287,22 @@ AC_ARG_ENABLE([bash-completion], [], [enable_bash_completion=yes] ) AM_CONDITIONAL([BUILD_BASH_COMPLETION], [test "x$enable_bash_completion" = xyes]) + +mtr_packet_prefix= +mtr_packet_suffix= +AS_IF([test "x$program_prefix" != "xNONE"], [ + mtr_packet_prefix=$program_prefix +]) +AS_IF([test "x$program_suffix" != "xNONE"], [ + mtr_packet_suffix=$program_suffix +]) +MTR_PACKET_NAME="${mtr_packet_prefix}mtr-packet${mtr_packet_suffix}" +AC_SUBST([MTR_PACKET_NAME]) +AC_DEFINE_UNQUOTED( + [MTR_PACKET_NAME], + ["$MTR_PACKET_NAME"], + [Name of the installed mtr-packet executable after program transforms.]) + echo "build options:" echo "--------------" echo "libasan :$with_libasan" diff --git a/ui/cmdpipe.c b/ui/cmdpipe.c index bd5606a..f213315 100644 --- a/ui/cmdpipe.c +++ b/ui/cmdpipe.c @@ -215,6 +215,7 @@ void execute_packet_child( void) { char buf[256]; + char *path_end; /* Allow the MTR_PACKET environment variable to override the path to the mtr-packet executable. This is necessary @@ -230,25 +231,34 @@ void execute_packet_child( if (access ("/etc/mtr.is.run.under.sudo", F_OK) != 0) mtr_packet_path = getenv("MTR_PACKET"); if (mtr_packet_path == NULL) - mtr_packet_path = "mtr-packet"; + mtr_packet_path = MTR_PACKET_NAME; /* First, try to execute mtr-packet from PATH or MTR_PACKET environment variable. */ - execlp(mtr_packet_path, "mtr-packet", (char *) NULL); + execlp(mtr_packet_path, MTR_PACKET_NAME, (char *) NULL); /* Then try to find it where WE were executed from. */ - strncpy (buf, myname, 240); - strcat (buf, "-packet"); - mtr_packet_path = buf; - execl(mtr_packet_path, "mtr-packet", (char *) NULL); + path_end = strrchr(myname, '/'); + + if (path_end != NULL) { + size_t dir_length = path_end - myname + 1; + + if (dir_length + strlen(MTR_PACKET_NAME) < sizeof(buf)) { + memcpy(buf, myname, dir_length); + strcpy(buf + dir_length, MTR_PACKET_NAME); + mtr_packet_path = buf; + execl(mtr_packet_path, MTR_PACKET_NAME, (char *) NULL); + } + } /* If mtr-packet is not found, try to use mtr-packet from current directory */ + execl("./" MTR_PACKET_NAME, "./" MTR_PACKET_NAME, (char *) NULL); execl("./mtr-packet", "./mtr-packet", (char *) NULL); /* Both exec attempts failed, so nothing to do but exit */ -- 2.47.3