wait3.c revision 8e3c57a3c9aa75d7adfa6ee670c67507535df4d4
/*
* 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 */
/*
* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley Software License Agreement
* specifies the terms and conditions for redistribution.
*/
#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.
*/
#include <errno.h>
#include <wait.h>
#include <sys/resource.h>
/*
* 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
* ...
*
*/
/*
* 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
* the csh utility will result in warnings, hence the renaming of the local
* 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
* 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.
*/
{
struct tms before_tms;
int error;
if (rp)
return (-1); /* errno is set by times() */
/*
* BSD's wait3() only supports WNOHANG & WUNTRACED
*/
if (error == 0) {
return (0); /* no child found */
if (rp) {
return (-1); /* errno set by times() */
/*
*/
}
} else {
return (-1); /* error number is set by waitid() */
}
}
/*
* Convert the status code to old style wait status
*/
static int
{
switch (code) {
case CLD_EXITED:
stat <<= 8;
break;
case CLD_DUMPED:
break;
case CLD_KILLED:
break;
case CLD_TRAPPED:
case CLD_STOPPED:
stat <<= 8;
break;
case CLD_CONTINUED:
break;
}
return (stat);
}
csh_wait_noreap(void)
{
return (-1);
}