]>
Commit | Line | Data |
---|---|---|
726f6388 JA |
1 | This file is suspend.def, from which is created suspend.c. |
2 | It implements the builtin "suspend" in Bash. | |
3 | ||
7117c2d2 | 4 | Copyright (C) 1987-2002 Free Software Foundation, Inc. |
726f6388 JA |
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 | |
bb70624e | 10 | Software Foundation; either version 2, or (at your option) any later |
726f6388 JA |
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 | |
bb70624e | 20 | Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. |
726f6388 JA |
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 | ||
ccc6cda3 JA |
33 | #include <config.h> |
34 | ||
35 | #if defined (JOB_CONTROL) | |
36 | #if defined (HAVE_UNISTD_H) | |
cce855bc JA |
37 | # ifdef _MINIX |
38 | # include <sys/types.h> | |
39 | # endif | |
ccc6cda3 JA |
40 | # include <unistd.h> |
41 | #endif | |
42 | ||
43 | #include "../bashtypes.h" | |
726f6388 JA |
44 | #include <signal.h> |
45 | #include "../shell.h" | |
46 | #include "../jobs.h" | |
ccc6cda3 JA |
47 | #include "common.h" |
48 | #include "bashgetopt.h" | |
726f6388 | 49 | |
d166f048 JA |
50 | static SigHandler *old_cont; |
51 | #if 0 | |
52 | static SigHandler *old_stop; | |
53 | #endif | |
726f6388 JA |
54 | |
55 | /* Continue handler. */ | |
56 | sighandler | |
57 | suspend_continue (sig) | |
58 | int sig; | |
59 | { | |
60 | set_signal_handler (SIGCONT, old_cont); | |
ccc6cda3 JA |
61 | #if 0 |
62 | set_signal_handler (SIGSTOP, old_stop); | |
63 | #endif | |
64 | SIGRETURN (0); | |
726f6388 JA |
65 | } |
66 | ||
67 | /* Suspending the shell. If -f is the arg, then do the suspend | |
68 | no matter what. Otherwise, complain if a login shell. */ | |
69 | int | |
70 | suspend_builtin (list) | |
71 | WORD_LIST *list; | |
72 | { | |
ccc6cda3 JA |
73 | int opt, force; |
74 | ||
75 | reset_internal_getopt (); | |
76 | force = 0; | |
77 | while ((opt = internal_getopt (list, "f")) != -1) | |
78 | switch (opt) | |
79 | { | |
80 | case 'f': | |
81 | force++; | |
82 | break; | |
83 | default: | |
84 | builtin_usage (); | |
85 | return (EX_USAGE); | |
86 | } | |
87 | ||
88 | list = loptend; | |
89 | ||
90 | if (job_control == 0) | |
726f6388 | 91 | { |
7117c2d2 | 92 | sh_nojobs ("cannot suspend"); |
726f6388 JA |
93 | return (EXECUTION_FAILURE); |
94 | } | |
95 | ||
ccc6cda3 | 96 | if (force == 0) |
726f6388 | 97 | { |
ccc6cda3 JA |
98 | no_args (list); |
99 | ||
100 | if (login_shell) | |
101 | { | |
102 | builtin_error ("cannot suspend a login shell"); | |
103 | return (EXECUTION_FAILURE); | |
104 | } | |
726f6388 JA |
105 | } |
106 | ||
726f6388 | 107 | old_cont = (SigHandler *)set_signal_handler (SIGCONT, suspend_continue); |
ccc6cda3 JA |
108 | #if 0 |
109 | old_stop = (SigHandler *)set_signal_handler (SIGSTOP, SIG_DFL); | |
110 | #endif | |
111 | killpg (shell_pgrp, SIGSTOP); | |
726f6388 JA |
112 | return (EXECUTION_SUCCESS); |
113 | } | |
114 | ||
115 | #endif /* JOB_CONTROL */ |