84 lines
2.2 KiB
Modula-2
84 lines
2.2 KiB
Modula-2
This file is suspend.def, from which is created suspend.c.
|
|
It implements the builtin "suspend" in Bash.
|
|
|
|
Copyright (C) 1987, 1989, 1991 Free Software Foundation, Inc.
|
|
|
|
This file is part of GNU Bash, the Bourne Again SHell.
|
|
|
|
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 1, or (at your option) any later
|
|
version.
|
|
|
|
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.
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
with Bash; see the file COPYING. If not, write to the Free Software
|
|
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
$PRODUCES suspend.c
|
|
|
|
$BUILTIN suspend
|
|
$DEPENDS_ON JOB_CONTROL
|
|
$FUNCTION suspend_builtin
|
|
$SHORT_DOC suspend [-f]
|
|
Suspend the execution of this shell until it receives a SIGCONT
|
|
signal. The `-f' if specified says not to complain about this
|
|
being a login shell if it is; just suspend anyway.
|
|
$END
|
|
|
|
#include <signal.h>
|
|
#include <sys/types.h>
|
|
#include "../shell.h"
|
|
#include "../jobs.h"
|
|
|
|
#if defined (JOB_CONTROL)
|
|
extern int job_control;
|
|
|
|
static SigHandler *old_cont, *old_tstp;
|
|
|
|
/* Continue handler. */
|
|
sighandler
|
|
suspend_continue (sig)
|
|
int sig;
|
|
{
|
|
signal (SIGCONT, old_cont);
|
|
signal (SIGTSTP, old_tstp);
|
|
}
|
|
|
|
/* 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;
|
|
{
|
|
if (!job_control)
|
|
{
|
|
builtin_error ("Cannot suspend a shell without job control");
|
|
return (EXECUTION_FAILURE);
|
|
}
|
|
|
|
if (list)
|
|
if (strcmp (list->word->word, "-f") == 0)
|
|
goto do_suspend;
|
|
|
|
no_args (list);
|
|
|
|
if (login_shell)
|
|
{
|
|
builtin_error ("Can't suspend a login shell");
|
|
return (EXECUTION_FAILURE);
|
|
}
|
|
|
|
do_suspend:
|
|
old_cont = (SigHandler *)signal (SIGCONT, suspend_continue);
|
|
old_tstp = (SigHandler *)signal (SIGTSTP, SIG_DFL);
|
|
killpg (shell_pgrp, SIGTSTP);
|
|
return (EXECUTION_SUCCESS);
|
|
}
|
|
|
|
#endif /* JOB_CONTROL */
|