Imported from ../bash-1.14.7.tar.gz.
[platform/upstream/bash.git] / builtins / suspend.def
1 This file is suspend.def, from which is created suspend.c.
2 It implements the builtin "suspend" in Bash.
3
4 Copyright (C) 1987, 1989, 1991 Free Software Foundation, Inc.
5
6 This file is part of GNU Bash, the Bourne Again SHell.
7
8 Bash is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 1, or (at your option) any later
11 version.
12
13 Bash is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with Bash; see the file COPYING.  If not, write to the Free Software
20 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21
22 $PRODUCES suspend.c
23
24 $BUILTIN suspend
25 $DEPENDS_ON JOB_CONTROL
26 $FUNCTION suspend_builtin
27 $SHORT_DOC suspend [-f]
28 Suspend the execution of this shell until it receives a SIGCONT
29 signal.  The `-f' if specified says not to complain about this
30 being a login shell if it is; just suspend anyway.
31 $END
32
33 #include <sys/types.h>
34 #include <signal.h>
35 #include "../shell.h"
36 #include "../jobs.h"
37
38 #if defined (JOB_CONTROL)
39 extern int job_control;
40
41 static SigHandler *old_cont, *old_tstp;
42
43 /* Continue handler. */
44 sighandler
45 suspend_continue (sig)
46      int sig;
47 {
48   set_signal_handler (SIGCONT, old_cont);
49   set_signal_handler (SIGTSTP, old_tstp);
50 #if !defined (VOID_SIGHANDLER)
51   return (0);
52 #endif /* !VOID_SIGHANDLER */
53 }
54
55 /* Suspending the shell.  If -f is the arg, then do the suspend
56    no matter what.  Otherwise, complain if a login shell. */
57 int
58 suspend_builtin (list)
59      WORD_LIST *list;
60 {
61   if (!job_control)
62     {
63       builtin_error ("Cannot suspend a shell without job control");
64       return (EXECUTION_FAILURE);
65     }
66
67   if (list)
68     if (strcmp (list->word->word, "-f") == 0)
69       goto do_suspend;
70
71   no_args (list);
72
73   if (login_shell)
74     {
75       builtin_error ("Can't suspend a login shell");
76       return (EXECUTION_FAILURE);
77     }
78
79 do_suspend:
80   old_cont = (SigHandler *)set_signal_handler (SIGCONT, suspend_continue);
81   old_tstp = (SigHandler *)set_signal_handler (SIGTSTP, SIG_DFL);
82   killpg (shell_pgrp, SIGTSTP);
83   return (EXECUTION_SUCCESS);
84 }
85
86 #endif /* JOB_CONTROL */