|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T n
Length: 5494 (0x1576) Types: TextFile Names: »nojobs.c«
└─⟦a05ed705a⟧ Bits:30007078 DKUUG GNU 2/12/89 └─⟦ca1f037a2⟧ »./bash-1.04.tar.Z« └─⟦46465a4db⟧ └─⟦this⟧ »bash-1.04/nojobs.c«
/* The thing that makes children, remembers them, and contains wait loops. */ /* this will probably only work with System V */ /* Copyright (C) 1987,1989 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. */ #include <stdio.h> #include <sys/types.h> #include <sys/ttold.h> #include <fcntl.h> #include <termio.h> #include <signal.h> #include <setjmp.h> #include <errno.h> #include "config.h" #include "general.h" #include "jobs.h" #ifndef SIGABRT #define SIGABRT SIGIOT #endif #ifndef SYSV #include <sys/time.h> #include <sys/resource.h> /* The total amount of system time spent running processes for me. */ struct timeval total_systime = {0, 0}; long system_minutes_used = 0; int system_seconds_used = 0; /* The total amount of user time spent running processes for me. */ struct timeval total_usertime = {0, 0}; long user_minutes_used = 0; int user_seconds_used = 0; #endif int last_made_pid; int last_asynchronous_pid; /* * Initialize the job control mechanism, and set up the tty stuff. */ initialize_jobs () { } /* * Setup this shell to handle C-C, etc. */ initialize_job_signals () { extern int login_shell; int throw_to_top_level (); signal (SIGINT, throw_to_top_level); signal (SIGQUIT, SIG_IGN); /* If this is a login shell we don't wish to be disturbed by stop signals. */ if (login_shell) { #ifdef SIGSTOP signal (SIGSTOP, SIG_IGN); #endif #ifdef SIGTSTP signal (SIGTSTP, SIG_IGN); signal (SIGTTOU, SIG_IGN); signal (SIGTTIN, SIG_IGN); #endif } } /* * Fork, handling errors. Returns the pid of the newly made child, or 0. * COMMAND is just for remembering the name of the command; we don't do * anything else with it. ASYNC_P says what to do with the tty. If * non-zero, then don't give it away. */ make_child (command, async_p) char *command; int async_p; { int pid; /* Discard saved memory. */ free (command); /* Make new environment array if neccessary. */ maybe_make_export_env (); /* Create the child, handle severe errors. */ if ((pid = fork ()) < 0) { report_error ("Memory exhausted or process overflow!"); throw_to_top_level (); } if (!pid) { /* * Ignore INT and QUIT in asynchronous children. */ if (async_p) { signal (SIGINT, SIG_IGN); signal (SIGQUIT, SIG_IGN); last_asynchronous_pid = getpid (); } else { signal (SIGINT, SIG_DFL); signal (SIGQUIT, SIG_DFL); } /* Set the resource limits for this child. (In ulimit.c). */ set_process_resource_limits (); } else { /* * In the parent. */ last_made_pid = pid; if (async_p) last_asynchronous_pid = pid; } return (pid); } /* * Wait for pid (one of our children) to terminate. */ wait_for (pid) int pid; { int got_pid, return_val, oldmask; union wait status; #ifndef SYSV SigHandler *old_int, *old_quit; #endif #ifdef SYSV oldmask = sigignore (SIGINT); #else oldmask = sigblock (sigmask (SIGINT)); #endif while ((got_pid = wait (&status)) != pid) { if (got_pid < 0 && errno == ECHILD) { status.w_termsig = status.w_retcode = 0; break; } else if (got_pid < 0 && errno != EINTR) programming_error ("got errno %d while waiting for %d", errno, pid); } #ifdef SYSV sigrelse (oldmask); #else sigsetmask (oldmask); #endif /* Default return value. */ return_val = status.w_retcode & 0x7f; if (status.w_termsig != 0 && status.w_termsig != WSTOPPED) { extern char *sys_siglist[]; fprintf (stderr, "%s", sys_siglist[status.w_termsig]); if (status.w_coredump) fprintf (stderr, " (core dumped)"); fprintf (stderr, "\n"); return_val = status.w_termsig + 128; get_tty_state (); } return (return_val); } /* When we end a job abnormally, or if we stop a job, we set the tty to the state kept in here. When a job ends normally, we set the state in here to the state of the tty. */ static struct sgttyb shell_tty_info; /* Fill the contents of shell_tty_info with the current tty info. */ get_tty_state () { int tty = open ("/dev/tty", O_RDONLY); if (tty != -1) { #ifdef TIOCGETP ioctl (tty, TIOCGETP, &shell_tty_info); #endif close (tty); } } /* Make the current tty use the state in shell_tty_info. */ set_tty_state () { int tty = open ("/dev/tty", O_RDONLY); if (tty != -1) { #ifdef TIOCSETN ioctl (tty, TIOCSETN, &shell_tty_info); #endif close (tty); } } /* * stop a pipeline */ stop_pipeline (async, ignore) int async; char *ignore; { } /* * Print descriptive information about the job with leader pid PID. */ describe_pid (pid) int pid; { fprintf (stderr, "<%d>\n", pid); } wait_for_background_pids () {} wait_for_single_pid () {}