jobs.c (97660) | jobs.c (97663) |
---|---|
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 --- 25 unchanged lines hidden (view full) --- 34 * SUCH DAMAGE. 35 */ 36 37#ifndef lint 38#if 0 39static char sccsid[] = "@(#)jobs.c 8.5 (Berkeley) 5/4/95"; 40#endif 41static const char rcsid[] = | 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 --- 25 unchanged lines hidden (view full) --- 34 * SUCH DAMAGE. 35 */ 36 37#ifndef lint 38#if 0 39static char sccsid[] = "@(#)jobs.c 8.5 (Berkeley) 5/4/95"; 40#endif 41static const char rcsid[] = |
42 "$FreeBSD: head/bin/sh/jobs.c 97660 2002-05-31 12:35:34Z tjr $"; | 42 "$FreeBSD: head/bin/sh/jobs.c 97663 2002-05-31 13:07:05Z tjr $"; |
43#endif /* not lint */ 44 45#include <fcntl.h> 46#include <signal.h> 47#include <errno.h> 48#include <unistd.h> 49#include <stdlib.h> 50#include <sys/param.h> --- 53 unchanged lines hidden (view full) --- 104STATIC int waitproc(int, int *); 105STATIC void cmdtxt(union node *); 106STATIC void cmdputs(char *); 107#if JOBS 108STATIC void setcurjob(struct job *); 109STATIC void deljob(struct job *); 110STATIC struct job *getcurjob(struct job *); 111#endif | 43#endif /* not lint */ 44 45#include <fcntl.h> 46#include <signal.h> 47#include <errno.h> 48#include <unistd.h> 49#include <stdlib.h> 50#include <sys/param.h> --- 53 unchanged lines hidden (view full) --- 104STATIC int waitproc(int, int *); 105STATIC void cmdtxt(union node *); 106STATIC void cmdputs(char *); 107#if JOBS 108STATIC void setcurjob(struct job *); 109STATIC void deljob(struct job *); 110STATIC struct job *getcurjob(struct job *); 111#endif |
112STATIC void showjob(struct job *); |
|
112 113 114/* 115 * Turn job control on and off. 116 * 117 * Note: This code assumes that the third arg to ioctl is a character 118 * pointer, which is true on Berkeley systems but not System V. Since 119 * System V doesn't have job control yet, this isn't a problem now. --- 151 unchanged lines hidden (view full) --- 271 272int 273jobscmd(int argc __unused, char **argv __unused) 274{ 275 showjobs(0); 276 return 0; 277} 278 | 113 114 115/* 116 * Turn job control on and off. 117 * 118 * Note: This code assumes that the third arg to ioctl is a character 119 * pointer, which is true on Berkeley systems but not System V. Since 120 * System V doesn't have job control yet, this isn't a problem now. --- 151 unchanged lines hidden (view full) --- 272 273int 274jobscmd(int argc __unused, char **argv __unused) 275{ 276 showjobs(0); 277 return 0; 278} 279 |
280STATIC void 281showjob(struct job *jp) 282{ 283 char s[64]; 284 struct procstat *ps; 285 int col, i, jobno, procno; |
|
279 | 286 |
287 procno = jp->nprocs; 288 jobno = jp - jobtab + 1; 289 for (ps = jp->ps ; ; ps++) { /* for each process */ 290 if (ps == jp->ps) 291 fmtstr(s, 64, "[%d] %d ", jobno, ps->pid); 292 else 293 fmtstr(s, 64, " %d ", ps->pid); 294 out1str(s); 295 col = strlen(s); 296 s[0] = '\0'; 297 if (ps->status == -1) { 298 /* don't print anything */ 299 } else if (WIFEXITED(ps->status)) { 300 fmtstr(s, 64, "Exit %d", WEXITSTATUS(ps->status)); 301 } else { 302#if JOBS 303 if (WIFSTOPPED(ps->status)) 304 i = WSTOPSIG(ps->status); 305 else 306#endif 307 i = WTERMSIG(ps->status); 308 if ((i & 0x7F) < NSIG && sys_siglist[i & 0x7F]) 309 scopy(sys_siglist[i & 0x7F], s); 310 else 311 fmtstr(s, 64, "Signal %d", i & 0x7F); 312 if (WCOREDUMP(ps->status)) 313 strcat(s, " (core dumped)"); 314 } 315 out1str(s); 316 col += strlen(s); 317 do { 318 out1c(' '); 319 col++; 320 } while (col < 30); 321 out1str(ps->cmd); 322 out1c('\n'); 323 if (--procno <= 0) 324 break; 325 } 326} 327 |
|
280/* 281 * Print a list of jobs. If "change" is nonzero, only print jobs whose 282 * statuses have changed since the last call to showjobs. 283 * 284 * If the shell is interrupted in the process of creating a job, the 285 * result may be a job structure containing zero processes. Such structures 286 * will be freed here. 287 */ 288 289void 290showjobs(int change) 291{ 292 int jobno; | 328/* 329 * Print a list of jobs. If "change" is nonzero, only print jobs whose 330 * statuses have changed since the last call to showjobs. 331 * 332 * If the shell is interrupted in the process of creating a job, the 333 * result may be a job structure containing zero processes. Such structures 334 * will be freed here. 335 */ 336 337void 338showjobs(int change) 339{ 340 int jobno; |
293 int procno; 294 int i; | |
295 struct job *jp; | 341 struct job *jp; |
296 struct procstat *ps; 297 int col; 298 char s[64]; | |
299 300 TRACE(("showjobs(%d) called\n", change)); 301 while (dowait(0, (struct job *)NULL) > 0); 302 for (jobno = 1, jp = jobtab ; jobno <= njobs ; jobno++, jp++) { 303 if (! jp->used) 304 continue; 305 if (jp->nprocs == 0) { 306 freejob(jp); 307 continue; 308 } 309 if (change && ! jp->changed) 310 continue; | 342 343 TRACE(("showjobs(%d) called\n", change)); 344 while (dowait(0, (struct job *)NULL) > 0); 345 for (jobno = 1, jp = jobtab ; jobno <= njobs ; jobno++, jp++) { 346 if (! jp->used) 347 continue; 348 if (jp->nprocs == 0) { 349 freejob(jp); 350 continue; 351 } 352 if (change && ! jp->changed) 353 continue; |
311 procno = jp->nprocs; 312 for (ps = jp->ps ; ; ps++) { /* for each process */ 313 if (ps == jp->ps) 314 fmtstr(s, 64, "[%d] %d ", jobno, ps->pid); 315 else 316 fmtstr(s, 64, " %d ", ps->pid); 317 out1str(s); 318 col = strlen(s); 319 s[0] = '\0'; 320 if (ps->status == -1) { 321 /* don't print anything */ 322 } else if (WIFEXITED(ps->status)) { 323 fmtstr(s, 64, "Exit %d", WEXITSTATUS(ps->status)); 324 } else { 325#if JOBS 326 if (WIFSTOPPED(ps->status)) 327 i = WSTOPSIG(ps->status); 328 else 329#endif 330 i = WTERMSIG(ps->status); 331 if ((i & 0x7F) < NSIG && sys_siglist[i & 0x7F]) 332 scopy(sys_siglist[i & 0x7F], s); 333 else 334 fmtstr(s, 64, "Signal %d", i & 0x7F); 335 if (WCOREDUMP(ps->status)) 336 strcat(s, " (core dumped)"); 337 } 338 out1str(s); 339 col += strlen(s); 340 do { 341 out1c(' '); 342 col++; 343 } while (col < 30); 344 out1str(ps->cmd); 345 out1c('\n'); 346 if (--procno <= 0) 347 break; 348 } | 354 showjob(jp); |
349 jp->changed = 0; 350 if (jp->state == JOBDONE) { 351 freejob(jp); 352 } 353 } 354} 355 356 --- 527 unchanged lines hidden (view full) --- 884 deljob(jp); 885#endif 886 } 887 } 888 } 889 } 890 INTON; 891 if (! rootshell || ! iflag || (job && thisjob == job)) { | 355 jp->changed = 0; 356 if (jp->state == JOBDONE) { 357 freejob(jp); 358 } 359 } 360} 361 362 --- 527 unchanged lines hidden (view full) --- 890 deljob(jp); 891#endif 892 } 893 } 894 } 895 } 896 INTON; 897 if (! rootshell || ! iflag || (job && thisjob == job)) { |
892 core = WCOREDUMP(status); | |
893#if JOBS 894 if (WIFSTOPPED(status)) 895 sig = WSTOPSIG(status); 896 else 897#endif | 898#if JOBS 899 if (WIFSTOPPED(status)) 900 sig = WSTOPSIG(status); 901 else 902#endif |
903 { |
|
898 if (WIFEXITED(status)) 899 sig = 0; 900 else 901 sig = WTERMSIG(status); | 904 if (WIFEXITED(status)) 905 sig = 0; 906 else 907 sig = WTERMSIG(status); |
902 903 if (sig != 0 && sig != SIGINT && sig != SIGPIPE) { 904 if (thisjob != job) 905 outfmt(out2, "%d: ", pid); 906#if JOBS 907 if (sig == SIGTSTP && rootshell && iflag) 908 outfmt(out2, "%%%d ", job - jobtab + 1); 909#endif 910 if (sig < NSIG && sys_siglist[sig]) 911 out2str(sys_siglist[sig]); 912 else 913 outfmt(out2, "Signal %d", sig); 914 if (core) 915 out2str(" - core dumped"); 916 out2c('\n'); 917 flushout(&errout); 918 } else { 919 TRACE(("Not printing status: status=%d, sig=%d\n", 920 status, sig)); | |
921 } | 908 } |
909 if (sig != 0 && sig != SIGINT && sig != SIGPIPE) 910 showjob(thisjob); |
|
922 } else { 923 TRACE(("Not printing status, rootshell=%d, job=0x%x\n", rootshell, job)); 924 if (thisjob) 925 thisjob->changed = 1; 926 } 927 return pid; 928} 929 --- 288 unchanged lines hidden --- | 911 } else { 912 TRACE(("Not printing status, rootshell=%d, job=0x%x\n", rootshell, job)); 913 if (thisjob) 914 thisjob->changed = 1; 915 } 916 return pid; 917} 918 --- 288 unchanged lines hidden --- |