Blame SOURCES/gdb-6.6-bz229517-gcore-without-terminal.patch

0a406a
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
0a406a
From: Jan Kratochvil <jan.kratochvil@redhat.com>
0a406a
Date: Fri, 27 Oct 2017 21:07:50 +0200
0a406a
Subject: gdb-6.6-bz229517-gcore-without-terminal.patch
0a406a
0a406a
;; Allow running `/usr/bin/gcore' with provided but inaccessible tty (BZ 229517).
0a406a
;;=fedoratest
0a406a
0a406a
2007-04-22  Jan Kratochvil <jan.kratochvil@redhat.com>
0a406a
0a406a
	* gdb_gcore.sh: Redirect GDB from `
0a406a
0a406a
2007-04-22  Jan Kratochvil <jan.kratochvil@redhat.com>
0a406a
0a406a
	* gdb.base/gcorebg.exp, gdb.base/gcorebg.c: New files.
0a406a
0a406a
diff --git a/gdb/testsuite/gdb.base/gcorebg.c b/gdb/testsuite/gdb.base/gcorebg.c
0a406a
new file mode 100644
0a406a
--- /dev/null
0a406a
+++ b/gdb/testsuite/gdb.base/gcorebg.c
0a406a
@@ -0,0 +1,49 @@
0a406a
+#include <stdio.h>
0a406a
+#include <sys/types.h>
0a406a
+#include <unistd.h>
0a406a
+#include <stdlib.h>
0a406a
+#include <signal.h>
0a406a
+#include <string.h>
0a406a
+#include <assert.h>
0a406a
+
0a406a
+int main (int argc, char **argv)
0a406a
+{
0a406a
+  pid_t pid = 0;
0a406a
+  pid_t ppid;
0a406a
+  char buf[1024*2 + 500];
0a406a
+  int gotint;
0a406a
+
0a406a
+  if (argc != 4)
0a406a
+    {
0a406a
+      fprintf (stderr, "Syntax: %s {standard|detached} <gcore command> <core output file>\n",
0a406a
+	       argv[0]);
0a406a
+      exit (1);
0a406a
+    }
0a406a
+
0a406a
+  pid = fork ();
0a406a
+
0a406a
+  switch (pid)
0a406a
+    {
0a406a
+      case 0:
0a406a
+        if (strcmp (argv[1], "detached") == 0)
0a406a
+	  setpgrp ();
0a406a
+	ppid = getppid ();
0a406a
+	gotint = snprintf (buf, sizeof (buf), "sh %s -o %s %d", argv[2], argv[3], (int) ppid);
0a406a
+	assert (gotint < sizeof (buf));
0a406a
+	system (buf);
0a406a
+	fprintf (stderr, "Killing parent PID %d\n", ppid);
0a406a
+	kill (ppid, SIGTERM);
0a406a
+	break;
0a406a
+
0a406a
+      case -1:
0a406a
+	perror ("fork err\n");
0a406a
+	exit (1);
0a406a
+	break;
0a406a
+
0a406a
+      default:
0a406a
+	fprintf (stderr,"Sleeping as PID %d\n", getpid ());
0a406a
+	sleep (60);
0a406a
+    }
0a406a
+
0a406a
+  return 0;
0a406a
+}
0a406a
diff --git a/gdb/testsuite/gdb.base/gcorebg.exp b/gdb/testsuite/gdb.base/gcorebg.exp
0a406a
new file mode 100644
0a406a
--- /dev/null
0a406a
+++ b/gdb/testsuite/gdb.base/gcorebg.exp
0a406a
@@ -0,0 +1,113 @@
0a406a
+# Copyright 2007 Free Software Foundation, Inc.
0a406a
+
0a406a
+# This program is free software; you can redistribute it and/or modify
0a406a
+# it under the terms of the GNU General Public License as published by
0a406a
+# the Free Software Foundation; either version 2 of the License, or
0a406a
+# (at your option) any later version.
0a406a
+#
0a406a
+# This program is distributed in the hope that it will be useful,
0a406a
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
0a406a
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0a406a
+# GNU General Public License for more details.
0a406a
+#
0a406a
+# You should have received a copy of the GNU General Public License
0a406a
+# along with this program; if not, write to the Free Software
0a406a
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
0a406a
+
0a406a
+# Please email any bugs, comments, and/or additions to this file to:
0a406a
+# bug-gdb@prep.ai.mit.edu
0a406a
+
0a406a
+# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
0a406a
+# This is a test for `gdb_gcore.sh' functionality.
0a406a
+# It also tests a regression with `gdb_gcore.sh' being run without its
0a406a
+# accessible terminal.
0a406a
+
0a406a
+if ![info exists GCORE] {
0a406a
+    set GCORE "[standard_output_file ../../../../gcore]"
0a406a
+}
0a406a
+verbose "using GCORE = $GCORE" 2
0a406a
+
0a406a
+set testfile "gcorebg"
0a406a
+set srcfile  ${testfile}.c
0a406a
+set binfile  [standard_output_file ${testfile}]
0a406a
+set corefile [standard_output_file ${testfile}.test]
0a406a
+
0a406a
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
0a406a
+     untested gcorebg.exp
0a406a
+     return -1
0a406a
+}
0a406a
+
0a406a
+# Cleanup.
0a406a
+
0a406a
+proc core_clean {} {
0a406a
+    global corefile
0a406a
+
0a406a
+    foreach file [glob -nocomplain [join [list $corefile *] ""]] {
0a406a
+	verbose "Delete file $file" 1
0a406a
+	remote_file target delete $file
0a406a
+    }
0a406a
+}
0a406a
+core_clean
0a406a
+remote_file target delete "./gdb"
0a406a
+
0a406a
+# Generate the core file.
0a406a
+
0a406a
+# Provide `./gdb' for `gdb_gcore.sh' running it as a bare `gdb' command.
0a406a
+# Setup also `$PATH' appropriately.
0a406a
+# If GDB was not found let `gdb_gcore.sh' to find the system GDB by `$PATH'.
0a406a
+if {$GDB != "gdb"} {
0a406a
+    file link ./gdb $GDB
0a406a
+}
0a406a
+global env
0a406a
+set oldpath $env(PATH)
0a406a
+set env(PATH) [join [list . $env(PATH)] ":"]
0a406a
+verbose "PATH = $env(PATH)" 2
0a406a
+
0a406a
+# Test file body.
0a406a
+# $detached == "standard" || $detached == "detached"
0a406a
+
0a406a
+proc test_body { detached } {
0a406a
+    global binfile
0a406a
+    global GCORE
0a406a
+    global corefile
0a406a
+
0a406a
+    set res [remote_spawn target "$binfile $detached $GCORE $corefile"]
0a406a
+    if { $res < 0 || $res == "" } {
0a406a
+	fail "Spawning $detached gcore"
0a406a
+	return 1
0a406a
+    }
0a406a
+    pass "Spawning $detached gcore"
0a406a
+    remote_expect target 20 {
0a406a
+	timeout {
0a406a
+	    fail "Spawned $detached gcore finished (timeout)"
0a406a
+	    remote_exec target "kill -9 -[exp_pid -i $res]"
0a406a
+	    return 1
0a406a
+	}
0a406a
+	"Saved corefile .*\r\nKilling parent PID " {
0a406a
+	    pass "Spawned $detached gcore finished"
0a406a
+	    remote_wait target 20
0a406a
+	}
0a406a
+    }
0a406a
+
0a406a
+    if {1 == [llength [glob -nocomplain [join [list $corefile *] ""]]]} {
0a406a
+	pass "Core file generated by $detached gcore"
0a406a
+    } else {
0a406a
+	fail "Core file generated by $detached gcore"
0a406a
+    }
0a406a
+    core_clean
0a406a
+}
0a406a
+
0a406a
+# First a general `gdb_gcore.sh' spawn with its controlling terminal available.
0a406a
+
0a406a
+test_body standard
0a406a
+
0a406a
+# And now `gdb_gcore.sh' spawn without its controlling terminal available.
0a406a
+# It is spawned through `gcorebg.c' using setpgrp ().
0a406a
+
0a406a
+test_body detached
0a406a
+
0a406a
+
0a406a
+# Cleanup.
0a406a
+
0a406a
+set env(PATH) $oldpath
0a406a
+remote_file target delete "./gdb"