Blame SOURCES/ltrace-0.7.91-XDG_CONFIG_DIRS.patch

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