Blame SOURCES/ltrace-0.7.91-XDG_CONFIG_DIRS.patch

263585
diff -rupN a/options.c b/options.c
263585
--- a/options.c	2019-06-28 17:15:31.515626363 -0400
263585
+++ b/options.c	2019-06-28 17:18:59.490632337 -0400
263585
@@ -440,7 +440,8 @@ parse_int(const char *optarg, char opt,
263585
 }
263585
 
263585
 int
263585
-parse_colon_separated_list(const char *paths, struct vect *vec)
263585
+parse_colon_separated_list(const char *paths, struct vect *vec,
263585
+			   enum opt_F_origin origin)
263585
 {
263585
 	/* PATHS contains a colon-separated list of directories and
263585
 	 * files to load.  It's modeled after shell PATH variable,
263585
@@ -467,6 +468,7 @@ parse_colon_separated_list(const char *p
263585
 		struct opt_F_t arg = {
263585
 			.pathname = tok,
263585
 			.own_pathname = tok == clone,
263585
+			.origin = origin,
263585
 		};
263585
 		if (VECT_PUSHBACK(vec, &arg) < 0)
263585
 			/* Presumably this is not a deal-breaker.  */
263585
@@ -494,16 +496,18 @@ opt_F_get_kind(struct opt_F_t *entry)
263585
 	if (entry->kind == OPT_F_UNKNOWN) {
263585
 		struct stat st;
263585
 		if (lstat(entry->pathname, &st) < 0) {
263585
-			fprintf(stderr, "Couldn't stat %s: %s\n",
263585
-				entry->pathname, strerror(errno));
263585
+			if (entry->origin == OPT_F_CMDLINE)
263585
+				fprintf(stderr, "Couldn't stat %s: %s\n",
263585
+					entry->pathname, strerror(errno));
263585
 			entry->kind = OPT_F_BROKEN;
263585
 		} else if (S_ISDIR(st.st_mode)) {
263585
 			entry->kind = OPT_F_DIR;
263585
 		} else if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) {
263585
 			entry->kind = OPT_F_FILE;
263585
 		} else {
263585
-			fprintf(stderr, "%s is neither a regular file, "
263585
-				"nor a directory.\n", entry->pathname);
263585
+			if (entry->origin == OPT_F_CMDLINE)
263585
+				fprintf(stderr, "%s is neither a regular file, "
263585
+					"nor a directory.\n", entry->pathname);
263585
 			entry->kind = OPT_F_BROKEN;
263585
 		}
263585
 	}
263585
@@ -607,7 +611,8 @@ process_options(int argc, char **argv)
263585
 			options.follow = 1;
263585
 			break;
263585
 		case 'F':
263585
-			parse_colon_separated_list(optarg, &opt_F);
263585
+			parse_colon_separated_list(optarg, &opt_F,
263585
+						   OPT_F_CMDLINE);
263585
 			break;
263585
 		case 'h':
263585
 			usage();
263585
diff -rupN a/options.h b/options.h
263585
--- a/options.h	2019-06-28 17:15:31.515626363 -0400
263585
+++ b/options.h	2019-06-28 17:18:55.984632238 -0400
263585
@@ -1,6 +1,6 @@
263585
 /*
263585
  * This file is part of ltrace.
263585
- * Copyright (C) 2012,2013 Petr Machata, Red Hat Inc.
263585
+ * Copyright (C) 2012, 2013, 2015 Petr Machata, Red Hat Inc.
263585
  * Copyright (C) 2009,2010 Joe Damato
263585
  * Copyright (C) 1998,2002,2008 Juan Cespedes
263585
  * Copyright (C) 2006 Ian Wienand
263585
@@ -77,10 +77,16 @@ enum opt_F_kind {
263585
 	OPT_F_DIR,
263585
 };
263585
 
263585
+enum opt_F_origin {
263585
+	OPT_F_CMDLINE = 0,
263585
+	OPT_F_ENVIRON,
263585
+};
263585
+
263585
 struct opt_F_t {
263585
 	char *pathname;
263585
 	int own_pathname : 1;
263585
 	enum opt_F_kind kind : 2;
263585
+	enum opt_F_origin origin : 1;
263585
 };
263585
 
263585
 /* If entry->kind is OPT_F_UNKNOWN, figure out whether it should be
263585
@@ -98,7 +104,8 @@ void opt_F_destroy(struct opt_F_t *entry
263585
  * The list is split and added to VEC, which shall be a vector
263585
  * initialized like VECT_INIT(VEC, struct opt_F_t); Returns 0 on
263585
  * success or a negative value on failure.  */
263585
-int parse_colon_separated_list(const char *paths, struct vect *vec);
263585
+int parse_colon_separated_list(const char *paths, struct vect *vec,
263585
+			       enum opt_F_origin origin);
263585
 
263585
 /* Vector of struct opt_F_t.  */
263585
 extern struct vect opt_F;
263585
diff -rupN a/sysdeps/linux-gnu/hooks.c b/sysdeps/linux-gnu/hooks.c
263585
--- a/sysdeps/linux-gnu/hooks.c	2013-11-04 20:08:03.000000000 -0500
263585
+++ b/sysdeps/linux-gnu/hooks.c	2019-06-28 17:18:55.989632238 -0400
263585
@@ -1,6 +1,6 @@
263585
 /*
263585
  * This file is part of ltrace.
263585
- * Copyright (C) 2012, 2013 Petr Machata
263585
+ * Copyright (C) 2012, 2013, 2015 Petr Machata
263585
  *
263585
  * This program is free software; you can redistribute it and/or
263585
  * modify it under the terms of the GNU General Public License as
263585
@@ -153,7 +153,7 @@ again:
263585
 	if (xdg_sys != NULL) {
263585
 		struct vect v;
263585
 		VECT_INIT(&v, struct opt_F_t);
263585
-		if (parse_colon_separated_list(xdg_sys, &v) < 0
263585
+		if (parse_colon_separated_list(xdg_sys, &v, OPT_F_ENVIRON) < 0
263585
 		    || VECT_EACH(&v, struct opt_F_t, NULL,
263585
 				 add_dir_component_cb, &dirs) != NULL)
263585
 			fprintf(stderr,
263585
diff -rupN a/testsuite/ltrace.main/XDG_CONFIG_DIRS.exp b/testsuite/ltrace.main/XDG_CONFIG_DIRS.exp
263585
--- a/testsuite/ltrace.main/XDG_CONFIG_DIRS.exp	1969-12-31 19:00:00.000000000 -0500
263585
+++ b/testsuite/ltrace.main/XDG_CONFIG_DIRS.exp	2019-06-28 17:18:55.989632238 -0400
263585
@@ -0,0 +1,35 @@
263585
+# This file is part of ltrace.
263585
+# Copyright (C) 2015 Petr Machata, Red Hat Inc.
263585
+#
263585
+# This program is free software; you can redistribute it and/or
263585
+# modify it under the terms of the GNU General Public License as
263585
+# published by the Free Software Foundation; either version 2 of the
263585
+# License, or (at your option) any later version.
263585
+#
263585
+# This program is distributed in the hope that it will be useful, but
263585
+# WITHOUT ANY WARRANTY; without even the implied warranty of
263585
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
263585
+# General Public License for more details.
263585
+#
263585
+# You should have received a copy of the GNU General Public License
263585
+# along with this program; if not, write to the Free Software
263585
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
263585
+# 02110-1301 USA
263585
+
263585
+set bin [ltraceCompile {} [ltraceSource c {
263585
+    int main() { return 0; }
263585
+}]]
263585
+
263585
+setenv XDG_CONFIG_DIRS "blah"
263585
+ltraceRun -L -- $bin
263585
+unsetenv XDG_CONFIG_DIRS
263585
+
263585
+if {[catch "exec $LTRACE -L -F blah -- $bin" output]} {
263585
+    ltraceMatch [ltraceSource ltrace "$output"] {
263585
+	{blah == 1}
263585
+    }
263585
+} else {
263585
+    fail "expected error message regarding `blah`"
263585
+}
263585
+
263585
+ltraceDone