1 This file is suspend.def, from which is created suspend.c.
2 It implements the builtin "suspend" in Bash.
4 Copyright (C) 1987-2009 Free Software Foundation, Inc.
6 This file is part of GNU Bash, the Bourne Again SHell.
8 Bash 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 Bash 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 Bash. If not, see <http://www.gnu.org/licenses/>.
24 $DEPENDS_ON JOB_CONTROL
25 $FUNCTION suspend_builtin
26 $SHORT_DOC suspend [-f]
27 Suspend shell execution.
29 Suspend the execution of this shell until it receives a SIGCONT signal.
30 Unless forced, login shells cannot be suspended.
33 -f force the suspend, even if the shell is a login shell
36 Returns success unless job control is not enabled or an error occurs.
41 #if defined (JOB_CONTROL)
42 #if defined (HAVE_UNISTD_H)
44 # include <sys/types.h>
49 #include "../bashtypes.h"
51 #include "../bashintl.h"
55 #include "bashgetopt.h"
57 static sighandler suspend_continue __P((int));
59 static SigHandler *old_cont;
61 static SigHandler *old_stop;
64 /* Continue handler. */
66 suspend_continue (sig)
69 set_signal_handler (SIGCONT, old_cont);
71 set_signal_handler (SIGSTOP, old_stop);
76 /* Suspending the shell. If -f is the arg, then do the suspend
77 no matter what. Otherwise, complain if a login shell. */
79 suspend_builtin (list)
84 reset_internal_getopt ();
86 while ((opt = internal_getopt (list, "f")) != -1)
101 sh_nojobs (_("cannot suspend"));
102 return (EXECUTION_FAILURE);
111 builtin_error (_("cannot suspend a login shell"));
112 return (EXECUTION_FAILURE);
116 /* XXX - should we put ourselves back into the original pgrp now? If so,
117 call end_job_control() here and do the right thing in suspend_continue
118 (that is, call restart_job_control()). */
119 old_cont = (SigHandler *)set_signal_handler (SIGCONT, suspend_continue);
121 old_stop = (SigHandler *)set_signal_handler (SIGSTOP, SIG_DFL);
123 killpg (shell_pgrp, SIGSTOP);
124 return (EXECUTION_SUCCESS);
127 #endif /* JOB_CONTROL */