Blame SOURCES/ltrace-0.7.91-XDG_CONFIG_DIRS.patch

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