arch, passt: Use executable link to form AVX2 binary path

...instead of argv[0], which might or might not contain a valid path
to the executable itself. Instead of mangling argv[0], use the same
link to find out if we're already running the AVX2 build where
supported.

Alternatively, we could use execvpe(), but that might result in
running a different installed version, in case e.g. the set of
binaries is present in both /usr/bin and /usr/local/bin, with both
being in $PATH.

Reported-by: Wenli Quan <wquan@redhat.com>
Link: https://bugzilla.redhat.com/show_bug.cgi?id=2101310
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
Stefano Brivio
2022-07-13 03:20:45 +02:00
parent 30ac86823b
commit 17689cc9bf
2 changed files with 21 additions and 13 deletions

View File

@@ -35,6 +35,7 @@
#include <sys/mount.h>
#include <netinet/ip.h>
#include <net/ethernet.h>
#include <libgen.h>
#include <stdlib.h>
#include <unistd.h>
#include <net/if.h>
@@ -283,11 +284,11 @@ int main(int argc, char **argv)
{
int nfds, i, devnull_fd = -1, pidfile_fd = -1, quit_fd;
struct epoll_event events[EPOLL_EVENTS];
char *log_name, argv0[PATH_MAX], *name;
struct ctx c = { 0 };
struct rlimit limit;
struct timespec now;
struct sigaction sa;
char *log_name;
arch_avx2_exec(argv);
@@ -304,14 +305,16 @@ int main(int argc, char **argv)
if (argc < 1)
exit(EXIT_FAILURE);
if (strstr(argv[0], "pasta")) {
strncpy(argv0, argv[0], PATH_MAX - 1);
name = basename(argv0);
if (strstr(name, "pasta")) {
sa.sa_handler = pasta_child_handler;
sigaction(SIGCHLD, &sa, NULL);
signal(SIGPIPE, SIG_IGN);
c.mode = MODE_PASTA;
log_name = "pasta";
} else if (strstr(argv[0], "passt")) {
} else if (strstr(name, "passt")) {
c.mode = MODE_PASST;
log_name = "passt";
} else {