summaryrefslogtreecommitdiff
path: root/usr/src/cmd/csh/wait3.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/cmd/csh/wait3.c')
-rw-r--r--usr/src/cmd/csh/wait3.c155
1 files changed, 82 insertions, 73 deletions
diff --git a/usr/src/cmd/csh/wait3.c b/usr/src/cmd/csh/wait3.c
index b2ae68c95a..75c3ce366e 100644
--- a/usr/src/cmd/csh/wait3.c
+++ b/usr/src/cmd/csh/wait3.c
@@ -1,10 +1,10 @@
/*
- * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
-/* All Rights Reserved */
+/* All Rights Reserved */
/*
* Copyright (c) 1980 Regents of the University of California.
@@ -15,9 +15,9 @@
#pragma ident "%Z%%M% %I% %E% SMI"
/*
- * Compatibility lib for BSD's wait3(). It is not
- * binary compatible, since BSD's WNOHANG and WUNTRACED
- * carry different #define values.
+ * Compatibility lib for BSD's wait3(). It is not
+ * binary compatible, since BSD's WNOHANG and WUNTRACED
+ * carry different #define values.
*/
#include <errno.h>
#include <sys/types.h>
@@ -32,17 +32,17 @@
/*
* Since sysV does not support rusage as in BSD, an approximate approach
* is:
- * ...
- * call times
- * call waitid
- * if ( a child is found )
- * call times again
- * rusage ~= diff in the 2 times call
- * ...
- *
+ * ...
+ * call times
+ * call waitid
+ * if ( a child is found )
+ * call times again
+ * rusage ~= diff in the 2 times call
+ * ...
+ *
*/
-/*
+/*
* XXX: There is now a wait3 function in libc which should be used instead
* of this local version of wait3. With the addition of a wait3 prototype
* in <sys/wait.h> as per the X/Open XPG4v2 specification, compilation of
@@ -50,87 +50,96 @@
* version. Using the libc wait3 rather than the local version results in
* a failure with csh, however, this version should eventually be dropped
* in favor of the libc wait3 with appropriate updates made to sh.proc.c
- * to account for the difference in implementation of the local versus
+ * to account for the difference in implementation of the local versus
* the libc versions. This should probably be done as part of an overall
* effort to rid csh of local versions of functions now in libc.
*/
-csh_wait3(status, options, rp)
- int *status;
- int options;
- struct rusage *rp;
-
+static int wstat(int code, int status);
+
+pid_t
+csh_wait3(int *status, int options, struct rusage *rp)
{
- struct tms before_tms;
- struct tms after_tms;
- siginfo_t info;
- int error;
+ struct tms before_tms;
+ struct tms after_tms;
+ siginfo_t info;
+ int error;
if (rp)
- memset((void *)rp, 0, sizeof(struct rusage));
- memset((void *)&info, 0, sizeof(siginfo_t));
- if ( times(&before_tms) == -1 )
- return (-1); /* errno is set by times() */
+ memset((void *)rp, 0, sizeof (struct rusage));
+ memset((void *)&info, 0, sizeof (siginfo_t));
+ if (times(&before_tms) == -1)
+ return (-1); /* errno is set by times() */
/*
* BSD's wait3() only supports WNOHANG & WUNTRACED
*/
options |= (WNOHANG|WUNTRACED|WEXITED|WSTOPPED|WTRAPPED|WCONTINUED);
- error = waitid(P_ALL, 0, &info, options);
- if ( error == 0 ) {
- clock_t diffu; /* difference in usertime (ticks) */
- clock_t diffs; /* difference in systemtime (ticks) */
+ error = waitid(P_ALL, 0, &info, options);
+ if (error == 0) {
+ clock_t diffu; /* difference in usertime (ticks) */
+ clock_t diffs; /* difference in systemtime (ticks) */
- if ( (options & WNOHANG) && (info.si_pid == 0) )
- return (0); /* no child found */
+ if ((options & WNOHANG) && (info.si_pid == 0))
+ return (0); /* no child found */
if (rp) {
- if ( times(&after_tms) == -1 )
- return (-1); /* errno set by times() */
- /*
- * The system/user time is an approximation only !!!
- */
- diffu = after_tms.tms_cutime - before_tms.tms_cutime;
- diffs = after_tms.tms_cstime - before_tms.tms_cstime;
- rp->ru_utime.tv_sec = diffu/HZ;
- rp->ru_utime.tv_usec = (diffu % HZ) / HZ * 1000000;
- rp->ru_stime.tv_sec = diffs/HZ;
- rp->ru_stime.tv_usec = (diffs % HZ) / HZ * 1000000;
+ if (times(&after_tms) == -1)
+ return (-1); /* errno set by times() */
+ /*
+ * The system/user time is an approximation only !!!
+ */
+ diffu = after_tms.tms_cutime - before_tms.tms_cutime;
+ diffs = after_tms.tms_cstime - before_tms.tms_cstime;
+ rp->ru_utime.tv_sec = diffu/HZ;
+ rp->ru_utime.tv_usec = (diffu % HZ) / HZ * 1000000;
+ rp->ru_stime.tv_sec = diffs/HZ;
+ rp->ru_stime.tv_usec = (diffs % HZ) / HZ * 1000000;
}
- *status = wstat(info.si_code, info.si_status);
- return (info.si_pid);
+ *status = wstat(info.si_code, info.si_status);
+ return (info.si_pid);
- } else {
- return (-1); /* error number is set by waitid() */
- }
+ } else {
+ return (-1); /* error number is set by waitid() */
+ }
}
/*
* Convert the status code to old style wait status
*/
-wstat(code, status)
- int code;
- int status;
+static int
+wstat(int code, int status)
{
- register stat = (status & 0377);
-
- switch (code) {
- case CLD_EXITED:
- stat <<= 8;
- break;
- case CLD_DUMPED:
- stat |= WCOREFLG;
- break;
- case CLD_KILLED:
- break;
- case CLD_TRAPPED:
- case CLD_STOPPED:
- stat <<= 8;
- stat |= WSTOPFLG;
- break;
+ int stat = (status & 0377);
+
+ switch (code) {
+ case CLD_EXITED:
+ stat <<= 8;
+ break;
+ case CLD_DUMPED:
+ stat |= WCOREFLG;
+ break;
+ case CLD_KILLED:
+ break;
+ case CLD_TRAPPED:
+ case CLD_STOPPED:
+ stat <<= 8;
+ stat |= WSTOPFLG;
+ break;
case CLD_CONTINUED:
- stat = WCONTFLG;
- break;
- }
- return (stat);
+ stat = WCONTFLG;
+ break;
+ }
+ return (stat);
+}
+
+pid_t
+csh_wait_noreap(void)
+{
+ siginfo_t info;
+
+ if (waitid(P_ALL, 0, &info,
+ WEXITED | WTRAPPED | WSTOPPED | WCONTINUED | WNOWAIT) != 0)
+ return (-1);
+ return (info.si_pid);
}