diff --git a/Build.sh b/Build.sh index 60eabd7..582ffe6 100644 --- a/Build.sh +++ b/Build.sh @@ -1,5 +1,5 @@ #!/bin/sh -srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.378 2009/03/29 17:50:45 tg Exp $' +srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.379 2009/04/03 09:39:01 tg Exp $' #- # Environment used: CC CFLAGS CPPFLAGS LDFLAGS LIBS NOWARN NROFF TARGET_OS # CPPFLAGS recognised: MKSH_SMALL MKSH_ASSUME_UTF8 MKSH_NOPWNAM MKSH_NOVI @@ -1070,6 +1070,15 @@ ac_testn flock_ex '' 'flock and mmap' <<-'EOF' PROT_READ, MAP_PRIVATE, 0, 0) == (void *)NULL ? 1 : 0); } EOF +ac_test getrusage <<-'EOF' + #define MKSH_INCLUDES_ONLY + #include "sh.h" + int main(void) { + struct rusage ru; + return (getrusage(RUSAGE_SELF + RUSAGE_CHILDREN, &ru)); + } +EOF + ac_test mknod '' 'if to use mknod(), makedev() and friends' <<-'EOF' #define MKSH_INCLUDES_ONLY #include "sh.h" diff --git a/Makefile b/Makefile index e4d7ae6..06c9759 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/Makefile,v 1.72 2009/03/22 16:55:37 tg Exp $ +# $MirOS: src/bin/mksh/Makefile,v 1.73 2009/04/03 09:39:03 tg Exp $ #- # use CPPFLAGS=-DDEBUG __CRAZY=Yes to check for certain more stuff @@ -17,12 +17,12 @@ CPPFLAGS+= -DMKSH_ASSUME_UTF8 \ -DHAVE_GRP_H=1 -DHAVE_ULIMIT_H=0 -DHAVE_VALUES_H=0 \ -DHAVE_STDINT_H=1 -DHAVE_RLIM_T=1 -DHAVE_SIG_T=1 \ -DHAVE_SYS_SIGNAME=1 -DHAVE_SYS_SIGLIST=1 -DHAVE_STRSIGNAL=0 \ - -DHAVE_ARC4RANDOM=1 -DHAVE_ARC4RANDOM_PUSHB=1 -DHAVE_MKNOD=1 \ - -DHAVE_MKSTEMP=1 -DHAVE_NICE=1 -DHAVE_REALPATH=1 \ - -DHAVE_REVOKE=1 -DHAVE_SETLOCALE_CTYPE=0 \ - -DHAVE_LANGINFO_CODESET=0 -DHAVE_SETMODE=1 \ - -DHAVE_SETRESUGID=1 -DHAVE_SETGROUPS=1 -DHAVE_STRCASESTR=1 \ - -DHAVE_STRLCPY=1 -DHAVE_ARC4RANDOM_DECL=1 \ + -DHAVE_ARC4RANDOM=1 -DHAVE_ARC4RANDOM_PUSHB=1 \ + -DHAVE_GETRUSAGE=1 -DHAVE_MKNOD=1 -DHAVE_MKSTEMP=1 \ + -DHAVE_NICE=1 -DHAVE_REALPATH=1 -DHAVE_REVOKE=1 \ + -DHAVE_SETLOCALE_CTYPE=0 -DHAVE_LANGINFO_CODESET=0 \ + -DHAVE_SETMODE=1 -DHAVE_SETRESUGID=1 -DHAVE_SETGROUPS=1 \ + -DHAVE_STRCASESTR=1 -DHAVE_STRLCPY=1 -DHAVE_ARC4RANDOM_DECL=1 \ -DHAVE_ARC4RANDOM_PUSHB_DECL=1 -DHAVE_FLOCK_DECL=1 \ -DHAVE_REVOKE_DECL=1 -DHAVE_SYS_SIGLIST_DECL=1 \ -DHAVE_PERSISTENT_HISTORY=1 diff --git a/check.t b/check.t index 8540ed2..7c9b19f 100644 --- a/check.t +++ b/check.t @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/check.t,v 1.266 2009/03/25 21:45:27 tg Exp $ +# $MirOS: src/bin/mksh/check.t,v 1.267 2009/04/03 09:39:03 tg Exp $ # $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $ @@ -7,7 +7,7 @@ # http://www.research.att.com/~gsf/public/ifs.sh expected-stdout: - @(#)MIRBSD KSH R37 2009/03/25 + @(#)MIRBSD KSH R37 2009/04/03 description: Check version of shell. stdin: diff --git a/funcs.c b/funcs.c index 352b3de..4c5c5b3 100644 --- a/funcs.c +++ b/funcs.c @@ -5,7 +5,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.100 2009/03/22 18:28:34 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.101 2009/04/03 09:39:05 tg Exp $"); /* A leading = means assignments before command are kept; * a leading * means a POSIX special builtin; @@ -2184,17 +2184,13 @@ c_times(const char **wp __unused) { struct rusage usage; -#ifdef RUSAGE_SELF - (void) getrusage(RUSAGE_SELF, &usage); + getrusage(RUSAGE_SELF, &usage); p_time(shl_stdout, 0, &usage.ru_utime, 0, NULL, " "); p_time(shl_stdout, 0, &usage.ru_stime, 0, NULL, "\n"); -#endif -#ifdef RUSAGE_CHILDREN - (void) getrusage(RUSAGE_CHILDREN, &usage); + getrusage(RUSAGE_CHILDREN, &usage); p_time(shl_stdout, 0, &usage.ru_utime, 0, NULL, " "); p_time(shl_stdout, 0, &usage.ru_stime, 0, NULL, "\n"); -#endif return 0; } @@ -2208,9 +2204,6 @@ timex(struct op *t, int f, volatile int *xerrok) #define TF_NOARGS BIT(0) #define TF_NOREAL BIT(1) /* don't report real time */ #define TF_POSIX BIT(2) /* report in posix format */ -#if !defined(RUSAGE_SELF) || !defined(RUSAGE_CHILDREN) - return (0); -#else int rv = 0, tf = 0; struct rusage ru0, ru1, cru0, cru1; struct timeval usrtime, systime, tv0, tv1; @@ -2267,7 +2260,6 @@ timex(struct op *t, int f, volatile int *xerrok) shf_flush(shl_out); return (rv); -#endif } void diff --git a/misc.c b/misc.c index 31596d1..1488218 100644 --- a/misc.c +++ b/misc.c @@ -2,11 +2,14 @@ /* $OpenBSD: path.c,v 1.12 2005/03/30 17:16:37 deraadt Exp $ */ #include "sh.h" +#if !HAVE_GETRUSAGE +#include +#endif #if HAVE_GRP_H #include #endif -__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.99 2009/03/22 18:09:16 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.100 2009/04/03 09:39:06 tg Exp $"); #undef USE_CHVT #if defined(TIOCSCTTY) && !defined(MKSH_SMALL) @@ -1465,3 +1468,37 @@ strdup_(const char *src, Area *ap) return (src == NULL ? NULL : strndup_(src, strlen(src), ap)); } #endif + +#if !HAVE_GETRUSAGE +#define INVTCK(r,t) do { \ + r.tv_usec = ((t) % (1000000 / CLK_TCK)) * (1000000 / CLK_TCK); \ + r.tv_sec = (t) / CLK_TCK; \ +} while (/* CONSTCOND */ 0) + +int +getrusage(int what, struct rusage *ru) +{ + struct tms tms; + clock_t u, s; + + if (/* ru == NULL || */ times(&tms) == (clock_t)-1) + return (-1); + + switch (what) { + case RUSAGE_SELF: + u = tms.tms_utime; + s = tms.tms_stime; + break; + case RUSAGE_CHILDREN: + u = tms.tms_cutime; + s = tms.tms_cstime; + break; + default: + errno = EINVAL; + return (-1); + } + INVTCK(r->ru_utime, u); + INVTCK(r->ru_stime, s); + return (0); +} +#endif diff --git a/sh.h b/sh.h index fb269dd..6d094fd 100644 --- a/sh.h +++ b/sh.h @@ -102,14 +102,28 @@ #define __SCCSID(x) __IDSTRING(sccsid,x) #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.286 2009/03/25 21:45:28 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.287 2009/04/03 09:39:07 tg Exp $"); #endif -#define MKSH_VERSION "R37 2009/03/25" +#define MKSH_VERSION "R37 2009/04/03" #ifndef MKSH_INCLUDES_ONLY /* extra types */ +#if !HAVE_GETRUSAGE +#undef rusage +#undef RUSAGE_SELF +#undef RUSAGE_CHILDREN +#define rusage mksh_rusage +#define RUSAGE_SELF 0 +#define RUSAGE_CHILDREN -1 + +struct rusage { + struct timeval ru_utime; + struct timeval ru_stime; +}; +#endif + #if !HAVE_RLIM_T typedef long rlim_t; #endif @@ -216,6 +230,10 @@ extern uint32_t arc4random_pushb(void *, size_t); extern int flock(int, int); #endif +#if !HAVE_GETRUSAGE +extern int getrusage(int, struct rusage *); +#endif + #if !HAVE_REVOKE_DECL extern int revoke(const char *); #endif