Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf namespaces: Avoid get_current_dir_name dependency

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>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
062d02a9 2836ed17

+3 -35
-4
tools/perf/Makefile.config
··· 417 417 CFLAGS += -DHAVE_EVENTFD_SUPPORT 418 418 endif 419 419 420 - ifeq ($(feature-get_current_dir_name), 1) 421 - CFLAGS += -DHAVE_GET_CURRENT_DIR_NAME 422 - endif 423 - 424 420 ifeq ($(feature-gettid), 1) 425 421 CFLAGS += -DHAVE_GETTID 426 422 endif
-1
tools/perf/util/Build
··· 23 23 perf-util-y += perf_event_attr_fprintf.o 24 24 perf-util-y += evswitch.o 25 25 perf-util-y += find_bit.o 26 - perf-util-y += get_current_dir_name.o 27 26 perf-util-y += levenshtein.o 28 27 perf-util-$(CONFIG_LIBBFD) += libbfd.o 29 28 perf-util-y += llvm.o
-18
tools/perf/util/get_current_dir_name.c
··· 1 - // SPDX-License-Identifier: LGPL-2.1 2 - // Copyright (C) 2018, 2019 Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com> 3 - // 4 - #ifndef HAVE_GET_CURRENT_DIR_NAME 5 - #include "get_current_dir_name.h" 6 - #include <limits.h> 7 - #include <string.h> 8 - #include <unistd.h> 9 - 10 - /* Android's 'bionic' library, for one, doesn't have this */ 11 - 12 - char *get_current_dir_name(void) 13 - { 14 - char pwd[PATH_MAX]; 15 - 16 - return getcwd(pwd, sizeof(pwd)) == NULL ? NULL : strdup(pwd); 17 - } 18 - #endif // HAVE_GET_CURRENT_DIR_NAME
-8
tools/perf/util/get_current_dir_name.h
··· 1 - // SPDX-License-Identifier: LGPL-2.1 2 - // Copyright (C) 2018, 2019 Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com> 3 - // 4 - #ifndef __PERF_GET_CURRENT_DIR_NAME_H 5 - #ifndef HAVE_GET_CURRENT_DIR_NAME 6 - char *get_current_dir_name(void); 7 - #endif // HAVE_GET_CURRENT_DIR_NAME 8 - #endif // __PERF_GET_CURRENT_DIR_NAME_H
+3 -4
tools/perf/util/namespaces.c
··· 6 6 7 7 #include "namespaces.h" 8 8 #include "event.h" 9 - #include "get_current_dir_name.h" 10 9 #include <sys/types.h> 11 10 #include <sys/stat.h> 12 11 #include <fcntl.h> ··· 292 293 if (!nsi || !nsinfo__need_setns(nsi)) 293 294 return; 294 295 295 - if (snprintf(curpath, PATH_MAX, "/proc/self/ns/mnt") >= PATH_MAX) 296 + if (!getcwd(curpath, sizeof(curpath))) 296 297 return; 297 298 298 - oldcwd = get_current_dir_name(); 299 + oldcwd = strdup(curpath); 299 300 if (!oldcwd) 300 301 return; 301 302 302 - oldns = open(curpath, O_RDONLY); 303 + oldns = open("/proc/self/ns/mnt", O_RDONLY); 303 304 if (oldns < 0) 304 305 goto errout; 305 306