(experimental) implement getrusage via times if not found
This commit is contained in:
		
							
								
								
									
										11
									
								
								Build.sh
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								Build.sh
									
									
									
									
									
								
							| @@ -1,5 +1,5 @@ | |||||||
| #!/bin/sh | #!/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 | # Environment used: CC CFLAGS CPPFLAGS LDFLAGS LIBS NOWARN NROFF TARGET_OS | ||||||
| # CPPFLAGS recognised:	MKSH_SMALL MKSH_ASSUME_UTF8 MKSH_NOPWNAM MKSH_NOVI | # 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); } | 	    PROT_READ, MAP_PRIVATE, 0, 0) == (void *)NULL ? 1 : 0); } | ||||||
| EOF | 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' | ac_test mknod '' 'if to use mknod(), makedev() and friends' <<-'EOF' | ||||||
| 	#define MKSH_INCLUDES_ONLY | 	#define MKSH_INCLUDES_ONLY | ||||||
| 	#include "sh.h" | 	#include "sh.h" | ||||||
|   | |||||||
							
								
								
									
										14
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								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 | # 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_GRP_H=1 -DHAVE_ULIMIT_H=0 -DHAVE_VALUES_H=0 \ | ||||||
| 		-DHAVE_STDINT_H=1 -DHAVE_RLIM_T=1 -DHAVE_SIG_T=1 \ | 		-DHAVE_STDINT_H=1 -DHAVE_RLIM_T=1 -DHAVE_SIG_T=1 \ | ||||||
| 		-DHAVE_SYS_SIGNAME=1 -DHAVE_SYS_SIGLIST=1 -DHAVE_STRSIGNAL=0 \ | 		-DHAVE_SYS_SIGNAME=1 -DHAVE_SYS_SIGLIST=1 -DHAVE_STRSIGNAL=0 \ | ||||||
| 		-DHAVE_ARC4RANDOM=1 -DHAVE_ARC4RANDOM_PUSHB=1 -DHAVE_MKNOD=1 \ | 		-DHAVE_ARC4RANDOM=1 -DHAVE_ARC4RANDOM_PUSHB=1 \ | ||||||
| 		-DHAVE_MKSTEMP=1 -DHAVE_NICE=1 -DHAVE_REALPATH=1 \ | 		-DHAVE_GETRUSAGE=1 -DHAVE_MKNOD=1 -DHAVE_MKSTEMP=1 \ | ||||||
| 		-DHAVE_REVOKE=1 -DHAVE_SETLOCALE_CTYPE=0 \ | 		-DHAVE_NICE=1 -DHAVE_REALPATH=1 -DHAVE_REVOKE=1 \ | ||||||
| 		-DHAVE_LANGINFO_CODESET=0 -DHAVE_SETMODE=1 \ | 		-DHAVE_SETLOCALE_CTYPE=0 -DHAVE_LANGINFO_CODESET=0 \ | ||||||
| 		-DHAVE_SETRESUGID=1 -DHAVE_SETGROUPS=1 -DHAVE_STRCASESTR=1 \ | 		-DHAVE_SETMODE=1 -DHAVE_SETRESUGID=1 -DHAVE_SETGROUPS=1 \ | ||||||
| 		-DHAVE_STRLCPY=1 -DHAVE_ARC4RANDOM_DECL=1 \ | 		-DHAVE_STRCASESTR=1 -DHAVE_STRLCPY=1 -DHAVE_ARC4RANDOM_DECL=1 \ | ||||||
| 		-DHAVE_ARC4RANDOM_PUSHB_DECL=1 -DHAVE_FLOCK_DECL=1 \ | 		-DHAVE_ARC4RANDOM_PUSHB_DECL=1 -DHAVE_FLOCK_DECL=1 \ | ||||||
| 		-DHAVE_REVOKE_DECL=1 -DHAVE_SYS_SIGLIST_DECL=1 \ | 		-DHAVE_REVOKE_DECL=1 -DHAVE_SYS_SIGLIST_DECL=1 \ | ||||||
| 		-DHAVE_PERSISTENT_HISTORY=1 | 		-DHAVE_PERSISTENT_HISTORY=1 | ||||||
|   | |||||||
							
								
								
									
										4
									
								
								check.t
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								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: 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: 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 $ | # $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 | # http://www.research.att.com/~gsf/public/ifs.sh | ||||||
|  |  | ||||||
| expected-stdout: | expected-stdout: | ||||||
| 	@(#)MIRBSD KSH R37 2009/03/25 | 	@(#)MIRBSD KSH R37 2009/04/03 | ||||||
| description: | description: | ||||||
| 	Check version of shell. | 	Check version of shell. | ||||||
| stdin: | stdin: | ||||||
|   | |||||||
							
								
								
									
										14
									
								
								funcs.c
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								funcs.c
									
									
									
									
									
								
							| @@ -5,7 +5,7 @@ | |||||||
|  |  | ||||||
| #include "sh.h" | #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 assignments before command are kept; | ||||||
|  * a leading * means a POSIX special builtin; |  * a leading * means a POSIX special builtin; | ||||||
| @@ -2184,17 +2184,13 @@ c_times(const char **wp __unused) | |||||||
| { | { | ||||||
| 	struct rusage usage; | 	struct rusage usage; | ||||||
|  |  | ||||||
| #ifdef RUSAGE_SELF | 	getrusage(RUSAGE_SELF, &usage); | ||||||
| 	(void) getrusage(RUSAGE_SELF, &usage); |  | ||||||
| 	p_time(shl_stdout, 0, &usage.ru_utime, 0, NULL, " "); | 	p_time(shl_stdout, 0, &usage.ru_utime, 0, NULL, " "); | ||||||
| 	p_time(shl_stdout, 0, &usage.ru_stime, 0, NULL, "\n"); | 	p_time(shl_stdout, 0, &usage.ru_stime, 0, NULL, "\n"); | ||||||
| #endif |  | ||||||
|  |  | ||||||
| #ifdef RUSAGE_CHILDREN | 	getrusage(RUSAGE_CHILDREN, &usage); | ||||||
| 	(void) getrusage(RUSAGE_CHILDREN, &usage); |  | ||||||
| 	p_time(shl_stdout, 0, &usage.ru_utime, 0, NULL, " "); | 	p_time(shl_stdout, 0, &usage.ru_utime, 0, NULL, " "); | ||||||
| 	p_time(shl_stdout, 0, &usage.ru_stime, 0, NULL, "\n"); | 	p_time(shl_stdout, 0, &usage.ru_stime, 0, NULL, "\n"); | ||||||
| #endif |  | ||||||
|  |  | ||||||
| 	return 0; | 	return 0; | ||||||
| } | } | ||||||
| @@ -2208,9 +2204,6 @@ timex(struct op *t, int f, volatile int *xerrok) | |||||||
| #define TF_NOARGS	BIT(0) | #define TF_NOARGS	BIT(0) | ||||||
| #define TF_NOREAL	BIT(1)		/* don't report real time */ | #define TF_NOREAL	BIT(1)		/* don't report real time */ | ||||||
| #define TF_POSIX	BIT(2)		/* report in posix format */ | #define TF_POSIX	BIT(2)		/* report in posix format */ | ||||||
| #if !defined(RUSAGE_SELF) || !defined(RUSAGE_CHILDREN) |  | ||||||
| 	return (0); |  | ||||||
| #else |  | ||||||
| 	int rv = 0, tf = 0; | 	int rv = 0, tf = 0; | ||||||
| 	struct rusage ru0, ru1, cru0, cru1; | 	struct rusage ru0, ru1, cru0, cru1; | ||||||
| 	struct timeval usrtime, systime, tv0, tv1; | 	struct timeval usrtime, systime, tv0, tv1; | ||||||
| @@ -2267,7 +2260,6 @@ timex(struct op *t, int f, volatile int *xerrok) | |||||||
| 	shf_flush(shl_out); | 	shf_flush(shl_out); | ||||||
|  |  | ||||||
| 	return (rv); | 	return (rv); | ||||||
| #endif |  | ||||||
| } | } | ||||||
|  |  | ||||||
| void | void | ||||||
|   | |||||||
							
								
								
									
										39
									
								
								misc.c
									
									
									
									
									
								
							
							
						
						
									
										39
									
								
								misc.c
									
									
									
									
									
								
							| @@ -2,11 +2,14 @@ | |||||||
| /*	$OpenBSD: path.c,v 1.12 2005/03/30 17:16:37 deraadt Exp $	*/ | /*	$OpenBSD: path.c,v 1.12 2005/03/30 17:16:37 deraadt Exp $	*/ | ||||||
|  |  | ||||||
| #include "sh.h" | #include "sh.h" | ||||||
|  | #if !HAVE_GETRUSAGE | ||||||
|  | #include <sys/times.h> | ||||||
|  | #endif | ||||||
| #if HAVE_GRP_H | #if HAVE_GRP_H | ||||||
| #include <grp.h> | #include <grp.h> | ||||||
| #endif | #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 | #undef USE_CHVT | ||||||
| #if defined(TIOCSCTTY) && !defined(MKSH_SMALL) | #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)); | 	return (src == NULL ? NULL : strndup_(src, strlen(src), ap)); | ||||||
| } | } | ||||||
| #endif | #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 | ||||||
|   | |||||||
							
								
								
									
										22
									
								
								sh.h
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								sh.h
									
									
									
									
									
								
							| @@ -102,14 +102,28 @@ | |||||||
| #define __SCCSID(x)	__IDSTRING(sccsid,x) | #define __SCCSID(x)	__IDSTRING(sccsid,x) | ||||||
|  |  | ||||||
| #ifdef EXTERN | #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 | #endif | ||||||
| #define MKSH_VERSION "R37 2009/03/25" | #define MKSH_VERSION "R37 2009/04/03" | ||||||
|  |  | ||||||
| #ifndef MKSH_INCLUDES_ONLY | #ifndef MKSH_INCLUDES_ONLY | ||||||
|  |  | ||||||
| /* extra types */ | /* 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 | #if !HAVE_RLIM_T | ||||||
| typedef long rlim_t; | typedef long rlim_t; | ||||||
| #endif | #endif | ||||||
| @@ -216,6 +230,10 @@ extern uint32_t arc4random_pushb(void *, size_t); | |||||||
| extern int flock(int, int); | extern int flock(int, int); | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|  | #if !HAVE_GETRUSAGE | ||||||
|  | extern int getrusage(int, struct rusage *); | ||||||
|  | #endif | ||||||
|  |  | ||||||
| #if !HAVE_REVOKE_DECL | #if !HAVE_REVOKE_DECL | ||||||
| extern int revoke(const char *); | extern int revoke(const char *); | ||||||
| #endif | #endif | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user