151c34dbae1ccc7229160b298939d0e9ed973129
[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 <config.h>
34
35 #if defined (JOB_CONTROL)
36 #if defined (HAVE_UNISTD_H)
37 #  include <unistd.h>
38 #endif
39
40 #include "../bashtypes.h"
41 #include <signal.h>
42 #include "../shell.h"
43 #include "../jobs.h"
44 #include "common.h"
45 #include "bashgetopt.h"
46
47 extern int job_control;
48
49 static SigHandler *old_cont, *old_stop;
50
51 /* Continue handler. */
52 sighandler
53 suspend_continue (sig)
54      int sig;
55 {
56   set_signal_handler (SIGCONT, old_cont);
57 #if 0
58   set_signal_handler (SIGSTOP, old_stop);
59 #endif
60   SIGRETURN (0);
61 }
62
63 /* Suspending the shell.  If -f is the arg, then do the suspend
64    no matter what.  Otherwise, complain if a login shell. */
65 int
66 suspend_builtin (list)
67      WORD_LIST *list;
68 {
69   int opt, force;
70
71   reset_internal_getopt ();
72   force = 0;
73   while ((opt = internal_getopt (list, "f")) != -1)
74     switch (opt)
75       {
76       case 'f':
77         force++;
78         break;
79       default:
80         builtin_usage ();
81         return (EX_USAGE);
82       }
83       
84   list = loptend;
85
86   if (job_control == 0)
87     {
88       builtin_error ("cannot suspend a shell without job control");
89       return (EXECUTION_FAILURE);
90     }
91
92   if (force == 0)  
93     {
94       no_args (list);
95
96       if (login_shell)
97         {
98           builtin_error ("cannot suspend a login shell");
99           return (EXECUTION_FAILURE);
100         }
101     }
102
103   old_cont = (SigHandler *)set_signal_handler (SIGCONT, suspend_continue);
104 #if 0
105   old_stop = (SigHandler *)set_signal_handler (SIGSTOP, SIG_DFL);
106 #endif
107   killpg (shell_pgrp, SIGSTOP);
108   return (EXECUTION_SUCCESS);
109 }
110
111 #endif /* JOB_CONTROL */