source: vendor/bash/3.1/builtins/suspend.def

Last change on this file was 3228, checked in by bird, 18 years ago

bash 3.1

File size: 2.8 KB
Line 
1This file is suspend.def, from which is created suspend.c.
2It implements the builtin "suspend" in Bash.
3
4Copyright (C) 1987-2003 Free Software Foundation, Inc.
5
6This file is part of GNU Bash, the Bourne Again SHell.
7
8Bash is free software; you can redistribute it and/or modify it under
9the terms of the GNU General Public License as published by the Free
10Software Foundation; either version 2, or (at your option) any later
11version.
12
13Bash is distributed in the hope that it will be useful, but WITHOUT ANY
14WARRANTY; without even the implied warranty of MERCHANTABILITY or
15FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16for more details.
17
18You should have received a copy of the GNU General Public License along
19with Bash; see the file COPYING. If not, write to the Free Software
20Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
21
22$PRODUCES suspend.c
23
24$BUILTIN suspend
25$DEPENDS_ON JOB_CONTROL
26$FUNCTION suspend_builtin
27$SHORT_DOC suspend [-f]
28Suspend the execution of this shell until it receives a SIGCONT
29signal. The `-f' if specified says not to complain about this
30being 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# ifdef _MINIX
38# include <sys/types.h>
39# endif
40# include <unistd.h>
41#endif
42
43#include "../bashtypes.h"
44#include <signal.h>
45#include "../bashintl.h"
46#include "../shell.h"
47#include "../jobs.h"
48#include "common.h"
49#include "bashgetopt.h"
50
51static SigHandler *old_cont;
52#if 0
53static SigHandler *old_stop;
54#endif
55
56/* Continue handler. */
57sighandler
58suspend_continue (sig)
59 int sig;
60{
61 set_signal_handler (SIGCONT, old_cont);
62#if 0
63 set_signal_handler (SIGSTOP, old_stop);
64#endif
65 SIGRETURN (0);
66}
67
68/* Suspending the shell. If -f is the arg, then do the suspend
69 no matter what. Otherwise, complain if a login shell. */
70int
71suspend_builtin (list)
72 WORD_LIST *list;
73{
74 int opt, force;
75
76 reset_internal_getopt ();
77 force = 0;
78 while ((opt = internal_getopt (list, "f")) != -1)
79 switch (opt)
80 {
81 case 'f':
82 force++;
83 break;
84 default:
85 builtin_usage ();
86 return (EX_USAGE);
87 }
88
89 list = loptend;
90
91 if (job_control == 0)
92 {
93 sh_nojobs (_("cannot suspend"));
94 return (EXECUTION_FAILURE);
95 }
96
97 if (force == 0)
98 {
99 no_args (list);
100
101 if (login_shell)
102 {
103 builtin_error (_("cannot suspend a login shell"));
104 return (EXECUTION_FAILURE);
105 }
106 }
107
108 /* XXX - should we put ourselves back into the original pgrp now? If so,
109 call end_job_control() here and do the right thing in suspend_continue
110 (that is, call restart_job_control()). */
111 old_cont = (SigHandler *)set_signal_handler (SIGCONT, suspend_continue);
112#if 0
113 old_stop = (SigHandler *)set_signal_handler (SIGSTOP, SIG_DFL);
114#endif
115 killpg (shell_pgrp, SIGSTOP);
116 return (EXECUTION_SUCCESS);
117}
118
119#endif /* JOB_CONTROL */
Note: See TracBrowser for help on using the repository browser.