jobs.c (213760) | jobs.c (213775) |
---|---|
1/*- 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Kenneth Almquist. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 22 unchanged lines hidden (view full) --- 31 */ 32 33#ifndef lint 34#if 0 35static char sccsid[] = "@(#)jobs.c 8.5 (Berkeley) 5/4/95"; 36#endif 37#endif /* not lint */ 38#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Kenneth Almquist. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 22 unchanged lines hidden (view full) --- 31 */ 32 33#ifndef lint 34#if 0 35static char sccsid[] = "@(#)jobs.c 8.5 (Berkeley) 5/4/95"; 36#endif 37#endif /* not lint */ 38#include <sys/cdefs.h> |
39__FBSDID("$FreeBSD: head/bin/sh/jobs.c 213760 2010-10-13 04:01:01Z obrien $"); | 39__FBSDID("$FreeBSD: head/bin/sh/jobs.c 213775 2010-10-13 13:22:11Z jhb $"); |
40 | 40 |
41#include <fcntl.h> 42#include <signal.h> 43#include <errno.h> 44#include <paths.h> 45#include <unistd.h> 46#include <stdlib.h> | 41#include <sys/ioctl.h> |
47#include <sys/param.h> | 42#include <sys/param.h> |
48#include <sys/wait.h> 49#include <sys/time.h> | |
50#include <sys/resource.h> | 43#include <sys/resource.h> |
44#include <sys/stddef.h> 45#include <sys/time.h> 46#include <sys/wait.h> 47#include <errno.h> 48#include <fcntl.h> |
|
51#include <paths.h> | 49#include <paths.h> |
52#include <sys/ioctl.h> | 50#include <signal.h> 51#include <stdlib.h> 52#include <unistd.h> |
53 54#include "shell.h" 55#if JOBS 56#include <termios.h> 57#undef CEOF /* syntax.h redefines this */ 58#endif 59#include "redir.h" 60#include "show.h" --- 614 unchanged lines hidden (view full) --- 675 jp->next = NULL; 676#endif 677 if (nprocs > 1) { 678 jp->ps = ckmalloc(nprocs * sizeof (struct procstat)); 679 } else { 680 jp->ps = &jp->ps0; 681 } 682 INTON; | 53 54#include "shell.h" 55#if JOBS 56#include <termios.h> 57#undef CEOF /* syntax.h redefines this */ 58#endif 59#include "redir.h" 60#include "show.h" --- 614 unchanged lines hidden (view full) --- 675 jp->next = NULL; 676#endif 677 if (nprocs > 1) { 678 jp->ps = ckmalloc(nprocs * sizeof (struct procstat)); 679 } else { 680 jp->ps = &jp->ps0; 681 } 682 INTON; |
683 TRACE(("makejob(%p, %d) returns %%%d\n", (void *)node, nprocs, | 683 TRACE(("makejob(%p, %d) returns %%%td\n", (void *)node, nprocs, |
684 jp - jobtab + 1)); 685 return jp; 686} 687 688#if JOBS 689STATIC void 690setcurjob(struct job *cj) 691{ --- 69 unchanged lines hidden (view full) --- 761 */ 762 763pid_t 764forkshell(struct job *jp, union node *n, int mode) 765{ 766 pid_t pid; 767 pid_t pgrp; 768 | 684 jp - jobtab + 1)); 685 return jp; 686} 687 688#if JOBS 689STATIC void 690setcurjob(struct job *cj) 691{ --- 69 unchanged lines hidden (view full) --- 761 */ 762 763pid_t 764forkshell(struct job *jp, union node *n, int mode) 765{ 766 pid_t pid; 767 pid_t pgrp; 768 |
769 TRACE(("forkshell(%%%d, %p, %d) called\n", jp - jobtab, (void *)n, | 769 TRACE(("forkshell(%%%td, %p, %d) called\n", jp - jobtab, (void *)n, |
770 mode)); 771 INTOFF; 772 if (mode == FORK_BG) 773 checkzombies(); 774 flushall(); 775 pid = fork(); 776 if (pid == -1) { 777 TRACE(("Fork failed, errno=%d\n", errno)); --- 120 unchanged lines hidden (view full) --- 898#if JOBS 899 pid_t mypgrp = getpgrp(); 900 int propagate_int = jp->jobctl && jp->foreground; 901#endif 902 int status; 903 int st; 904 905 INTOFF; | 770 mode)); 771 INTOFF; 772 if (mode == FORK_BG) 773 checkzombies(); 774 flushall(); 775 pid = fork(); 776 if (pid == -1) { 777 TRACE(("Fork failed, errno=%d\n", errno)); --- 120 unchanged lines hidden (view full) --- 898#if JOBS 899 pid_t mypgrp = getpgrp(); 900 int propagate_int = jp->jobctl && jp->foreground; 901#endif 902 int status; 903 int st; 904 905 INTOFF; |
906 TRACE(("waitforjob(%%%d) called\n", jp - jobtab + 1)); | 906 TRACE(("waitforjob(%%%td) called\n", jp - jobtab + 1)); |
907 while (jp->state == 0) 908 if (dowait(1, jp) == -1) 909 dotrap(); 910#if JOBS 911 if (jp->jobctl) { 912 if (tcsetpgrp(ttyfd, mypgrp) < 0) 913 error("tcsetpgrp failed, errno=%d\n", errno); 914 } --- 84 unchanged lines hidden (view full) --- 999 if (sp->status == -1) 1000 stopped = 0; 1001 else if (WIFSTOPPED(sp->status)) 1002 done = 0; 1003 } 1004 if (stopped) { /* stopped or done */ 1005 int state = done? JOBDONE : JOBSTOPPED; 1006 if (jp->state != state) { | 907 while (jp->state == 0) 908 if (dowait(1, jp) == -1) 909 dotrap(); 910#if JOBS 911 if (jp->jobctl) { 912 if (tcsetpgrp(ttyfd, mypgrp) < 0) 913 error("tcsetpgrp failed, errno=%d\n", errno); 914 } --- 84 unchanged lines hidden (view full) --- 999 if (sp->status == -1) 1000 stopped = 0; 1001 else if (WIFSTOPPED(sp->status)) 1002 done = 0; 1003 } 1004 if (stopped) { /* stopped or done */ 1005 int state = done? JOBDONE : JOBSTOPPED; 1006 if (jp->state != state) { |
1007 TRACE(("Job %d: changing state from %d to %d\n", jp - jobtab + 1, jp->state, state)); | 1007 TRACE(("Job %td: changing state from %d to %d\n", jp - jobtab + 1, jp->state, state)); |
1008 jp->state = state; 1009 if (jp != job) { 1010 if (done && !jp->remembered && 1011 !iflag && jp != bgjob) 1012 freejob(jp); 1013#if JOBS 1014 else if (done) 1015 deljob(jp); --- 305 unchanged lines hidden --- | 1008 jp->state = state; 1009 if (jp != job) { 1010 if (done && !jp->remembered && 1011 !iflag && jp != bgjob) 1012 freejob(jp); 1013#if JOBS 1014 else if (done) 1015 deljob(jp); --- 305 unchanged lines hidden --- |