]> www.infradead.org Git - users/hch/misc.git/commitdiff
perf namespaces: Avoid get_current_dir_name dependency
authorIan Rogers <irogers@google.com>
Fri, 3 Oct 2025 17:56:12 +0000 (10:56 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 3 Oct 2025 18:28:04 +0000 (15:28 -0300)
get_current_dir_name is a GNU extension not supported on, for example,
Android. There is only one use of it so let's just switch to getcwd to
avoid build and other complexity.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/Makefile.config
tools/perf/util/Build
tools/perf/util/get_current_dir_name.c [deleted file]
tools/perf/util/get_current_dir_name.h [deleted file]
tools/perf/util/namespaces.c

index 481e7fe26f3b1eaed1def94d15899d9e8faf06be..76b92608a24e7451c1a955722c52df08b8a86aba 100644 (file)
@@ -417,10 +417,6 @@ ifeq ($(feature-eventfd), 1)
   CFLAGS += -DHAVE_EVENTFD_SUPPORT
 endif
 
-ifeq ($(feature-get_current_dir_name), 1)
-  CFLAGS += -DHAVE_GET_CURRENT_DIR_NAME
-endif
-
 ifeq ($(feature-gettid), 1)
   CFLAGS += -DHAVE_GETTID
 endif
index d31f5f252fa8bf5e2488d19f07e4c4071c5270fe..e6b396d919bbbf9f4dc7e528b438d1e6360875c5 100644 (file)
@@ -23,7 +23,6 @@ perf-util-y += evsel_fprintf.o
 perf-util-y += perf_event_attr_fprintf.o
 perf-util-y += evswitch.o
 perf-util-y += find_bit.o
-perf-util-y += get_current_dir_name.o
 perf-util-y += levenshtein.o
 perf-util-$(CONFIG_LIBBFD) += libbfd.o
 perf-util-y += llvm.o
diff --git a/tools/perf/util/get_current_dir_name.c b/tools/perf/util/get_current_dir_name.c
deleted file mode 100644 (file)
index e68935e..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-// SPDX-License-Identifier: LGPL-2.1
-// Copyright (C) 2018, 2019 Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
-//
-#ifndef HAVE_GET_CURRENT_DIR_NAME
-#include "get_current_dir_name.h"
-#include <limits.h>
-#include <string.h>
-#include <unistd.h>
-
-/* Android's 'bionic' library, for one, doesn't have this */
-
-char *get_current_dir_name(void)
-{
-       char pwd[PATH_MAX];
-
-       return getcwd(pwd, sizeof(pwd)) == NULL ? NULL : strdup(pwd);
-}
-#endif // HAVE_GET_CURRENT_DIR_NAME
diff --git a/tools/perf/util/get_current_dir_name.h b/tools/perf/util/get_current_dir_name.h
deleted file mode 100644 (file)
index 69f7d55..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-// SPDX-License-Identifier: LGPL-2.1
-// Copyright (C) 2018, 2019 Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
-//
-#ifndef __PERF_GET_CURRENT_DIR_NAME_H
-#ifndef HAVE_GET_CURRENT_DIR_NAME
-char *get_current_dir_name(void);
-#endif // HAVE_GET_CURRENT_DIR_NAME
-#endif // __PERF_GET_CURRENT_DIR_NAME_H
index 68f5de2d79c72c2cd1d2e722baad9e57bbb1e171..01502570b32d02abe0530bab6201cce644bd6d11 100644 (file)
@@ -6,7 +6,6 @@
 
 #include "namespaces.h"
 #include "event.h"
-#include "get_current_dir_name.h"
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -293,14 +292,14 @@ void nsinfo__mountns_enter(struct nsinfo *nsi,
        if (!nsi || !nsinfo__need_setns(nsi))
                return;
 
-       if (snprintf(curpath, PATH_MAX, "/proc/self/ns/mnt") >= PATH_MAX)
+       if (!getcwd(curpath, sizeof(curpath)))
                return;
 
-       oldcwd = get_current_dir_name();
+       oldcwd = strdup(curpath);
        if (!oldcwd)
                return;
 
-       oldns = open(curpath, O_RDONLY);
+       oldns = open("/proc/self/ns/mnt", O_RDONLY);
        if (oldns < 0)
                goto errout;