arm: Support pac_key_* register operand for MRS/MSR in Armv8.1-M Mainline
[binutils-gdb.git] / gdbsupport / job-control.cc
blobeff196dfdc85b15a813cebc0dfdf243e08f87f06
1 /* Job control and terminal related functions, for GDB and gdbserver
2 when running under Unix.
4 Copyright (C) 1986-2024 Free Software Foundation, Inc.
6 This file is part of GDB.
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.
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.
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/>. */
21 #include "job-control.h"
22 #ifdef HAVE_TERMIOS_H
23 #include <termios.h>
24 #endif
25 #include <unistd.h>
27 /* Nonzero if we have job control. */
28 int job_control;
30 /* Set the process group ID of the inferior.
32 Just using job_control only does part of it because setpgid or
33 setpgrp might not exist on a system without job control.
35 For a more clean implementation, in libiberty, put a setpgid which merely
36 calls setpgrp and a setpgrp which does nothing (any system with job control
37 will have one or the other). */
39 int
40 gdb_setpgid ()
42 int retval = 0;
44 if (job_control)
46 #ifdef HAVE_SETPGID
47 /* The call setpgid (0, 0) is supposed to work and mean the same
48 thing as this, but on Ultrix 4.2A it fails with EPERM (and
49 setpgid (getpid (), getpid ()) succeeds). */
50 retval = setpgid (getpid (), getpid ());
51 #else
52 #ifdef HAVE_SETPGRP
53 #ifdef SETPGRP_VOID
54 retval = setpgrp ();
55 #else
56 retval = setpgrp (getpid (), getpid ());
57 #endif
58 #endif /* HAVE_SETPGRP */
59 #endif /* HAVE_SETPGID */
62 return retval;
65 /* See gdbsupport/common-terminal.h. */
67 void
68 have_job_control ()
70 /* OK, figure out whether we have job control. If termios is not
71 available, leave job_control 0. */
72 #if defined (HAVE_TERMIOS_H)
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_H */