Imported from ../bash-2.05a.tar.gz.
[platform/upstream/bash.git] / nojobs.c
1 /* The thing that makes children, remembers them, and contains wait loops. */
2
3 /* This file works under BSD, System V, minix, and Posix systems.  It does
4    not implement job control. */
5
6 /* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc.
7
8    This file is part of GNU Bash, the Bourne Again SHell.
9
10    Bash is free software; you can redistribute it and/or modify it under
11    the terms of the GNU General Public License as published by the Free
12    Software Foundation; either version 2, or (at your option) any later
13    version.
14
15    Bash is distributed in the hope that it will be useful, but WITHOUT ANY
16    WARRANTY; without even the implied warranty of MERCHANTABILITY or
17    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
18    for more details.
19
20    You should have received a copy of the GNU General Public License along
21    with Bash; see the file COPYING.  If not, write to the Free Software
22    Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
23
24 #include "config.h"
25
26 #include "bashtypes.h"
27 #include "filecntl.h"
28
29 #if defined (HAVE_UNISTD_H)
30 #  include <unistd.h>
31 #endif
32
33 #include <stdio.h>
34 #include <signal.h>
35 #include <errno.h>
36
37 #if defined (BUFFERED_INPUT)
38 #  include "input.h"
39 #endif
40
41 /* Need to include this up here for *_TTY_DRIVER definitions. */
42 #include "shtty.h"
43
44 #if !defined (STRUCT_WINSIZE_IN_SYS_IOCTL)
45 /* For struct winsize on SCO */
46 /*   sys/ptem.h has winsize but needs mblk_t from sys/stream.h */
47 #  if defined (HAVE_SYS_PTEM_H) && defined (TIOCGWINSZ) && defined (SIGWINCH)
48 #    if defined (HAVE_SYS_STREAM_H)
49 #      include <sys/stream.h>
50 #    endif
51 #    include <sys/ptem.h>
52 #  endif /* HAVE_SYS_PTEM_H && TIOCGWINSZ && SIGWINCH */
53 #endif /* !STRUCT_WINSIZE_IN_SYS_IOCTL */
54
55 #include "shell.h"
56 #include "jobs.h"
57
58 #include "builtins/builtext.h"  /* for wait_builtin */
59
60 #if !defined (CHILD_MAX)
61 #  define CHILD_MAX 32
62 #endif
63
64 #if defined (_POSIX_VERSION) || !defined (HAVE_KILLPG)
65 #  define killpg(pg, sig)               kill(-(pg),(sig))
66 #endif /* USG || _POSIX_VERSION */
67
68 #if !defined (HAVE_SIGINTERRUPT)
69 #  define siginterrupt(sig, code)
70 #endif /* !HAVE_SIGINTERRUPT */
71
72 #if defined (HAVE_WAITPID)
73 #  define WAITPID(pid, statusp, options) waitpid (pid, statusp, options)
74 #else
75 #  define WAITPID(pid, statusp, options) wait (statusp)
76 #endif /* !HAVE_WAITPID */
77
78 /* Return the fd from which we are actually getting input. */
79 #define input_tty() (shell_tty != -1) ? shell_tty : fileno (stderr)
80
81 #if !defined (errno)
82 extern int errno;
83 #endif /* !errno */
84
85 #if defined (READLINE)
86 extern void rl_set_screen_size __P((int, int));
87 #endif
88
89 extern int interactive, interactive_shell, login_shell;
90 extern int subshell_environment;
91 extern int last_command_exit_value;
92 extern int interrupt_immediately;
93 extern sh_builtin_func_t *this_shell_builtin;
94 #if defined (HAVE_POSIX_SIGNALS)
95 extern sigset_t top_level_mask;
96 #endif
97 extern procenv_t wait_intr_buf;
98
99 pid_t last_made_pid = NO_PID;
100 pid_t last_asynchronous_pid = NO_PID;
101
102 /* Call this when you start making children. */
103 int already_making_children = 0;
104
105 /* The controlling tty for this shell. */
106 int shell_tty = -1;
107
108 /* If this is non-zero, $LINES and $COLUMNS are reset after every process
109    exits from get_tty_state(). */
110 int check_window_size;
111
112 /* STATUS and FLAGS are only valid if pid != NO_PID
113    STATUS is only valid if (flags & PROC_RUNNING) == 0 */
114 struct proc_status {
115   pid_t pid;
116   int status;   /* Exit status of PID or 128 + fatal signal number */
117   int flags;
118 };
119
120 /* Values for proc_status.flags */
121 #define PROC_RUNNING    0x01
122 #define PROC_NOTIFIED   0x02
123 #define PROC_ASYNC      0x04
124
125 /* Return values from find_status_by_pid */
126 #define PROC_BAD         -1
127 #define PROC_STILL_ALIVE -2
128
129 static struct proc_status *pid_list = (struct proc_status *)NULL;
130 static int pid_list_size;
131 static int wait_sigint_received;
132
133 static void alloc_pid_list __P((void));
134 static int find_proc_slot __P((void));
135 static int find_index_by_pid __P((pid_t));
136 static int find_status_by_pid __P((pid_t));
137 static int process_exit_status __P((WAIT));
138 static void set_pid_status __P((pid_t, WAIT));
139 static void set_pid_flags __P((pid_t, int));
140 static void unset_pid_flags __P((pid_t, int));
141 static void add_pid __P((pid_t, int));
142 static void mark_dead_jobs_as_notified __P((int));
143
144 static void get_new_window_size __P((int));
145 static sighandler sigwinch_sighandler __P((int));
146 static sighandler wait_signal_handler __P((int));
147
148 #if defined (HAVE_WAITPID)
149 static void reap_zombie_children __P((void));
150 #endif
151
152 static void restore_sigint_handler __P((void));
153
154 /* Allocate new, or grow existing PID_LIST. */
155 static void
156 alloc_pid_list ()
157 {
158   register int i;
159   int old = pid_list_size;
160
161   pid_list_size += 10;
162   pid_list = (struct proc_status *)xrealloc (pid_list, pid_list_size * sizeof (struct proc_status));
163
164   /* None of the newly allocated slots have process id's yet. */
165   for (i = old; i < pid_list_size; i++)
166     pid_list[i].pid = NO_PID;
167 }
168
169 /* Return the offset within the PID_LIST array of an empty slot.  This can
170    create new slots if all of the existing slots are taken. */
171 static int
172 find_proc_slot ()
173 {
174   register int i;
175
176   for (i = 0; i < pid_list_size; i++)
177     if (pid_list[i].pid == NO_PID)
178       return (i);
179
180   if (i == pid_list_size)
181     alloc_pid_list ();
182
183   return (i);
184 }
185
186 /* Return the offset within the PID_LIST array of a slot containing PID,
187    or the value NO_PID if the pid wasn't found. */
188 static int
189 find_index_by_pid (pid)
190      pid_t pid;
191 {
192   register int i;
193
194   for (i = 0; i < pid_list_size; i++)
195     if (pid_list[i].pid == pid)
196       return (i);
197
198   return (NO_PID);
199 }
200
201 /* Return the status of PID as looked up in the PID_LIST array.  A
202    return value of PROC_BAD indicates that PID wasn't found. */
203 static int
204 find_status_by_pid (pid)
205      pid_t pid;
206 {
207   int i;
208
209   i = find_index_by_pid (pid);
210   if (i == NO_PID)
211     return (PROC_BAD);
212   if (pid_list[i].flags & PROC_RUNNING)
213     return (PROC_STILL_ALIVE);
214   return (pid_list[i].status);
215 }
216
217 static int
218 process_exit_status (status)
219      WAIT status;
220 {
221   if (WIFSIGNALED (status))
222     return (128 + WTERMSIG (status));
223   else
224     return (WEXITSTATUS (status));
225 }
226
227 /* Give PID the status value STATUS in the PID_LIST array. */
228 static void
229 set_pid_status (pid, status)
230      pid_t pid;
231      WAIT status;
232 {
233   int slot;
234
235   slot = find_index_by_pid (pid);
236   if (slot == NO_PID)
237     return;
238
239   pid_list[slot].status = process_exit_status (status);
240   pid_list[slot].flags &= ~PROC_RUNNING;
241   /* If it's not a background process, mark it as notified so it gets
242      cleaned up. */
243   if ((pid_list[slot].flags & PROC_ASYNC) == 0)
244     pid_list[slot].flags |= PROC_NOTIFIED;
245 }
246
247 /* Give PID the flags FLAGS in the PID_LIST array. */
248 static void
249 set_pid_flags (pid, flags)
250      pid_t pid;
251      int flags;
252 {
253   int slot;
254
255   slot = find_index_by_pid (pid);
256   if (slot == NO_PID)
257     return;
258
259   pid_list[slot].flags |= flags;
260 }
261
262 /* Unset FLAGS for PID in the pid list */
263 static void
264 unset_pid_flags (pid, flags)
265      pid_t pid;
266      int flags;
267 {
268   int slot;
269
270   slot = find_index_by_pid (pid);
271   if (slot == NO_PID)
272     return;
273
274   pid_list[slot].flags &= ~flags;
275 }
276
277 static void
278 add_pid (pid, async)
279      pid_t pid;
280      int async;
281 {
282   int slot;
283
284   slot = find_proc_slot ();
285
286   pid_list[slot].pid = pid;
287   pid_list[slot].status = -1;
288   pid_list[slot].flags = PROC_RUNNING;
289   if (async)
290     pid_list[slot].flags |= PROC_ASYNC;
291 }
292
293 static void
294 mark_dead_jobs_as_notified (force)
295      int force;
296 {
297   register int i, ndead;
298
299   /* first, count the number of non-running async jobs if FORCE == 0 */
300   for (i = ndead = 0; force == 0 && i < pid_list_size; i++)
301     {
302       if (pid_list[i].pid == NO_PID)
303         continue;
304       if (((pid_list[i].flags & PROC_RUNNING) == 0) &&
305            (pid_list[i].flags & PROC_ASYNC))
306         ndead++;
307     }
308
309   if (force == 0 && ndead <= CHILD_MAX)
310     return;
311
312   /* If FORCE == 0, we just mark as many non-running async jobs as notified
313      to bring us under the CHILD_MAX limit. */
314   for (i = 0; i < pid_list_size; i++)
315     {
316       if (pid_list[i].pid == NO_PID)
317         continue;
318       if (((pid_list[i].flags & PROC_RUNNING) == 0) &&
319            pid_list[i].pid != last_asynchronous_pid)
320         {
321           pid_list[i].flags |= PROC_NOTIFIED;
322           if (force == 0 && (pid_list[i].flags & PROC_ASYNC) && --ndead <= CHILD_MAX)
323             break;
324         }
325     }
326 }
327
328 /* Remove all dead, notified jobs from the pid_list. */
329 int
330 cleanup_dead_jobs ()
331 {
332   register int i;
333
334 #if defined (HAVE_WAITPID)
335   reap_zombie_children ();
336 #endif
337
338   for (i = 0; i < pid_list_size; i++)
339     {
340       if ((pid_list[i].flags & PROC_RUNNING) == 0 &&
341           (pid_list[i].flags & PROC_NOTIFIED))
342         pid_list[i].pid = NO_PID;
343     }
344
345   return 0;
346 }
347
348 void
349 reap_dead_jobs ()
350 {
351   mark_dead_jobs_as_notified (0);
352   cleanup_dead_jobs ();
353 }
354
355 /* Initialize the job control mechanism, and set up the tty stuff. */
356 initialize_job_control (force)
357      int force;
358 {
359   shell_tty = fileno (stderr);
360
361   if (interactive)
362     get_tty_state ();
363 }
364
365 #if defined (TIOCGWINSZ) && defined (SIGWINCH)
366 static SigHandler *old_winch = (SigHandler *)SIG_DFL;
367
368 static void
369 get_new_window_size (from_sig)
370      int from_sig;
371 {
372   struct winsize win;
373   int tty;
374
375   tty = input_tty ();
376   if (tty >= 0 && (ioctl (tty, TIOCGWINSZ, &win) == 0) &&
377       win.ws_row > 0 && win.ws_col > 0)
378     {
379 #if defined (aixpc)
380       shell_tty_info.c_winsize = win;   /* structure copying */
381 #endif
382       sh_set_lines_and_columns (win.ws_row, win.ws_col);
383 #if defined (READLINE)
384       rl_set_screen_size (win.ws_row, win.ws_col);
385 #endif
386     }
387 }
388
389 static sighandler
390 sigwinch_sighandler (sig)
391      int sig;
392 {
393 #if defined (MUST_REINSTALL_SIGHANDLERS)
394   set_signal_handler (SIGWINCH, sigwinch_sighandler);
395 #endif /* MUST_REINSTALL_SIGHANDLERS */
396   get_new_window_size (1);
397 }
398 #else
399 static void
400 get_new_window_size (from_sig)
401      int from_sig;
402 {
403 }
404 #endif /* TIOCGWINSZ && SIGWINCH */
405
406 void
407 set_sigwinch_handler ()
408 {
409 #if defined (TIOCGWINSZ) && defined (SIGWINCH)
410   old_winch = set_signal_handler (SIGWINCH, sigwinch_sighandler);
411 #endif
412 }
413
414 void
415 unset_sigwinch_handler ()
416 {
417 #if defined (TIOCGWINSZ) && defined (SIGWINCH)
418   set_signal_handler (SIGWINCH, old_winch);
419 #endif
420 }
421
422 /* Setup this shell to handle C-C, etc. */
423 void
424 initialize_job_signals ()
425 {
426   set_signal_handler (SIGINT, sigint_sighandler);
427   set_sigwinch_handler ();
428
429   /* If this is a login shell we don't wish to be disturbed by
430      stop signals. */
431   if (login_shell)
432     ignore_tty_job_signals ();
433 }
434
435 #if defined (HAVE_WAITPID)
436 /* Collect the status of all zombie children so that their system
437    resources can be deallocated. */
438 static void
439 reap_zombie_children ()
440 {
441 #if defined (WNOHANG)
442   pid_t pid;
443   WAIT status;
444
445   while ((pid = waitpid (-1, (int *)&status, WNOHANG)) > 0)
446     set_pid_status (pid, status);
447 #endif
448 }
449 #endif /* WAITPID && WNOHANG */
450
451 /* Fork, handling errors.  Returns the pid of the newly made child, or 0.
452    COMMAND is just for remembering the name of the command; we don't do
453    anything else with it.  ASYNC_P says what to do with the tty.  If
454    non-zero, then don't give it away. */
455 pid_t
456 make_child (command, async_p)
457      char *command;
458      int async_p;
459 {
460   pid_t pid;
461 #if defined (HAVE_WAITPID)
462   int retry = 1;
463 #endif /* HAVE_WAITPID */
464
465   /* Discard saved memory. */
466   if (command)
467     free (command);
468
469   start_pipeline ();
470
471 #if defined (BUFFERED_INPUT)
472   /* If default_buffered_input is active, we are reading a script.  If
473      the command is asynchronous, we have already duplicated /dev/null
474      as fd 0, but have not changed the buffered stream corresponding to
475      the old fd 0.  We don't want to sync the stream in this case. */
476   if (default_buffered_input != -1 && (!async_p || default_buffered_input > 0))
477     sync_buffered_stream (default_buffered_input);
478 #endif /* BUFFERED_INPUT */
479
480   /* Create the child, handle severe errors. */
481 #if defined (HAVE_WAITPID)
482   retry_fork:
483 #endif /* HAVE_WAITPID */
484
485   if ((pid = fork ()) < 0)
486     {
487 #if defined (HAVE_WAITPID)
488       /* Posix systems with a non-blocking waitpid () system call available
489          get another chance after zombies are reaped. */
490       if (errno == EAGAIN && retry)
491         {
492           reap_zombie_children ();
493           retry = 0;
494           goto retry_fork;
495         }
496 #endif /* HAVE_WAITPID */
497
498       sys_error ("fork");
499
500       throw_to_top_level ();
501     }
502
503   if (pid == 0)
504     {
505 #if defined (BUFFERED_INPUT)
506       unset_bash_input (0);
507 #endif /* BUFFERED_INPUT */
508
509 #if defined (HAVE_POSIX_SIGNALS)
510       /* Restore top-level signal mask. */
511       sigprocmask (SIG_SETMASK, &top_level_mask, (sigset_t *)NULL);
512 #endif
513
514       /* Ignore INT and QUIT in asynchronous children. */
515       if (async_p)
516         last_asynchronous_pid = getpid ();
517
518       default_tty_job_signals ();
519     }
520   else
521     {
522       /* In the parent. */
523
524       last_made_pid = pid;
525
526       if (async_p)
527         last_asynchronous_pid = pid;
528
529       add_pid (pid, async_p);
530     }
531   return (pid);
532 }
533
534 void
535 ignore_tty_job_signals ()
536 {
537 #if defined (SIGTSTP)
538   set_signal_handler (SIGTSTP, SIG_IGN);
539   set_signal_handler (SIGTTIN, SIG_IGN);
540   set_signal_handler (SIGTTOU, SIG_IGN);
541 #endif
542 }
543
544 void
545 default_tty_job_signals ()
546 {
547 #if defined (SIGTSTP)
548   set_signal_handler (SIGTSTP, SIG_DFL);
549   set_signal_handler (SIGTTIN, SIG_DFL);
550   set_signal_handler (SIGTTOU, SIG_DFL);
551 #endif
552 }
553
554 /* Wait for a single pid (PID) and return its exit status.  Called by
555    the wait builtin. */
556 int
557 wait_for_single_pid (pid)
558      pid_t pid;
559 {
560   pid_t got_pid;
561   WAIT status;
562   int pstatus;
563
564   pstatus = find_status_by_pid (pid);
565
566   if (pstatus == PROC_BAD)
567     {
568       internal_error ("wait: pid %ld is not a child of this shell", (long)pid);
569       return (127);
570     }
571
572   if (pstatus != PROC_STILL_ALIVE)
573     return (pstatus);
574
575   siginterrupt (SIGINT, 1);
576   while ((got_pid = WAITPID (pid, &status, 0)) != pid)
577     {
578       if (got_pid < 0)
579         {
580           if (errno != EINTR && errno != ECHILD)
581             {
582               siginterrupt (SIGINT, 0);
583               sys_error ("wait");
584             }
585           break;
586         }
587       else if (got_pid > 0)
588         set_pid_status (got_pid, status);
589     }
590
591   set_pid_status (got_pid, status);
592   set_pid_flags (got_pid, PROC_NOTIFIED);
593
594   siginterrupt (SIGINT, 0);
595   QUIT;
596
597   return (process_exit_status (status));
598 }
599
600 /* Wait for all of the shell's children to exit.  Called by the `wait'
601    builtin. */
602 void
603 wait_for_background_pids ()
604 {
605   pid_t got_pid;
606   WAIT status;
607
608   /* If we aren't using job control, we let the kernel take care of the
609      bookkeeping for us.  wait () will return -1 and set errno to ECHILD
610      when there are no more unwaited-for child processes on both
611      4.2 BSD-based and System V-based systems. */
612
613   siginterrupt (SIGINT, 1);
614
615   /* Wait for ECHILD */
616   while ((got_pid = WAITPID (-1, &status, 0)) != -1)
617     set_pid_status (got_pid, status);
618
619   if (errno != EINTR && errno != ECHILD)
620     {
621       siginterrupt (SIGINT, 0);
622       sys_error("wait");
623     }
624
625   siginterrupt (SIGINT, 0);
626   QUIT;
627
628   mark_dead_jobs_as_notified (1);
629   cleanup_dead_jobs ();
630 }
631
632 /* Make OLD_SIGINT_HANDLER the SIGINT signal handler. */
633 #define INVALID_SIGNAL_HANDLER (SigHandler *)wait_for_background_pids
634 static SigHandler *old_sigint_handler = INVALID_SIGNAL_HANDLER;
635
636 static void
637 restore_sigint_handler ()
638 {
639   if (old_sigint_handler != INVALID_SIGNAL_HANDLER)
640     {
641       set_signal_handler (SIGINT, old_sigint_handler);
642       old_sigint_handler = INVALID_SIGNAL_HANDLER;
643     }
644 }
645
646 /* Handle SIGINT while we are waiting for children in a script to exit.
647    All interrupts are effectively ignored by the shell, but allowed to
648    kill a running job. */
649 static sighandler
650 wait_sigint_handler (sig)
651      int sig;
652 {
653   SigHandler *sigint_handler;
654
655   /* If we got a SIGINT while in `wait', and SIGINT is trapped, do
656      what POSIX.2 says (see builtins/wait.def for more info). */
657   if (this_shell_builtin && this_shell_builtin == wait_builtin &&
658       signal_is_trapped (SIGINT) &&
659       ((sigint_handler = trap_to_sighandler (SIGINT)) == trap_handler))
660     {
661       last_command_exit_value = EXECUTION_FAILURE;
662       restore_sigint_handler ();
663       interrupt_immediately = 0;
664       trap_handler (SIGINT);    /* set pending_traps[SIGINT] */
665       longjmp (wait_intr_buf, 1);
666     }
667
668   if (interrupt_immediately)
669     {
670       last_command_exit_value = EXECUTION_FAILURE;
671       restore_sigint_handler ();
672       ADDINTERRUPT;
673       QUIT;
674     }
675
676   wait_sigint_received = 1;
677
678   SIGRETURN (0);
679 }
680
681 /* Wait for pid (one of our children) to terminate.  This is called only
682    by the execution code in execute_cmd.c. */
683 int
684 wait_for (pid)
685      pid_t pid;
686 {
687   int return_val, pstatus;
688   pid_t got_pid;
689   WAIT status;
690
691   pstatus = find_status_by_pid (pid);
692
693   if (pstatus == PROC_BAD)
694     return (0);
695
696   if (pstatus != PROC_STILL_ALIVE)
697     return (pstatus);
698
699   /* If we are running a script, ignore SIGINT while we're waiting for
700      a child to exit.  The loop below does some of this, but not all. */
701   wait_sigint_received = 0;
702   if (interactive_shell == 0)
703     old_sigint_handler = set_signal_handler (SIGINT, wait_sigint_handler);
704
705   while ((got_pid = WAITPID (-1, &status, 0)) != pid) /* XXX was pid now -1 */
706     {
707       if (got_pid < 0 && errno == ECHILD)
708         {
709 #if !defined (_POSIX_VERSION)
710           status.w_termsig = status.w_retcode = 0;
711 #else
712           status = 0;
713 #endif /* _POSIX_VERSION */
714           break;
715         }
716       else if (got_pid < 0 && errno != EINTR)
717         programming_error ("wait_for(%ld): %s", (long)pid, strerror(errno));
718       else if (got_pid > 0)
719         set_pid_status (got_pid, status);
720     }
721
722   set_pid_status (got_pid, status);
723
724 #if defined (HAVE_WAITPID)
725   if (got_pid >= 0)
726     reap_zombie_children ();
727 #endif /* HAVE_WAITPID */
728
729   if (interactive_shell == 0)
730     {
731       SigHandler *temp_handler;
732
733       temp_handler = old_sigint_handler;
734       restore_sigint_handler ();
735
736       /* If the job exited because of SIGINT, make sure the shell acts as if
737          it had received one also. */
738       if (WIFSIGNALED (status) && (WTERMSIG (status) == SIGINT))
739         {
740
741           if (maybe_call_trap_handler (SIGINT) == 0)
742             {
743               if (temp_handler == SIG_DFL)
744                 termination_unwind_protect (SIGINT);
745               else if (temp_handler != INVALID_SIGNAL_HANDLER && temp_handler != SIG_IGN)
746                 (*temp_handler) (SIGINT);
747             }
748         }
749     }
750
751   /* Default return value. */
752   /* ``a full 8 bits of status is returned'' */
753   return_val = process_exit_status (status);
754
755 #if !defined (DONT_REPORT_SIGPIPE)
756   if ((WIFSTOPPED (status) == 0) && WIFSIGNALED (status) &&
757         (WTERMSIG (status) != SIGINT))
758 #else
759   if ((WIFSTOPPED (status) == 0) && WIFSIGNALED (status) &&
760         (WTERMSIG (status) != SIGINT) && (WTERMSIG (status) != SIGPIPE))
761 #endif
762     {
763       fprintf (stderr, "%s", strsignal (WTERMSIG (status)));
764       if (WIFCORED (status))
765         fprintf (stderr, " (core dumped)");
766       fprintf (stderr, "\n");
767     }
768
769   if (interactive_shell && subshell_environment == 0)
770     {
771       if (WIFSIGNALED (status) || WIFSTOPPED (status))
772         set_tty_state ();
773       else
774         get_tty_state ();
775     }
776
777   return (return_val);
778 }
779
780 /* Give PID SIGNAL.  This determines what job the pid belongs to (if any).
781    If PID does belong to a job, and the job is stopped, then CONTinue the
782    job after giving it SIGNAL.  Returns -1 on failure.  If GROUP is non-null,
783    then kill the process group associated with PID. */
784 int
785 kill_pid (pid, signal, group)
786      pid_t pid;
787      int signal, group;
788 {
789   int result;
790
791   result = group ? killpg (pid, signal) : kill (pid, signal);
792   return (result);
793 }
794
795 static TTYSTRUCT shell_tty_info;
796 static int got_tty_state;
797
798 /* Fill the contents of shell_tty_info with the current tty info. */
799 get_tty_state ()
800 {
801   int tty;
802
803   tty = input_tty ();
804   if (tty != -1)
805     {
806       ttgetattr (tty, &shell_tty_info);
807       got_tty_state = 1;
808       if (check_window_size)
809         get_new_window_size (0);
810     }
811 }
812
813 /* Make the current tty use the state in shell_tty_info. */
814 int
815 set_tty_state ()
816 {
817   int tty;
818
819   tty = input_tty ();
820   if (tty != -1)
821     {
822       if (got_tty_state == 0)
823         return 0;
824       ttsetattr (tty, &shell_tty_info);
825     }
826   return 0;
827 }
828
829 /* Give the terminal to PGRP.  */
830 give_terminal_to (pgrp, force)
831      pid_t pgrp;
832      int force;
833 {
834 }
835
836 /* Stop a pipeline. */
837 int
838 stop_pipeline (async, ignore)
839      int async;
840      COMMAND *ignore;
841 {
842   already_making_children = 0;
843   return 0;
844 }
845
846 void
847 start_pipeline ()
848 {
849   already_making_children = 1;
850 }
851
852 void
853 stop_making_children ()
854 {
855   already_making_children = 0;
856 }
857
858 int
859 get_job_by_pid (pid, block)
860      pid_t pid;
861      int block;
862 {
863   int i;
864
865   i = find_index_by_pid (pid);
866   return ((i == NO_PID) ? PROC_BAD : i);
867 }
868
869 /* Print descriptive information about the job with leader pid PID. */
870 void
871 describe_pid (pid)
872      pid_t pid;
873 {
874   fprintf (stderr, "%ld\n", (long) pid);
875 }
876
877 void
878 unfreeze_jobs_list ()
879 {
880 }
881
882 int
883 count_all_jobs ()
884 {
885   return 0;
886 }