i-bash/builtins/suspend.def

128 lines
2.9 KiB
Modula-2
Raw Normal View History

1996-08-26 18:22:31 +00:00
This file is suspend.def, from which is created suspend.c.
It implements the builtin "suspend" in Bash.
2009-01-12 13:36:28 +00:00
Copyright (C) 1987-2009 Free Software Foundation, Inc.
1996-08-26 18:22:31 +00:00
This file is part of GNU Bash, the Bourne Again SHell.
2009-01-12 13:36:28 +00:00
Bash is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
1996-08-26 18:22:31 +00:00
2009-01-12 13:36:28 +00:00
Bash is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
1996-08-26 18:22:31 +00:00
2009-01-12 13:36:28 +00:00
You should have received a copy of the GNU General Public License
along with Bash. If not, see <http://www.gnu.org/licenses/>.
1996-08-26 18:22:31 +00:00
$PRODUCES suspend.c
$BUILTIN suspend
$DEPENDS_ON JOB_CONTROL
$FUNCTION suspend_builtin
$SHORT_DOC suspend [-f]
2009-01-12 13:36:28 +00:00
Suspend shell execution.
Suspend the execution of this shell until it receives a SIGCONT signal.
Unless forced, login shells cannot be suspended.
Options:
-f force the suspend, even if the shell is a login shell
Exit Status:
Returns success unless job control is not enabled or an error occurs.
1996-08-26 18:22:31 +00:00
$END
1996-12-23 17:02:34 +00:00
#include <config.h>
#if defined (JOB_CONTROL)
#if defined (HAVE_UNISTD_H)
1998-04-17 19:52:44 +00:00
# ifdef _MINIX
# include <sys/types.h>
# endif
1996-12-23 17:02:34 +00:00
# include <unistd.h>
#endif
#include "../bashtypes.h"
1996-08-26 18:22:31 +00:00
#include <signal.h>
2004-07-27 13:29:18 +00:00
#include "../bashintl.h"
1996-08-26 18:22:31 +00:00
#include "../shell.h"
#include "../jobs.h"
1996-12-23 17:02:34 +00:00
#include "common.h"
#include "bashgetopt.h"
1996-08-26 18:22:31 +00:00
2006-10-10 14:15:34 +00:00
static sighandler suspend_continue __P((int));
1997-06-05 14:59:13 +00:00
static SigHandler *old_cont;
#if 0
static SigHandler *old_stop;
#endif
1996-08-26 18:22:31 +00:00
/* Continue handler. */
2006-10-10 14:15:34 +00:00
static sighandler
1996-08-26 18:22:31 +00:00
suspend_continue (sig)
int sig;
{
set_signal_handler (SIGCONT, old_cont);
1996-12-23 17:02:34 +00:00
#if 0
set_signal_handler (SIGSTOP, old_stop);
#endif
SIGRETURN (0);
1996-08-26 18:22:31 +00:00
}
/* Suspending the shell. If -f is the arg, then do the suspend
no matter what. Otherwise, complain if a login shell. */
int
suspend_builtin (list)
WORD_LIST *list;
{
1996-12-23 17:02:34 +00:00
int opt, force;
reset_internal_getopt ();
force = 0;
while ((opt = internal_getopt (list, "f")) != -1)
switch (opt)
{
case 'f':
force++;
break;
default:
builtin_usage ();
return (EX_USAGE);
}
list = loptend;
if (job_control == 0)
1996-08-26 18:22:31 +00:00
{
2004-07-27 13:29:18 +00:00
sh_nojobs (_("cannot suspend"));
1996-08-26 18:22:31 +00:00
return (EXECUTION_FAILURE);
}
1996-12-23 17:02:34 +00:00
if (force == 0)
1996-08-26 18:22:31 +00:00
{
1996-12-23 17:02:34 +00:00
no_args (list);
if (login_shell)
{
2004-07-27 13:29:18 +00:00
builtin_error (_("cannot suspend a login shell"));
1996-12-23 17:02:34 +00:00
return (EXECUTION_FAILURE);
}
1996-08-26 18:22:31 +00:00
}
2004-07-27 13:29:18 +00:00
/* XXX - should we put ourselves back into the original pgrp now? If so,
call end_job_control() here and do the right thing in suspend_continue
(that is, call restart_job_control()). */
1996-08-26 18:22:31 +00:00
old_cont = (SigHandler *)set_signal_handler (SIGCONT, suspend_continue);
1996-12-23 17:02:34 +00:00
#if 0
old_stop = (SigHandler *)set_signal_handler (SIGSTOP, SIG_DFL);
#endif
killpg (shell_pgrp, SIGSTOP);
1996-08-26 18:22:31 +00:00
return (EXECUTION_SUCCESS);
}
#endif /* JOB_CONTROL */