From dcb2c3c304c9ffd6a3e0146c79759194e3f66ba5 Mon Sep 17 00:00:00 2001 From: Petr Machata Date: Mon, 2 Mar 2015 16:50:54 +0100 Subject: [PATCH] Do not warn about bogus config files that come from environment - The logic being that the environment can contain all sorts of nonsense, and ltrace shouldn't bother user with this. However if a bogon is explicitly requested by -F, warnings shouldn't be muffled. --- options.c | 12 +++++++---- options.h | 11 ++++++++-- sysdeps/linux-gnu/hooks.c | 4 ++-- testsuite/ltrace.main/XDG_CONFIG_DIRS.exp | 35 +++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 testsuite/ltrace.main/XDG_CONFIG_DIRS.exp diff --git a/options.c b/options.c index 5c3441d..61d1633 100644 --- a/options.c +++ b/options.c @@ -440,7 +440,8 @@ parse_int(const char *optarg, char opt, int min, int max) } int -parse_colon_separated_list(const char *paths, struct vect *vec) +parse_colon_separated_list(const char *paths, struct vect *vec, + enum opt_F_origin origin) { /* PATHS contains a colon-separated list of directories and * files to load. It's modeled after shell PATH variable, @@ -467,6 +468,7 @@ parse_colon_separated_list(const char *paths, struct vect *vec) struct opt_F_t arg = { .pathname = tok, .own_pathname = tok == clone, + .origin = origin, }; if (VECT_PUSHBACK(vec, &arg) < 0) /* Presumably this is not a deal-breaker. */ @@ -494,8 +496,9 @@ opt_F_get_kind(struct opt_F_t *entry) if (entry->kind == OPT_F_UNKNOWN) { struct stat st; if (lstat(entry->pathname, &st) < 0) { - fprintf(stderr, "Couldn't stat %s: %s\n", - entry->pathname, strerror(errno)); + if (entry->origin == OPT_F_CMDLINE) + fprintf(stderr, "Couldn't stat %s: %s\n", + entry->pathname, strerror(errno)); entry->kind = OPT_F_BROKEN; } else if (S_ISDIR(st.st_mode)) { entry->kind = OPT_F_DIR; @@ -607,7 +610,8 @@ process_options(int argc, char **argv) options.follow = 1; break; case 'F': - parse_colon_separated_list(optarg, &opt_F); + parse_colon_separated_list(optarg, &opt_F, + OPT_F_CMDLINE); break; case 'h': usage(); diff --git a/options.h b/options.h index 38f4ecd..5138bcb 100644 --- a/options.h +++ b/options.h @@ -1,6 +1,6 @@ /* * This file is part of ltrace. - * Copyright (C) 2012,2013 Petr Machata, Red Hat Inc. + * Copyright (C) 2012,2013,2015 Petr Machata, Red Hat Inc. * Copyright (C) 2009,2010 Joe Damato * Copyright (C) 1998,2002,2008 Juan Cespedes * Copyright (C) 2006 Ian Wienand @@ -78,10 +78,16 @@ enum opt_F_kind { OPT_F_DIR, }; +enum opt_F_origin { + OPT_F_CMDLINE = 0, + OPT_F_ENVIRON, +}; + struct opt_F_t { char *pathname; int own_pathname : 1; enum opt_F_kind kind : 2; + enum opt_F_origin origin : 1; }; /* If entry->kind is OPT_F_UNKNOWN, figure out whether it should be @@ -99,7 +105,8 @@ void opt_F_destroy(struct opt_F_t *entry); * The list is split and added to VEC, which shall be a vector * initialized like VECT_INIT(VEC, struct opt_F_t); Returns 0 on * success or a negative value on failure. */ -int parse_colon_separated_list(const char *paths, struct vect *vec); +int parse_colon_separated_list(const char *paths, struct vect *vec, + enum opt_F_origin origin); /* Vector of struct opt_F_t. */ extern struct vect opt_F; diff --git a/sysdeps/linux-gnu/hooks.c b/sysdeps/linux-gnu/hooks.c index e9cb8d9..327fdf3 100644 --- a/sysdeps/linux-gnu/hooks.c +++ b/sysdeps/linux-gnu/hooks.c @@ -1,6 +1,6 @@ /* * This file is part of ltrace. - * Copyright (C) 2012, 2013 Petr Machata + * Copyright (C) 2012, 2013, 2015 Petr Machata * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -155,7 +155,7 @@ again: if (xdg_sys != NULL) { struct vect v; VECT_INIT(&v, struct opt_F_t); - if (parse_colon_separated_list(xdg_sys, &v) < 0 + if (parse_colon_separated_list(xdg_sys, &v, OPT_F_ENVIRON) < 0 || VECT_EACH(&v, struct opt_F_t, NULL, add_dir_component_cb, &dirs) != NULL) fprintf(stderr, diff --git a/testsuite/ltrace.main/XDG_CONFIG_DIRS.exp b/testsuite/ltrace.main/XDG_CONFIG_DIRS.exp new file mode 100644 index 0000000..fea2445 --- /dev/null +++ b/testsuite/ltrace.main/XDG_CONFIG_DIRS.exp @@ -0,0 +1,35 @@ +# This file is part of ltrace. +# Copyright (C) 2015 Petr Machata, Red Hat Inc. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +# 02110-1301 USA + +set bin [ltraceCompile {} [ltraceSource c { + int main() { return 0; } +}]] + +setenv XDG_CONFIG_DIRS "blah" +ltraceRun -L -- $bin +unsetenv XDG_CONFIG_DIRS + +if {[catch "exec $LTRACE -L -F blah -- $bin" output]} { + ltraceMatch [ltraceSource ltrace "$output"] { + {blah == 1} + } +} else { + fail "expected error message regarding `blah`" +} + +ltraceDone -- 2.1.0