Blame SOURCES/ltrace-0.7.91-XDG_CONFIG_DIRS.patch

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