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

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