Commit | Line | Data |
---|---|---|
15652511 SDJ |
1 | /* Job control and terminal related functions, for GDB and gdbserver |
2 | when running under Unix. | |
3 | ||
4 | Copyright (C) 1986-2017 Free Software Foundation, Inc. | |
5 | ||
6 | This file is part of GDB. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 3 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
20 | ||
21 | #include "common-defs.h" | |
22 | #include "job-control.h" | |
23 | #include "gdb_termios.h" | |
24 | ||
25 | /* Nonzero if we have job control. */ | |
26 | int job_control; | |
27 | ||
28 | /* Set the process group ID of the inferior. | |
29 | ||
30 | Just using job_control only does part of it because setpgid or | |
31 | setpgrp might not exist on a system without job control. | |
32 | ||
33 | For a more clean implementation, in libiberty, put a setpgid which merely | |
34 | calls setpgrp and a setpgrp which does nothing (any system with job control | |
35 | will have one or the other). */ | |
36 | ||
37 | int | |
38 | gdb_setpgid () | |
39 | { | |
40 | int retval = 0; | |
41 | ||
42 | if (job_control) | |
43 | { | |
44 | #if defined (HAVE_TERMIOS) || defined (TIOCGPGRP) | |
45 | #ifdef HAVE_SETPGID | |
46 | /* The call setpgid (0, 0) is supposed to work and mean the same | |
47 | thing as this, but on Ultrix 4.2A it fails with EPERM (and | |
48 | setpgid (getpid (), getpid ()) succeeds). */ | |
49 | retval = setpgid (getpid (), getpid ()); | |
50 | #else | |
51 | #ifdef HAVE_SETPGRP | |
52 | #ifdef SETPGRP_VOID | |
53 | retval = setpgrp (); | |
54 | #else | |
55 | retval = setpgrp (getpid (), getpid ()); | |
56 | #endif | |
57 | #endif /* HAVE_SETPGRP */ | |
58 | #endif /* HAVE_SETPGID */ | |
59 | #endif /* defined (HAVE_TERMIOS) || defined (TIOCGPGRP) */ | |
60 | } | |
61 | ||
62 | return retval; | |
63 | } | |
64 | ||
65 | /* See common/common-terminal.h. */ | |
66 | ||
67 | void | |
68 | have_job_control () | |
69 | { | |
70 | /* OK, figure out whether we have job control. If neither termios nor | |
71 | sgtty (i.e. termio or go32), leave job_control 0. */ | |
72 | #if defined (HAVE_TERMIOS) | |
73 | /* Do all systems with termios have the POSIX way of identifying job | |
74 | control? I hope so. */ | |
75 | #ifdef _POSIX_JOB_CONTROL | |
76 | job_control = 1; | |
77 | #else | |
78 | #ifdef _SC_JOB_CONTROL | |
79 | job_control = sysconf (_SC_JOB_CONTROL); | |
80 | #else | |
81 | job_control = 0; /* Have to assume the worst. */ | |
82 | #endif /* _SC_JOB_CONTROL */ | |
83 | #endif /* _POSIX_JOB_CONTROL */ | |
84 | #endif /* HAVE_TERMIOS */ | |
85 | ||
86 | #ifdef HAVE_SGTTY | |
87 | #ifdef TIOCGPGRP | |
88 | job_control = 1; | |
89 | #else | |
90 | job_control = 0; | |
91 | #endif /* TIOCGPGRP */ | |
92 | #endif /* sgtty */ | |
93 | } |