Correct shell compatibility issue detected with pkgsrc.
[deliverable/binutils-gdb.git] / gdb / gdbserver / fork-child.c
CommitLineData
2090129c
SDJ
1/* Fork a Unix child process, and set up to debug it, for GDBserver.
2 Copyright (C) 1989-2017 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18
19#include "server.h"
20#include "job-control.h"
21#include "nat/fork-inferior.h"
9845682b
SDJ
22#ifdef HAVE_SIGNAL_H
23#include <signal.h>
24#endif
2090129c
SDJ
25
26#ifdef SIGTTOU
27/* A file descriptor for the controlling terminal. */
28static int terminal_fd;
29
30/* TERMINAL_FD's original foreground group. */
31static pid_t old_foreground_pgrp;
32
33/* Hand back terminal ownership to the original foreground group. */
34
35static void
36restore_old_foreground_pgrp (void)
37{
38 tcsetpgrp (terminal_fd, old_foreground_pgrp);
39}
40#endif
41
42/* See nat/fork-inferior.h. */
43
44void
45prefork_hook (const char *args)
46{
47 if (debug_threads)
48 {
49 debug_printf ("args: %s\n", args);
50 debug_flush ();
51 }
52
53#ifdef SIGTTOU
54 signal (SIGTTOU, SIG_DFL);
55 signal (SIGTTIN, SIG_DFL);
56#endif
57
58 /* Clear this so the backend doesn't get confused, thinking
59 CONT_THREAD died, and it needs to resume all threads. */
60 cont_thread = null_ptid;
61}
62
63/* See nat/fork-inferior.h. */
64
65void
66postfork_hook (pid_t pid)
67{
68}
69
70/* See nat/fork-inferior.h. */
71
72void
73postfork_child_hook ()
74{
75 /* This is set to the result of setpgrp, which if vforked, will be
76 visible to you in the parent process. It's only used by humans
77 for debugging. */
78 static int debug_setpgrp = 657473;
79
80 debug_setpgrp = gdb_setpgid ();
81 if (debug_setpgrp == -1)
82 perror (_("setpgrp failed in child"));
83}
84
85/* See nat/fork-inferior.h. */
86
87void
88gdb_flush_out_err ()
89{
90 fflush (stdout);
91 fflush (stderr);
92}
93
94/* See server.h. */
95
96void
97post_fork_inferior (int pid, const char *program)
98{
99#ifdef SIGTTOU
100 signal (SIGTTOU, SIG_IGN);
101 signal (SIGTTIN, SIG_IGN);
102 terminal_fd = fileno (stderr);
103 old_foreground_pgrp = tcgetpgrp (terminal_fd);
104 tcsetpgrp (terminal_fd, pid);
105 atexit (restore_old_foreground_pgrp);
106#endif
107
108 startup_inferior (pid, START_INFERIOR_TRAPS_EXPECTED,
109 &last_status, &last_ptid);
110 current_thread->last_resume_kind = resume_stop;
111 current_thread->last_status = last_status;
112 signal_pid = pid;
113 target_post_create_inferior ();
114 fprintf (stderr, "Process %s created; pid = %d\n", program, pid);
115 fflush (stderr);
116}
This page took 0.045004 seconds and 4 git commands to generate.