Blame SOURCES/ltrace-0.7.91-XDG_CONFIG_DIRS.patch

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