Blame SOURCES/ltrace-0.7.91-XDG_CONFIG_DIRS.patch

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