perf namespaces: Avoid get_current_dir_name dependency
Ian Rogers
reviewerPATCH 1/2 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.
Signed-off-by Ian Rogers <[email protected]>
--- tools/perf/Makefile.config | 4 ---- tools/perf/util/Build | 1 - tools/perf/util/get_current_dir_name.c | 18 ------------------ tools/perf/util/get_current_dir_name.h | 8 -------- tools/perf/util/namespaces.c | 14 +++++--------- 5 files changed, 5 insertions(+), 40 deletions(-) delete mode 100644 tools/perf/util/get_current_dir_name.c delete mode 100644 tools/perf/util/get_current_dir_name.h
tools/perf/Makefile.config +0 -4
@@ -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
tools/perf/util/Build +0 -1
@@ -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-y += mmap.o perf-util-y += memswap.o
tools/perf/util/get_current_dir_name.c deleted +0 -18
@@ -1,18 +0,0 @@ -// SPDX-License-Identifier: LGPL-2.1 -// Copyright (C) 2018, 2019 Red Hat Inc, Arnaldo Carvalho de Melo <[email protected]> -// -#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
tools/perf/util/get_current_dir_name.h deleted +0 -8
@@ -1,8 +0,0 @@ -// SPDX-License-Identifier: LGPL-2.1 -// Copyright (C) 2018, 2019 Red Hat Inc, Arnaldo Carvalho de Melo <[email protected]> -// -#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
tools/perf/util/namespaces.c +5 -9
@@ -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>
@@ -279,10 +278,9 @@ void nsinfo__set_in_pidns(struct nsinfo *nsi)void nsinfo__mountns_enter (struct nsinfo *nsi,struct nscookie *nc) { -char curpath[PATH_MAX ]; +char oldcwd[PATH_MAX ];int oldns =-1 ;int newns =-1 ; -char *oldcwd =NULL ;if (nc ==NULL )return ;
@@ -293,14 +291,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 (oldcwd,sizeof (oldcwd)))return ; - oldcwd =get_current_dir_name (); -if (!oldcwd) + nc->oldcwd =strdup (oldcwd); +if (!nc->oldcwd)return ; - oldns =open (curpath,O_RDONLY ); + oldns =open ("/proc/self/ns/mnt" ,O_RDONLY );if (oldns <0 ) goto errout;
@@ -311,13 +309,11 @@ void nsinfo__mountns_enter(struct nsinfo *nsi,if (setns (newns,CLONE_NEWNS ) <0 ) goto errout; - nc->oldcwd = oldcwd; nc->oldns = oldns; nc->newns = newns;return ; errout: -free (oldcwd);if (oldns >-1 )close (oldns);if (newns >-1 )
Signature · 1 line
2.51.0.618.g983fd99d29-goog
Ian Rogers
reviewerPATCH 2/2 tools build: Remove get_current_dir_name
As perf no longer tests for this feature, and it was the only user, remove the feature test.
Signed-off-by Ian Rogers <[email protected]>
--- tools/build/Makefile.feature | 1 - tools/build/feature/Makefile | 4 ---- tools/build/feature/test-all.c | 4 ---- tools/build/feature/test-get_current_dir_name.c | 11 ----------- 4 files changed, 20 deletions(-) delete mode 100644 tools/build/feature/test-get_current_dir_name.c
tools/build/Makefile.feature +0 -1
@@ -68,7 +68,6 @@ FEATURE_TESTS_BASIC := \ libdw \ eventfd \ fortify-source \ - get_current_dir_name \ gettid \ glibc \ libbfd \
tools/build/feature/Makefile +0 -4
@@ -8,7 +8,6 @@ FILES= \ test-libdw.bin \ test-eventfd.bin \ test-fortify-source.bin \ - test-get_current_dir_name.bin \ test-glibc.bin \ test-gtk2.bin \ test-gtk2-infobar.bin \
@@ -147,9 +146,6 @@ $(OUTPUT)test-libelf.bin: $(OUTPUT)test-eventfd.bin: $(BUILD) -$(OUTPUT)test-get_current_dir_name.bin: - $(BUILD) - $(OUTPUT)test-glibc.bin: $(BUILD)
tools/build/feature/test-all.c +0 -4
@@ -22,10 +22,6 @@# include "test-libelf.c" #undef main -#define main main_test_get_current_dir_name -# include "test-get_current_dir_name.c" -#undef main -#define main main_test_gettid# include "test-gettid.c" #undef main
tools/build/feature/test-get_current_dir_name.c deleted +0 -11
@@ -1,11 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#define _GNU_SOURCE -#include <unistd.h> -#include <stdlib.h> - -int main (void ) -{ -free (get_current_dir_name ()); -return 0 ; -} -#undef _GNU_SOURCE
Signature · 1 line
2.51.0.618.g983fd99d29-goog