(source_command): Update documentation. Check permissions if
FROM_TTY is -1.
-Index: gdb-6.8.50.20090226/gdb/cli/cli-cmds.c
+Index: gdb-7.1.90.20100720/gdb/cli/cli-cmds.c
===================================================================
---- gdb-6.8.50.20090226.orig/gdb/cli/cli-cmds.c 2009-02-27 00:04:32.000000000 +0100
-+++ gdb-6.8.50.20090226/gdb/cli/cli-cmds.c 2009-02-28 07:17:49.000000000 +0100
-@@ -36,6 +36,7 @@
- #include "objfiles.h"
+--- gdb-7.1.90.20100720.orig/gdb/cli/cli-cmds.c 2010-05-17 21:28:12.000000000 +0200
++++ gdb-7.1.90.20100720/gdb/cli/cli-cmds.c 2010-07-21 20:30:30.000000000 +0200
+@@ -39,6 +39,7 @@
#include "source.h"
#include "disasm.h"
+ #include "tracepoint.h"
+#include "gdb_stat.h"
#include "ui-out.h"
-@@ -466,7 +467,7 @@ source_script (char *file, int from_tty)
+@@ -487,7 +488,7 @@ Script filename extension recognition is
- if (fd == -1)
- {
-- if (from_tty)
-+ if (from_tty > 0)
- perror_with_name (file);
- else
- {
-@@ -475,6 +476,29 @@ source_script (char *file, int from_tty)
- }
+ int
+ find_and_open_script (const char *script_file, int search_path,
+- FILE **streamp, char **full_pathp)
++ FILE **streamp, char **full_pathp, int from_tty)
+ {
+ char *file;
+ int fd;
+@@ -513,6 +514,32 @@ find_and_open_script (const char *script
+ return 0;
}
+#ifdef HAVE_GETUID
+
+ if (fstat (fd, &statbuf) < 0)
+ {
++ int save_errno = errno;
++
+ close (fd);
-+ /* Do not do_cleanups (old_cleanups) as FILE is allocated there.
-+ perror_with_name calls error which should call the cleanups. */
-+ perror_with_name (file);
++ do_cleanups (old_cleanups);
++ errno = save_errno;
++ return 0;
+ }
+ if (statbuf.st_uid != getuid () || (statbuf.st_mode & S_IWOTH))
+ {
+ warning (_("not using untrusted file \"%s\""), file);
+ close (fd);
+ do_cleanups (old_cleanups);
-+ return;
++ errno = EPERM;
++ return 0;
+ }
+ }
+#endif
+
- is_python = source_python;
- if (strlen (file) > 3 && !strcmp (&file[strlen (file) - 3], ".py"))
- is_python = 1;
-@@ -486,6 +510,7 @@ source_script (char *file, int from_tty)
- else
- script_from_file (stream, file);
-
-+ /* FILE gets freed by do_cleanups (old_cleanups). */
do_cleanups (old_cleanups);
- }
-Index: gdb-6.8.50.20090226/gdb/testsuite/gdb.base/gdbinit.exp
+ *streamp = fdopen (fd, FOPEN_RT);
+@@ -572,13 +599,14 @@ source_script_with_search (const char *f
+ if (file == NULL || *file == 0)
+ error (_("source command requires file name of file to source."));
+
+- if (!find_and_open_script (file, search_path, &stream, &full_path))
++ if (!find_and_open_script (file, search_path, &stream, &full_path,
++ from_tty))
+ {
+ /* The script wasn't found, or was otherwise inaccessible.
+ If the source command was invoked interactively, throw an error.
+ Otherwise (e.g. if it was invoked by a script), silently ignore
+ the error. */
+- if (from_tty)
++ if (from_tty > 0)
+ perror_with_name (file);
+ else
+ return;
+Index: gdb-7.1.90.20100720/gdb/testsuite/gdb.base/gdbinit.exp
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
-+++ gdb-6.8.50.20090226/gdb/testsuite/gdb.base/gdbinit.exp 2009-02-28 07:15:57.000000000 +0100
-@@ -0,0 +1,98 @@
++++ gdb-7.1.90.20100720/gdb/testsuite/gdb.base/gdbinit.exp 2010-07-20 22:25:40.000000000 +0200
+@@ -0,0 +1,91 @@
+# Copyright 2005
+# Free Software Foundation, Inc.
+
+
+# This file was written by Jeff Johnston <jjohnstn@redhat.com>.
+
-+if $tracelevel then {
-+ strace $tracelevel
-+}
-+
-+set prms_id 0
-+set bug_id 0
-+
+# are we on a target board
+if [is_remote target] {
+ return
+}
+
+remote_exec build "rm .gdbinit"
-Index: gdb-6.8.50.20090226/gdb/testsuite/gdb.base/gdbinit.sample
+Index: gdb-7.1.90.20100720/gdb/testsuite/gdb.base/gdbinit.sample
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
-+++ gdb-6.8.50.20090226/gdb/testsuite/gdb.base/gdbinit.sample 2009-02-28 07:15:57.000000000 +0100
++++ gdb-7.1.90.20100720/gdb/testsuite/gdb.base/gdbinit.sample 2010-07-20 22:25:40.000000000 +0200
@@ -0,0 +1 @@
+echo "\nin gdbinit"
-Index: gdb-6.8.50.20090226/gdb/main.c
+Index: gdb-7.1.90.20100720/gdb/main.c
===================================================================
---- gdb-6.8.50.20090226.orig/gdb/main.c 2009-02-27 00:04:32.000000000 +0100
-+++ gdb-6.8.50.20090226/gdb/main.c 2009-02-28 07:15:57.000000000 +0100
-@@ -855,7 +855,7 @@ Excess command line arguments ignored. (
+--- gdb-7.1.90.20100720.orig/gdb/main.c 2010-06-26 08:44:47.000000000 +0200
++++ gdb-7.1.90.20100720/gdb/main.c 2010-07-21 20:09:03.000000000 +0200
+@@ -794,7 +794,7 @@ Excess command line arguments ignored. (
debugging or what directory you are in. */
if (home_gdbinit && !inhibit_gdbinit)
/* Now perform all the actions indicated by the arguments. */
if (cdarg != NULL)
-@@ -924,7 +924,7 @@ Can't attach to process and specify a co
+@@ -868,7 +868,7 @@ Can't attach to process and specify a co
/* Read the .gdbinit file in the current directory, *if* it isn't
the same as the $HOME/.gdbinit file (it should exist, also). */
if (local_gdbinit && !inhibit_gdbinit)
- catch_command_errors (source_script, local_gdbinit, 0, RETURN_MASK_ALL);
+ catch_command_errors (source_script, local_gdbinit, -1, RETURN_MASK_ALL);
- for (i = 0; i < ncmd; i++)
- {
+ /* Now that all .gdbinit's have been read and all -d options have been
+ processed, we can read any scripts mentioned in SYMARG.
+Index: gdb-7.1.90.20100720/gdb/python/py-auto-load.c
+===================================================================
+--- gdb-7.1.90.20100720.orig/gdb/python/py-auto-load.c 2010-05-17 23:23:25.000000000 +0200
++++ gdb-7.1.90.20100720/gdb/python/py-auto-load.c 2010-07-20 22:25:40.000000000 +0200
+@@ -219,7 +219,7 @@ source_section_scripts (struct objfile *
+ }
+
+ opened = find_and_open_script (file, 1 /*search_path*/,
+- &stream, &full_path);
++ &stream, &full_path, 1 /* from_tty */);
+
+ /* If the file is not found, we still record the file in the hash table,
+ we only want to print an error message once.
+Index: gdb-7.1.90.20100720/gdb/cli/cli-cmds.h
+===================================================================
+--- gdb-7.1.90.20100720.orig/gdb/cli/cli-cmds.h 2010-05-03 01:52:14.000000000 +0200
++++ gdb-7.1.90.20100720/gdb/cli/cli-cmds.h 2010-07-20 22:25:40.000000000 +0200
+@@ -126,7 +126,8 @@ extern void source_script (char *, int);
+ /* Exported to objfiles.c. */
+
+ extern int find_and_open_script (const char *file, int search_path,
+- FILE **streamp, char **full_path);
++ FILE **streamp, char **full_path,
++ int from_tty);
+
+ /* Command tracing state. */
+