1/* suspend.c, created from suspend.def. */ 2#line 23 "suspend.def" 3 4#line 32 "suspend.def" 5 6#include <config.h> 7 8#if defined (JOB_CONTROL) 9#if defined (HAVE_UNISTD_H) 10# ifdef _MINIX 11# include <sys/types.h> 12# endif 13# include <unistd.h> 14#endif 15 16#include "../bashtypes.h" 17#include <signal.h> 18#include "../bashintl.h" 19#include "../shell.h" 20#include "../jobs.h" 21#include "common.h" 22#include "bashgetopt.h" 23 24static sighandler suspend_continue __P((int)); 25 26static SigHandler *old_cont; 27#if 0 28static SigHandler *old_stop; 29#endif 30 31/* Continue handler. */ 32static sighandler 33suspend_continue (sig) 34 int sig; 35{ 36 set_signal_handler (SIGCONT, old_cont); 37#if 0 38 set_signal_handler (SIGSTOP, old_stop); 39#endif 40 SIGRETURN (0); 41} 42 43/* Suspending the shell. If -f is the arg, then do the suspend 44 no matter what. Otherwise, complain if a login shell. */ 45int 46suspend_builtin (list) 47 WORD_LIST *list; 48{ 49 int opt, force; 50 51 reset_internal_getopt (); 52 force = 0; 53 while ((opt = internal_getopt (list, "f")) != -1) 54 switch (opt) 55 { 56 case 'f': 57 force++; 58 break; 59 default: 60 builtin_usage (); 61 return (EX_USAGE); 62 } 63 64 list = loptend; 65 66 if (job_control == 0) 67 { 68 sh_nojobs (_("cannot suspend")); 69 return (EXECUTION_FAILURE); 70 } 71 72 if (force == 0) 73 { 74 no_args (list); 75 76 if (login_shell) 77 { 78 builtin_error (_("cannot suspend a login shell")); 79 return (EXECUTION_FAILURE); 80 } 81 } 82 83 /* XXX - should we put ourselves back into the original pgrp now? If so, 84 call end_job_control() here and do the right thing in suspend_continue 85 (that is, call restart_job_control()). */ 86 old_cont = (SigHandler *)set_signal_handler (SIGCONT, suspend_continue); 87#if 0 88 old_stop = (SigHandler *)set_signal_handler (SIGSTOP, SIG_DFL); 89#endif 90 killpg (shell_pgrp, SIGSTOP); 91 return (EXECUTION_SUCCESS); 92} 93 94#endif /* JOB_CONTROL */ 95